Skip to content

Commit af11769

Browse files
authored
Merge pull request #59 from PlayerData/async-wrap-upgrade
Async wrap upgrade
2 parents bb29199 + 80b8ff6 commit af11769

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

example/ios/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PODS:
1111
- ReactCommon/turbomodule/core (= 0.68.1)
1212
- fmt (6.2.1)
1313
- glog (0.3.5)
14-
- iOSMcuManagerLibrary (1.1.0):
14+
- iOSMcuManagerLibrary (1.3.2):
1515
- SwiftCBOR (= 0.4.4)
1616
- MultiplatformBleAdapter (0.1.9)
1717
- RCT-Folly (2021.06.28.00-v2):
@@ -229,7 +229,7 @@ PODS:
229229
- react-native-get-random-values (1.8.0):
230230
- React-Core
231231
- react-native-mcu-manager (0.0.1-development):
232-
- iOSMcuManagerLibrary (~> 1.1.0)
232+
- iOSMcuManagerLibrary (~> 1.3.2)
233233
- React-Core
234234
- React-perflogger (0.68.1)
235235
- React-RCTActionSheet (0.68.1):
@@ -424,7 +424,7 @@ SPEC CHECKSUMS:
424424
FBReactNativeSpec: 371350f24afa87b6aba606972ec959dcd4a95c9a
425425
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
426426
glog: 476ee3e89abb49e07f822b48323c51c57124b572
427-
iOSMcuManagerLibrary: 64853befc4e6ff100809069f308cbf6ba38ec033
427+
iOSMcuManagerLibrary: 2dbc3ef6fed190e1c1db2c88d8dacdde8b6dda0d
428428
MultiplatformBleAdapter: 5a6a897b006764392f9cef785e4360f54fb9477d
429429
RCT-Folly: 4d8508a426467c48885f1151029bc15fa5d7b3b8
430430
RCTRequired: 00581111c53531e39e3c6346ef0d2c0cf52a5a37
@@ -442,7 +442,7 @@ SPEC CHECKSUMS:
442442
react-native-ble-plx: f10240444452dfb2d2a13a0e4f58d7783e92d76e
443443
react-native-document-picker: 2b8f18667caee73a96708a82b284a4f40b30a156
444444
react-native-get-random-values: a6ea6a8a65dc93e96e24a11105b1a9c8cfe1d72a
445-
react-native-mcu-manager: 0b8b4258106b8a3c2888a1521a6ae3d5634ba463
445+
react-native-mcu-manager: a7166f610e90374fdff1b80c6db17b9bb7f754b5
446446
React-perflogger: 30ab8d6db10e175626069e742eead3ebe8f24fd5
447447
React-RCTActionSheet: 4b45da334a175b24dabe75f856b98fed3dfd6201
448448
React-RCTAnimation: d6237386cb04500889877845b3e9e9291146bc2e
@@ -460,4 +460,4 @@ SPEC CHECKSUMS:
460460

461461
PODFILE CHECKSUM: c253f0de47435bd522e26588156f2650ee8d47f0
462462

463-
COCOAPODS: 1.12.0
463+
COCOAPODS: 1.12.1

ios/DeviceUpgrade.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ class DeviceUpgrade {
3838
self.upgradeResolver = resolve
3939
self.upgradeRejecter = reject
4040

41-
guard let bleUuid = UUID(uuidString: bleId) else {
41+
guard let bleUuid = UUID(uuidString: self.bleId) else {
4242
let error = NSError(domain: "", code: 200, userInfo: nil)
4343
return reject("error", "failed to parse uuid", error);
4444
}
4545

46-
guard let fileUrl = URL(string: fileURI) else {
46+
guard let fileUrl = URL(string: self.fileURI) else {
4747
let error = NSError(domain: "", code: 200, userInfo: nil)
4848
return reject("error", "failed to parse file uri as url", error);
4949
}
@@ -56,7 +56,7 @@ class DeviceUpgrade {
5656
self.bleTransport = McuMgrBleTransport(bleUuid)
5757
self.dfuManager = FirmwareUpgradeManager(transporter: self.bleTransport!, delegate: self)
5858

59-
let estimatedSwapTime: TimeInterval = options["estimatedSwapTime"] as! TimeInterval
59+
let estimatedSwapTime: TimeInterval = self.options["estimatedSwapTime"] as! TimeInterval
6060
let config = FirmwareUpgradeConfiguration(
6161
estimatedSwapTime: estimatedSwapTime
6262
)

ios/McuManager.swift

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,26 @@ class RNMcuManager: RCTEventEmitter {
2222

2323
@objc
2424
func eraseImage(_ bleId: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
25-
guard let bleUuid = UUID(uuidString: bleId) else {
26-
let error = NSError(domain: "", code: 200, userInfo: nil)
27-
return reject("error", "failed to parse uuid", error);
28-
}
25+
DispatchQueue.main.async {
26+
guard let bleUuid = UUID(uuidString: bleId) else {
27+
let error = NSError(domain: "", code: 200, userInfo: nil)
28+
return reject("error", "failed to parse uuid", error);
29+
}
30+
31+
let bleTransport = McuMgrBleTransport(bleUuid)
32+
let imageManager = ImageManager(transporter: bleTransport)
2933

30-
let bleTransport = McuMgrBleTransport(bleUuid)
31-
let imageManager = ImageManager(transporter: bleTransport)
34+
imageManager.erase { (response: McuMgrResponse?, err: Error?) in
35+
bleTransport.close()
3236

33-
imageManager.erase { (response: McuMgrResponse?, err: Error?) in
34-
bleTransport.close()
37+
if (err != nil) {
38+
reject("ERASE_ERR", err?.localizedDescription, err)
39+
return
40+
}
3541

36-
if (err != nil) {
37-
reject("ERASE_ERR", err?.localizedDescription, err)
42+
resolve(nil)
3843
return
3944
}
40-
41-
resolve(nil)
42-
return
4345
}
4446
}
4547

@@ -50,12 +52,14 @@ class RNMcuManager: RCTEventEmitter {
5052

5153
@objc
5254
func runUpgrade(_ id: String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
53-
guard let upgrade = self.upgrades[id] else {
54-
reject("ID_NOT_FOUND", "Upgrade object not found", nil)
55-
return
56-
}
55+
DispatchQueue.main.async {
56+
guard let upgrade = self.upgrades[id] else {
57+
reject("ID_NOT_FOUND", "Upgrade object not found", nil)
58+
return
59+
}
5760

58-
upgrade.startUpgrade(resolver: resolve, rejecter: reject)
61+
upgrade.startUpgrade(resolver: resolve, rejecter: reject)
62+
}
5963
}
6064

6165
@objc

0 commit comments

Comments
 (0)