From 7b6e58d6d129beb7f4bceacb1d5cb44fb942a509 Mon Sep 17 00:00:00 2001 From: Robson Oliveira dos Santos Date: Sun, 17 Dec 2023 18:07:37 -0300 Subject: [PATCH 1/8] feat: update Android DFU to version 2.4.1 --- .vscode/settings.json | 3 ++- android/build.gradle | 2 +- example/android/variables.gradle | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ec700c4..3c05d97 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,5 +29,6 @@ "cSpell.words": ["Bootloader", "Buttonless", "Softdevice"], "[swift]": { "editor.defaultFormatter": "vknabel.vscode-swiftformat" - } + }, + "java.configuration.updateBuildConfiguration": "automatic" } diff --git a/android/build.gradle b/android/build.gradle index 5fbe35b..9fb6388 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -55,5 +55,5 @@ dependencies { testImplementation "junit:junit:$junitVersion" androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion" androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion" - implementation "no.nordicsemi.android:dfu:2.3.0" + implementation "no.nordicsemi.android:dfu:2.4.1" } diff --git a/example/android/variables.gradle b/example/android/variables.gradle index 5946ada..631e622 100644 --- a/example/android/variables.gradle +++ b/example/android/variables.gradle @@ -1,7 +1,7 @@ ext { minSdkVersion = 22 - compileSdkVersion = 33 - targetSdkVersion = 33 + compileSdkVersion = 34 + targetSdkVersion = 34 androidxActivityVersion = '1.7.0' androidxAppCompatVersion = '1.6.1' androidxCoordinatorLayoutVersion = '1.2.0' @@ -13,4 +13,4 @@ ext { androidxJunitVersion = '1.1.5' androidxEspressoCoreVersion = '3.5.1' cordovaAndroidVersion = '10.1.1' -} \ No newline at end of file +} From 9650b149d2916ee39f17093375681f9fd4525e33 Mon Sep 17 00:00:00 2001 From: Robson Oliveira dos Santos Date: Sun, 17 Dec 2023 18:29:24 -0300 Subject: [PATCH 2/8] feat: update iOS DFU to version 4.14.0 --- CapacitorCommunityNordicDfu.podspec | 2 +- ios/Plugin/NordicDfu.swift | 2 +- ios/Plugin/NordicDfuPlugin.swift | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CapacitorCommunityNordicDfu.podspec b/CapacitorCommunityNordicDfu.podspec index 9f40763..c6c5646 100644 --- a/CapacitorCommunityNordicDfu.podspec +++ b/CapacitorCommunityNordicDfu.podspec @@ -14,5 +14,5 @@ Pod::Spec.new do |s| s.ios.deployment_target = '13.0' s.dependency 'Capacitor' s.swift_version = '5.1' - s.dependency 'iOSDFULibrary', '~> 4.13.0' + s.dependency 'iOSDFULibrary', '~> 4.14.0' end diff --git a/ios/Plugin/NordicDfu.swift b/ios/Plugin/NordicDfu.swift index 9575947..ac3250d 100644 --- a/ios/Plugin/NordicDfu.swift +++ b/ios/Plugin/NordicDfu.swift @@ -1,5 +1,5 @@ import Capacitor import CoreBluetooth -import iOSDFULibrary +import NordicDFU @objc public class NordicDfu: NSObject {} diff --git a/ios/Plugin/NordicDfuPlugin.swift b/ios/Plugin/NordicDfuPlugin.swift index 00f193e..7637d66 100644 --- a/ios/Plugin/NordicDfuPlugin.swift +++ b/ios/Plugin/NordicDfuPlugin.swift @@ -1,7 +1,7 @@ import Capacitor import CoreBluetooth import Foundation -import iOSDFULibrary +import NordicDFU import UserNotifications @objc(NordicDfuPlugin) @@ -18,7 +18,7 @@ public class NordicDfuPlugin: CAPPlugin, CBCentralManagerDelegate, DFUServiceDel var notification: JSObject = [ "id": Int(request.identifier) ?? -1, "title": request.content.title, - "body": request.content.body + "body": request.content.body, ] if let userInfo = JSTypes.coerceDictionaryToJSObject(request.content.userInfo) { @@ -72,7 +72,7 @@ public class NordicDfuPlugin: CAPPlugin, CBCentralManagerDelegate, DFUServiceDel return [ .badge, .sound, - .alert + .alert, ] } @@ -137,7 +137,7 @@ public class NordicDfuPlugin: CAPPlugin, CBCentralManagerDelegate, DFUServiceDel "speed": currentSpeedBytesPerSecond / 1000, "avgSpeed": avgSpeedBytesPerSecond / 1000, "currentPart": part, - "partsTotal": totalParts + "partsTotal": totalParts, ] sendStateUpdate("DFU_PROGRESS", data) } @@ -145,7 +145,7 @@ public class NordicDfuPlugin: CAPPlugin, CBCentralManagerDelegate, DFUServiceDel private func sendStateUpdate(_ state: String, _ data: JSObject = [:]) { let ret: JSObject = [ "state": state, - "data": data + "data": data, ] notifyListeners(dfuChangeEvent, data: ret) } @@ -238,7 +238,8 @@ public class NordicDfuPlugin: CAPPlugin, CBCentralManagerDelegate, DFUServiceDel // } if let packetsReceiptNotificationsValueStr = dfuOption["packetsReceiptNotificationsValue"] as? String, - let packetsReceiptNotificationsValue = UInt16(packetsReceiptNotificationsValueStr) { + let packetsReceiptNotificationsValue = UInt16(packetsReceiptNotificationsValueStr) + { starter.packetReceiptNotificationParameter = packetsReceiptNotificationsValue } From cb25dda93b474d66e2f0a6be569f4feee8c4eb85 Mon Sep 17 00:00:00 2001 From: Robson Oliveira dos Santos Date: Mon, 18 Dec 2023 12:44:20 -0300 Subject: [PATCH 3/8] feat: add duration and remaining time to progress data --- README.md | 16 ++++++----- .../example/plugin/nordicdfu/NordicDfu.java | 15 ++++++++++ example/src/app/scan/dfu/dfu.page.html | 2 ++ ios/Plugin/NordicDfuPlugin.swift | 28 ++++++++++++++++--- src/definitions.ts | 14 ++++++++++ 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d016233..bd00d83 100644 --- a/README.md +++ b/README.md @@ -221,13 +221,15 @@ The DFU update object that is passed to the DFUStateChanged event Contains data related to the DFU update process, such as progress and speed. -| Prop | Type | Description | Since | -| ----------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | -| **`percent`** | number | The current status of upload (0-99). | 1.0.0 | -| **`speed`** | number | The current speed in bytes per millisecond. | 1.0.0 | -| **`avgSpeed`** | number | The average speed in bytes per millisecond. | 1.0.0 | -| **`currentPart`** | number | The number of parts being sent. In case the ZIP file contains a Soft Device and/or a Bootloader together with the application the SD+BL are sent as part 1, then the service starts again and send the application as part 2. | 1.0.0 | -| **`partsTotal`** | number | The total number of parts. | 1.0.0 | +| Prop | Type | Description | Since | +| ------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | +| **`percent`** | number | The current status of upload (0-99). | 1.0.0 | +| **`speed`** | number | The current speed in bytes per millisecond. | 1.0.0 | +| **`avgSpeed`** | number | The average speed in bytes per millisecond. | 1.0.0 | +| **`currentPart`** | number | The number of parts being sent. In case the ZIP file contains a Soft Device and/or a Bootloader together with the application the SD+BL are sent as part 1, then the service starts again and send the application as part 2. | 1.0.0 | +| **`partsTotal`** | number | The total number of parts. | 1.0.0 | +| **`duration`** | number | The total time elapsed since the start of the DFU process in milliseconds | 1.0.1 | +| **`remainingTime`** | number | The estimated remaining time to the end of the DFU process in milliseconds | 1.0.1 | ### Type Aliases diff --git a/android/src/main/java/com/example/plugin/nordicdfu/NordicDfu.java b/android/src/main/java/com/example/plugin/nordicdfu/NordicDfu.java index 520b089..bb6d455 100644 --- a/android/src/main/java/com/example/plugin/nordicdfu/NordicDfu.java +++ b/android/src/main/java/com/example/plugin/nordicdfu/NordicDfu.java @@ -30,6 +30,8 @@ public void setDFUEventListener(@Nullable DfuEventListener dfuEventListener) { @Nullable private DfuEventListener dfuEventListener; + private long startTime = 0; + public NordicDfu(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { DfuServiceInitiator.createDfuNotificationChannel(context); @@ -60,6 +62,8 @@ public void onDfuProcessStarting(@NonNull final String deviceAddress) { @Override public void onDfuProcessStarted(@NonNull final String deviceAddress) { + startTime = System.currentTimeMillis(); + JSObject ret = new JSObject(); ret.put("deviceAddress", deviceAddress); dfuEventListener.onDfuEvent("DFU_PROCESS_STARTED", ret); @@ -81,6 +85,15 @@ public void onProgressChanged( final int currentPart, final int partsTotal ) { + long currentTime = System.currentTimeMillis(); + long duration = currentTime - startTime; + long remainingTime = 0; + + if (percent > 0) { + long estimatedTotalTime = (duration * 100) / percent; + remainingTime = estimatedTotalTime - duration; + } + JSObject ret = new JSObject(); ret.put("deviceAddress", deviceAddress); ret.put("percent", percent); @@ -88,6 +101,8 @@ public void onProgressChanged( ret.put("avgSpeed", avgSpeed); ret.put("currentPart", currentPart); ret.put("partsTotal", partsTotal); + ret.put("duration", duration); + ret.put("remainingTime", remainingTime); dfuEventListener.onDfuEvent("DFU_PROGRESS", ret); } diff --git a/example/src/app/scan/dfu/dfu.page.html b/example/src/app/scan/dfu/dfu.page.html index 359d6d3..943711c 100644 --- a/example/src/app/scan/dfu/dfu.page.html +++ b/example/src/app/scan/dfu/dfu.page.html @@ -19,6 +19,8 @@ Average Speed: {{ (update?.data?.avgSpeed ?? 0)* 1000 / 1024 | number }} kBps
Current part: {{ (update?.data?.currentPart ?? 0)}}
Total Parts: {{ (update?.data?.partsTotal ?? 0)}}
+ Duration: {{ (update?.data?.duration ?? 0) | number }}
+ Remaining time: {{ (update?.data?.remainingTime ?? 0) | number }}
0 { + let estimatedTotalTimeInSeconds = durationInSeconds * (100.0 / Double(progress)) + let estimatedRemainingTimeInSeconds = estimatedTotalTimeInSeconds - durationInSeconds + remainingTime = estimatedRemainingTimeInSeconds * 1000 // Convert remaining time to milliseconds + } + let data: JSObject = [ "deviceAddress": "", "percent": progress, @@ -138,6 +156,8 @@ public class NordicDfuPlugin: CAPPlugin, CBCentralManagerDelegate, DFUServiceDel "avgSpeed": avgSpeedBytesPerSecond / 1000, "currentPart": part, "partsTotal": totalParts, + "duration": duration, + "remainingTime": remainingTime, ] sendStateUpdate("DFU_PROGRESS", data) } diff --git a/src/definitions.ts b/src/definitions.ts index f655052..7c67c2d 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -148,6 +148,20 @@ export interface DfuUpdateData { * @since 1.0.0 */ partsTotal?: number; + + /** + * The total time elapsed since the start of the DFU process in milliseconds + * + * @since 1.0.1 + */ + duration?: number; + + /** + * The estimated remaining time to the end of the DFU process in milliseconds + * + * @since 1.0.1 + */ + remainingTime?: number; } /** From 6a0b6c4527679a854b2ee543a4ef948766325c94 Mon Sep 17 00:00:00 2001 From: Robson Oliveira dos Santos Date: Mon, 18 Dec 2023 15:08:28 -0300 Subject: [PATCH 4/8] fix: improve code signing for Pods --- example/ios/App/Podfile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/example/ios/App/Podfile b/example/ios/App/Podfile index e814c8a..a378d13 100644 --- a/example/ios/App/Podfile +++ b/example/ios/App/Podfile @@ -24,4 +24,25 @@ end post_install do |installer| assertDeploymentTarget(installer) + + # Get main project development team id + dev_team = "" + project = installer.aggregate_targets.first.user_project + project.targets.each do |target| + target.build_configurations.each do |config| + if dev_team.empty? && !config.build_settings['DEVELOPMENT_TEAM'].nil? + dev_team = config.build_settings['DEVELOPMENT_TEAM'] + end + end + end + + # Apply development team to all pod targets + installer.pods_project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings['DEVELOPMENT_TEAM'] = dev_team + config.build_settings['CODE_SIGN_STYLE'] = 'Automatic' + config.build_settings['CODE_SIGN_IDENTITY'] = 'iPhone Developer' + config.build_settings['PROVISIONING_PROFILE_SPECIFIER'] = '' + end + end end From d0cf4119ac03416fda5b1d8e3a3fd5964148bc6d Mon Sep 17 00:00:00 2001 From: Robson Oliveira dos Santos Date: Mon, 18 Dec 2023 15:59:12 -0300 Subject: [PATCH 5/8] docs: update documentation --- .all-contributorsrc | 4 ++++ README.md | 48 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 .all-contributorsrc diff --git a/.all-contributorsrc b/.all-contributorsrc new file mode 100644 index 0000000..d6c5687 --- /dev/null +++ b/.all-contributorsrc @@ -0,0 +1,4 @@ +{ + "projectName": "", + "projectOwner": "" +} diff --git a/README.md b/README.md index bd00d83..55bcbac 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,34 @@


Nordic DFU

-

@capacitor-community/nordic-dfu

+

capacitor-community-nordic-dfu

Capacitor plugin to interface with Nordic DFU's IOS-DFU-Library and Android-DFU-Library.

- - - -
- - - - - + + GitHub Workflow Status (with event) + +
+ Downloads from npmjs + Version from npmjs + GitHub contributors from allcontributors.org

## Table of Contents @@ -23,6 +37,7 @@ - [Installation](#installation) - [Permissions](#permissions) - [API](#api) +- [Contributors](#contributors) ## Maintainers @@ -33,7 +48,7 @@ ## Installation ```bash -npm install @capacitor-community/nordic-dfu +npm install capacitor-community-nordic-dfu npx cap sync ``` @@ -261,3 +276,14 @@ Contains data related to the DFU update process, such as progress and speed. | **`DFU_FAILED`** | 'DFU_FAILED' | The DFU process has failed. | 1.0.0 | + +## Contributors + + + + + + + + + From b713d108f166d14eb198c21b3f42f5e17af9cbbf Mon Sep 17 00:00:00 2001 From: Robson Oliveira dos Santos Date: Mon, 18 Dec 2023 18:02:07 -0300 Subject: [PATCH 6/8] ci: optimize CI --- .github/workflows/ci.yaml | 47 ++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9261f11..3055d4e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,22 +8,60 @@ env: JAVA_VERSION: 17 jobs: - ci: + lint: runs-on: macos-13 steps: - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 0 + fetch-depth: 1 + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Lint + run: yarn lint + + verify-ios: + runs-on: macos-13 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' - name: Set up Xcode run: sudo xcode-select --switch /Applications/Xcode_14.2.app + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Lint + run: yarn lint + + - name: Verify + run: yarn verify:ios + + verify-android: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + - name: Setup Java uses: actions/setup-java@v3 with: @@ -33,8 +71,5 @@ jobs: - name: Install dependencies run: yarn install --frozen-lockfile - - name: Lint - run: yarn lint - - name: Verify - run: yarn verify + run: yarn verify:android From bc916b38e93193f282e85d6392280a6f3ac4cded Mon Sep 17 00:00:00 2001 From: Robson Oliveira dos Santos Date: Mon, 18 Dec 2023 18:54:32 -0300 Subject: [PATCH 7/8] ci: add create pull request action --- .github/workflows/ci.yaml | 88 ++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3055d4e..809a1b0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,6 +22,32 @@ jobs: - name: Lint run: yarn lint + verify-android: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + + - name: Setup Java + uses: actions/setup-java@v3 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: 'zulu' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Verify + run: yarn verify:android + verify-ios: runs-on: macos-13 steps: @@ -48,28 +74,60 @@ jobs: - name: Verify run: yarn verify:ios - verify-android: + create-pr: runs-on: ubuntu-latest + needs: [lint, verify-ios, verify-android] steps: - name: Checkout uses: actions/checkout@v3 with: - fetch-depth: 1 + fetch-depth: 0 - - name: Setup Node.js - uses: actions/setup-node@v3 + - name: Create pull or update pull request + uses: actions/github-script@v7 with: - node-version: ${{ env.NODE_VERSION }} - cache: 'yarn' + script: | + const head = context.payload.ref.replace('refs/heads/', ''); + const base = 'main'; + const title = 'Merge ' + head + ' into ' + base + ' 🔀'; + const body = 'This is an automated PR'; - - name: Setup Java - uses: actions/setup-java@v3 - with: - java-version: ${{ env.JAVA_VERSION }} - distribution: 'zulu' + async function run() { + try { + const { data: pulls } = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + head: context.repo.owner + ':' + head, + base: base + }); - - name: Install dependencies - run: yarn install --frozen-lockfile + if (pulls.length > 0) { + const pullNumber = pulls[0].number; + console.log(`Updating existing PR #${pullNumber}`); - - name: Verify - run: yarn verify:android + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pullNumber, + title: title, + body: body + }); + } else { + console.log('Creating new PR'); + await github.rest.pulls.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: title, + body: body, + head: head, + base: base + }); + } + } catch (error) { + console.error('Error processing pull request:', error); + throw error; + } + } + + run(); From cfaf1c005a681770c02544f6ee33352382e249b8 Mon Sep 17 00:00:00 2001 From: Robson Oliveira dos Santos Date: Mon, 18 Dec 2023 19:27:23 -0300 Subject: [PATCH 8/8] ci: update action scripts --- .github/workflows/cd.yaml | 16 ++++++++-------- .github/workflows/ci.yaml | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 98d5a4f..1065202 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -11,26 +11,26 @@ jobs: cd: runs-on: macos-12 permissions: - contents: write # to be able to publish a GitHub release - issues: write # to be able to comment on released issues - pull-requests: write # to be able to comment on released pull requests - id-token: write # to enable use of OIDC for npm provenance + contents: write + issues: write + pull-requests: write + id-token: write steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 1 - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' - name: Install dependencies run: yarn install --frozen-lockfile - name: Release env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: npx semantic-release diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 809a1b0..dc15e15 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: runs-on: macos-13 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 1 @@ -26,18 +26,18 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 1 - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} cache: 'yarn' - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: ${{ env.JAVA_VERSION }} distribution: 'zulu' @@ -52,12 +52,12 @@ jobs: runs-on: macos-13 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 1 - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} cache: 'yarn' @@ -79,7 +79,7 @@ jobs: needs: [lint, verify-ios, verify-android] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0