@@ -35,40 +35,38 @@ class DeviceUpgrade {
35
35
}
36
36
37
37
func startUpgrade( resolver resolve: @escaping RCTPromiseResolveBlock , rejecter reject: @escaping RCTPromiseRejectBlock ) {
38
- DispatchQueue . main. async {
39
- self . upgradeResolver = resolve
40
- self . upgradeRejecter = reject
41
-
42
- guard let bleUuid = UUID ( uuidString: self . bleId) else {
43
- let error = NSError ( domain: " " , code: 200 , userInfo: nil )
44
- return reject ( " error " , " failed to parse uuid " , error) ;
45
- }
46
-
47
- guard let fileUrl = URL ( string: self . fileURI) else {
48
- let error = NSError ( domain: " " , code: 200 , userInfo: nil )
49
- return reject ( " error " , " failed to parse file uri as url " , error) ;
50
- }
51
-
52
- do {
53
- let filehandle = try FileHandle ( forReadingFrom: fileUrl)
54
- let file = Data ( filehandle. availableData)
55
- filehandle. closeFile ( )
56
-
57
- self . bleTransport = McuMgrBleTransport ( bleUuid)
58
- self . dfuManager = FirmwareUpgradeManager ( transporter: self . bleTransport!, delegate: self )
59
-
60
- let estimatedSwapTime : TimeInterval = self . options [ " estimatedSwapTime " ] as! TimeInterval
61
- let config = FirmwareUpgradeConfiguration (
62
- estimatedSwapTime: estimatedSwapTime
63
- )
64
-
65
- self . dfuManager!. logDelegate = self . logDelegate
66
- self . dfuManager!. mode = self . getMode ( ) ;
67
-
68
- try self . dfuManager!. start ( data: file as Data , using: config)
69
- } catch {
70
- reject ( error. localizedDescription, error. localizedDescription, error)
71
- }
38
+ self . upgradeResolver = resolve
39
+ self . upgradeRejecter = reject
40
+
41
+ guard let bleUuid = UUID ( uuidString: self . bleId) else {
42
+ let error = NSError ( domain: " " , code: 200 , userInfo: nil )
43
+ return reject ( " error " , " failed to parse uuid " , error) ;
44
+ }
45
+
46
+ guard let fileUrl = URL ( string: self . fileURI) else {
47
+ let error = NSError ( domain: " " , code: 200 , userInfo: nil )
48
+ return reject ( " error " , " failed to parse file uri as url " , error) ;
49
+ }
50
+
51
+ do {
52
+ let filehandle = try FileHandle ( forReadingFrom: fileUrl)
53
+ let file = Data ( filehandle. availableData)
54
+ filehandle. closeFile ( )
55
+
56
+ self . bleTransport = McuMgrBleTransport ( bleUuid)
57
+ self . dfuManager = FirmwareUpgradeManager ( transporter: self . bleTransport!, delegate: self )
58
+
59
+ let estimatedSwapTime : TimeInterval = self . options [ " estimatedSwapTime " ] as! TimeInterval
60
+ let config = FirmwareUpgradeConfiguration (
61
+ estimatedSwapTime: estimatedSwapTime
62
+ )
63
+
64
+ self . dfuManager!. logDelegate = self . logDelegate
65
+ self . dfuManager!. mode = self . getMode ( ) ;
66
+
67
+ try self . dfuManager!. start ( data: file as Data , using: config)
68
+ } catch {
69
+ reject ( error. localizedDescription, error. localizedDescription, error)
72
70
}
73
71
}
74
72
0 commit comments