@capgo/capacitor-updater 7.2.20 → 7.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +128 -134
- package/android/src/main/java/ee/forgr/capacitor_updater/{CapacitorUpdater.java → CapgoUpdater.java} +18 -18
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipherV2.java +7 -7
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +21 -24
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +1 -1
- package/ios/Plugin/AES.swift +2 -2
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +93 -93
- package/ios/Plugin/{CapacitorUpdater.swift → CapgoUpdater.swift} +67 -67
- package/ios/Plugin/CryptoCipherV2.swift +25 -25
- package/ios/Plugin/DelayUpdateUtils.swift +23 -23
- package/package.json +1 -1
|
@@ -44,8 +44,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
44
44
|
CAPPluginMethod(name: "isAutoUpdateAvailable", returnType: CAPPluginReturnPromise),
|
|
45
45
|
CAPPluginMethod(name: "getNextBundle", returnType: CAPPluginReturnPromise)
|
|
46
46
|
]
|
|
47
|
-
public var implementation =
|
|
48
|
-
private let PLUGIN_VERSION: String = "7.2.
|
|
47
|
+
public var implementation = CapgoUpdater()
|
|
48
|
+
private let PLUGIN_VERSION: String = "7.2.21"
|
|
49
49
|
static let updateUrlDefault = "https://plugin.capgo.app/updates"
|
|
50
50
|
static let statsUrlDefault = "https://plugin.capgo.app/stats"
|
|
51
51
|
static let channelUrlDefault = "https://plugin.capgo.app/channel_self"
|
|
@@ -71,26 +71,26 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
71
71
|
|
|
72
72
|
override public func load() {
|
|
73
73
|
#if targetEnvironment(simulator)
|
|
74
|
-
print("\(
|
|
75
|
-
print("\(
|
|
74
|
+
print("\(CapgoUpdater.TAG) ::::: SIMULATOR :::::")
|
|
75
|
+
print("\(CapgoUpdater.TAG) Application directory: \(NSHomeDirectory())")
|
|
76
76
|
#endif
|
|
77
77
|
|
|
78
78
|
self.semaphoreUp()
|
|
79
79
|
self.implementation.deviceID = (UserDefaults.standard.string(forKey: "appUUID") ?? UUID().uuidString).lowercased()
|
|
80
80
|
UserDefaults.standard.set( self.implementation.deviceID, forKey: "appUUID")
|
|
81
81
|
UserDefaults.standard.synchronize()
|
|
82
|
-
print("\(
|
|
82
|
+
print("\(CapgoUpdater.TAG) init for device \(self.implementation.deviceID)")
|
|
83
83
|
guard let versionName = getConfig().getString("version", Bundle.main.versionName) else {
|
|
84
|
-
print("\(
|
|
84
|
+
print("\(CapgoUpdater.TAG) Cannot get version name")
|
|
85
85
|
// crash the app
|
|
86
86
|
fatalError("Cannot get version name")
|
|
87
87
|
}
|
|
88
88
|
do {
|
|
89
89
|
currentVersionNative = try Version(versionName)
|
|
90
90
|
} catch {
|
|
91
|
-
print("\(
|
|
91
|
+
print("\(CapgoUpdater.TAG) Cannot parse versionName \(versionName)")
|
|
92
92
|
}
|
|
93
|
-
print("\(
|
|
93
|
+
print("\(CapgoUpdater.TAG) version native \(self.currentVersionNative.description)")
|
|
94
94
|
implementation.versionBuild = getConfig().getString("version", Bundle.main.versionName)!
|
|
95
95
|
autoDeleteFailed = getConfig().getBoolean("autoDeleteFailed", true)
|
|
96
96
|
autoDeletePrevious = getConfig().getBoolean("autoDeletePrevious", true)
|
|
@@ -123,7 +123,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
123
123
|
if implementation.appId == "" {
|
|
124
124
|
fatalError("appId is missing in capacitor.config.json or plugin config, and cannot be retrieved from the native app, please add it globally or in the plugin config")
|
|
125
125
|
}
|
|
126
|
-
print("\(
|
|
126
|
+
print("\(CapgoUpdater.TAG) appId \(implementation.appId)")
|
|
127
127
|
implementation.statsUrl = getConfig().getString("statsUrl", CapacitorUpdaterPlugin.statsUrlDefault)!
|
|
128
128
|
implementation.channelUrl = getConfig().getString("channelUrl", CapacitorUpdaterPlugin.channelUrlDefault)!
|
|
129
129
|
implementation.defaultChannel = getConfig().getString("defaultChannel", "")!
|
|
@@ -141,7 +141,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
141
141
|
// According to martin it is not possible to use serverBasePath on ios in a way that allows us to store the bundle once
|
|
142
142
|
|
|
143
143
|
if !self.initialLoad() {
|
|
144
|
-
print("\(
|
|
144
|
+
print("\(CapgoUpdater.TAG) unable to force reload, the plugin might fallback to the builtin version")
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
let nc = NotificationCenter.default
|
|
@@ -164,18 +164,18 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
if !FileManager.default.fileExists(atPath: dest.path) {
|
|
167
|
-
print("\(
|
|
167
|
+
print("\(CapgoUpdater.TAG) Initial load fail - file at path \(dest.path) doesn't exist. Defaulting to buildin!! \(id)")
|
|
168
168
|
dest = Bundle.main.resourceURL!.appendingPathComponent("public")
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
print("\(
|
|
171
|
+
print("\(CapgoUpdater.TAG) Initial load \(id)")
|
|
172
172
|
// We don't use the viewcontroller here as it does not work during the initial load state
|
|
173
173
|
bridge.setServerBasePath(dest.path)
|
|
174
174
|
return true
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
private func semaphoreWait(waitTime: Int) {
|
|
178
|
-
// print("\(
|
|
178
|
+
// print("\(CapgoUpdater.TAG) semaphoreWait \(waitTime)")
|
|
179
179
|
_ = semaphoreReady.wait(timeout: .now() + .milliseconds(waitTime))
|
|
180
180
|
}
|
|
181
181
|
|
|
@@ -194,16 +194,16 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
194
194
|
do {
|
|
195
195
|
LatestVersionNative = try Version(UserDefaults.standard.string(forKey: "LatestVersionNative") ?? "0.0.0")
|
|
196
196
|
} catch {
|
|
197
|
-
print("\(
|
|
197
|
+
print("\(CapgoUpdater.TAG) Cannot get version native \(currentVersionNative)")
|
|
198
198
|
}
|
|
199
199
|
if LatestVersionNative != "0.0.0" && self.currentVersionNative.description != LatestVersionNative.description {
|
|
200
200
|
_ = self._reset(toLastSuccessful: false)
|
|
201
201
|
let res = implementation.list()
|
|
202
202
|
res.forEach { version in
|
|
203
|
-
print("\(
|
|
203
|
+
print("\(CapgoUpdater.TAG) Deleting obsolete bundle: \(version.getId())")
|
|
204
204
|
let res = implementation.delete(id: version.getId())
|
|
205
205
|
if !res {
|
|
206
|
-
print("\(
|
|
206
|
+
print("\(CapgoUpdater.TAG) Delete failed, id \(version.getId()) doesn't exist")
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
}
|
|
@@ -224,12 +224,12 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
224
224
|
|
|
225
225
|
@objc func setUpdateUrl(_ call: CAPPluginCall) {
|
|
226
226
|
if !getConfig().getBoolean("allowModifyUrl", false) {
|
|
227
|
-
print("\(
|
|
227
|
+
print("\(CapgoUpdater.TAG) setUpdateUrl called without allowModifyUrl")
|
|
228
228
|
call.reject("setUpdateUrl called without allowModifyUrl set allowModifyUrl in your config to true to allow it")
|
|
229
229
|
return
|
|
230
230
|
}
|
|
231
231
|
guard let url = call.getString("url") else {
|
|
232
|
-
print("\(
|
|
232
|
+
print("\(CapgoUpdater.TAG) setUpdateUrl called without url")
|
|
233
233
|
call.reject("setUpdateUrl called without url")
|
|
234
234
|
return
|
|
235
235
|
}
|
|
@@ -239,12 +239,12 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
239
239
|
|
|
240
240
|
@objc func setStatsUrl(_ call: CAPPluginCall) {
|
|
241
241
|
if !getConfig().getBoolean("allowModifyUrl", false) {
|
|
242
|
-
print("\(
|
|
242
|
+
print("\(CapgoUpdater.TAG) setStatsUrl called without allowModifyUrl")
|
|
243
243
|
call.reject("setStatsUrl called without allowModifyUrl set allowModifyUrl in your config to true to allow it")
|
|
244
244
|
return
|
|
245
245
|
}
|
|
246
246
|
guard let url = call.getString("url") else {
|
|
247
|
-
print("\(
|
|
247
|
+
print("\(CapgoUpdater.TAG) setStatsUrl called without url")
|
|
248
248
|
call.reject("setStatsUrl called without url")
|
|
249
249
|
return
|
|
250
250
|
}
|
|
@@ -254,12 +254,12 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
254
254
|
|
|
255
255
|
@objc func setChannelUrl(_ call: CAPPluginCall) {
|
|
256
256
|
if !getConfig().getBoolean("allowModifyUrl", false) {
|
|
257
|
-
print("\(
|
|
257
|
+
print("\(CapgoUpdater.TAG) setChannelUrl called without allowModifyUrl")
|
|
258
258
|
call.reject("setChannelUrl called without allowModifyUrl set allowModifyUrl in your config to true to allow it")
|
|
259
259
|
return
|
|
260
260
|
}
|
|
261
261
|
guard let url = call.getString("url") else {
|
|
262
|
-
print("\(
|
|
262
|
+
print("\(CapgoUpdater.TAG) setChannelUrl called without url")
|
|
263
263
|
call.reject("setChannelUrl called without url")
|
|
264
264
|
return
|
|
265
265
|
}
|
|
@@ -281,12 +281,12 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
281
281
|
|
|
282
282
|
@objc func download(_ call: CAPPluginCall) {
|
|
283
283
|
guard let urlString = call.getString("url") else {
|
|
284
|
-
print("\(
|
|
284
|
+
print("\(CapgoUpdater.TAG) Download called without url")
|
|
285
285
|
call.reject("Download called without url")
|
|
286
286
|
return
|
|
287
287
|
}
|
|
288
288
|
guard let version = call.getString("version") else {
|
|
289
|
-
print("\(
|
|
289
|
+
print("\(CapgoUpdater.TAG) Download called without version")
|
|
290
290
|
call.reject("Download called without version")
|
|
291
291
|
return
|
|
292
292
|
}
|
|
@@ -294,39 +294,39 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
294
294
|
let sessionKey = call.getString("sessionKey", "")
|
|
295
295
|
var checksum = call.getString("checksum", "")
|
|
296
296
|
let url = URL(string: urlString)
|
|
297
|
-
print("\(
|
|
297
|
+
print("\(CapgoUpdater.TAG) Downloading \(String(describing: url))")
|
|
298
298
|
DispatchQueue.global(qos: .background).async {
|
|
299
299
|
do {
|
|
300
300
|
let next = try self.implementation.download(url: url!, version: version, sessionKey: sessionKey)
|
|
301
301
|
// If public key is present but no checksum provided, refuse installation
|
|
302
302
|
if self.implementation.publicKey != "" && checksum == "" {
|
|
303
|
-
print("\(
|
|
303
|
+
print("\(CapgoUpdater.TAG) Public key present but no checksum provided")
|
|
304
304
|
self.implementation.sendStats(action: "checksum_required", versionName: next.getVersionName())
|
|
305
305
|
let id = next.getId()
|
|
306
306
|
let resDel = self.implementation.delete(id: id)
|
|
307
307
|
if !resDel {
|
|
308
|
-
print("\(
|
|
308
|
+
print("\(CapgoUpdater.TAG) Delete failed, id \(id) doesn't exist")
|
|
309
309
|
}
|
|
310
310
|
throw ObjectSavableError.checksum
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
checksum = try CryptoCipherV2.decryptChecksum(checksum: checksum, publicKey: self.implementation.publicKey)
|
|
314
314
|
if (checksum != "" || self.implementation.publicKey != "") && next.getChecksum() != checksum {
|
|
315
|
-
print("\(
|
|
315
|
+
print("\(CapgoUpdater.TAG) Error checksum", next.getChecksum(), checksum)
|
|
316
316
|
self.implementation.sendStats(action: "checksum_fail", versionName: next.getVersionName())
|
|
317
317
|
let id = next.getId()
|
|
318
318
|
let resDel = self.implementation.delete(id: id)
|
|
319
319
|
if !resDel {
|
|
320
|
-
print("\(
|
|
320
|
+
print("\(CapgoUpdater.TAG) Delete failed, id \(id) doesn't exist")
|
|
321
321
|
}
|
|
322
322
|
throw ObjectSavableError.checksum
|
|
323
323
|
} else {
|
|
324
|
-
print("\(
|
|
324
|
+
print("\(CapgoUpdater.TAG) Good checksum", next.getChecksum(), checksum)
|
|
325
325
|
}
|
|
326
326
|
self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
|
|
327
327
|
call.resolve(next.toJSON())
|
|
328
328
|
} catch {
|
|
329
|
-
print("\(
|
|
329
|
+
print("\(CapgoUpdater.TAG) Failed to download from: \(String(describing: url)) \(error.localizedDescription)")
|
|
330
330
|
self.notifyListeners("downloadFailed", data: ["version": version])
|
|
331
331
|
self.implementation.sendStats(action: "download_fail")
|
|
332
332
|
call.reject("Failed to download from: \(url!)", error.localizedDescription)
|
|
@@ -344,16 +344,16 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
344
344
|
} else {
|
|
345
345
|
dest = self.implementation.getBundleDirectory(id: id)
|
|
346
346
|
}
|
|
347
|
-
print("\(
|
|
347
|
+
print("\(CapgoUpdater.TAG) Reloading \(id)")
|
|
348
348
|
if let vc = bridge.viewController as? CAPBridgeViewController {
|
|
349
349
|
guard let capBridge = vc.bridge else {
|
|
350
|
-
print("\(
|
|
350
|
+
print("\(CapgoUpdater.TAG) Cannot get capBridge")
|
|
351
351
|
return false
|
|
352
352
|
}
|
|
353
353
|
if keepUrlPathAfterReload {
|
|
354
354
|
DispatchQueue.main.async {
|
|
355
355
|
guard let url = vc.webView?.url else {
|
|
356
|
-
print("\(
|
|
356
|
+
print("\(CapgoUpdater.TAG) vc.webView?.url is null?")
|
|
357
357
|
return
|
|
358
358
|
}
|
|
359
359
|
capBridge.setServerBasePath(dest.path)
|
|
@@ -379,20 +379,20 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
379
379
|
if self._reload() {
|
|
380
380
|
call.resolve()
|
|
381
381
|
} else {
|
|
382
|
-
print("\(
|
|
382
|
+
print("\(CapgoUpdater.TAG) Reload failed")
|
|
383
383
|
call.reject("Reload failed")
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
|
|
387
387
|
@objc func next(_ call: CAPPluginCall) {
|
|
388
388
|
guard let id = call.getString("id") else {
|
|
389
|
-
print("\(
|
|
389
|
+
print("\(CapgoUpdater.TAG) Next called without id")
|
|
390
390
|
call.reject("Next called without id")
|
|
391
391
|
return
|
|
392
392
|
}
|
|
393
|
-
print("\(
|
|
393
|
+
print("\(CapgoUpdater.TAG) Setting next active id \(id)")
|
|
394
394
|
if !self.implementation.setNextBundle(next: id) {
|
|
395
|
-
print("\(
|
|
395
|
+
print("\(CapgoUpdater.TAG) Set next version failed. id \(id) does not exist.")
|
|
396
396
|
call.reject("Set next version failed. id \(id) does not exist.")
|
|
397
397
|
} else {
|
|
398
398
|
call.resolve(self.implementation.getBundleInfo(id: id).toJSON())
|
|
@@ -401,14 +401,14 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
401
401
|
|
|
402
402
|
@objc func set(_ call: CAPPluginCall) {
|
|
403
403
|
guard let id = call.getString("id") else {
|
|
404
|
-
print("\(
|
|
404
|
+
print("\(CapgoUpdater.TAG) Set called without id")
|
|
405
405
|
call.reject("Set called without id")
|
|
406
406
|
return
|
|
407
407
|
}
|
|
408
408
|
let res = implementation.set(id: id)
|
|
409
|
-
print("\(
|
|
409
|
+
print("\(CapgoUpdater.TAG) Set active bundle: \(id)")
|
|
410
410
|
if !res {
|
|
411
|
-
print("\(
|
|
411
|
+
print("\(CapgoUpdater.TAG) Bundle successfully set to: \(id) ")
|
|
412
412
|
call.reject("Update failed, id \(id) doesn't exist")
|
|
413
413
|
} else {
|
|
414
414
|
self.reload(call)
|
|
@@ -417,7 +417,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
417
417
|
|
|
418
418
|
@objc func delete(_ call: CAPPluginCall) {
|
|
419
419
|
guard let id = call.getString("id") else {
|
|
420
|
-
print("\(
|
|
420
|
+
print("\(CapgoUpdater.TAG) Delete called without version")
|
|
421
421
|
call.reject("Delete called without id")
|
|
422
422
|
return
|
|
423
423
|
}
|
|
@@ -425,7 +425,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
425
425
|
if res {
|
|
426
426
|
call.resolve()
|
|
427
427
|
} else {
|
|
428
|
-
print("\(
|
|
428
|
+
print("\(CapgoUpdater.TAG) Delete failed, id \(id) doesn't exist or it cannot be deleted (perhaps it is the 'next' bundle)")
|
|
429
429
|
call.reject("Delete failed, id \(id) does not exist or it cannot be deleted (perhaps it is the 'next' bundle)")
|
|
430
430
|
}
|
|
431
431
|
}
|
|
@@ -464,7 +464,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
464
464
|
call.reject(res.error)
|
|
465
465
|
} else {
|
|
466
466
|
if self._isAutoUpdateEnabled() && triggerAutoUpdate {
|
|
467
|
-
print("\(
|
|
467
|
+
print("\(CapgoUpdater.TAG) Calling autoupdater after channel change!")
|
|
468
468
|
self.backgroundDownload()
|
|
469
469
|
}
|
|
470
470
|
call.resolve(res.toDict())
|
|
@@ -474,7 +474,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
474
474
|
|
|
475
475
|
@objc func setChannel(_ call: CAPPluginCall) {
|
|
476
476
|
guard let channel = call.getString("channel") else {
|
|
477
|
-
print("\(
|
|
477
|
+
print("\(CapgoUpdater.TAG) setChannel called without channel")
|
|
478
478
|
call.reject("setChannel called without channel")
|
|
479
479
|
return
|
|
480
480
|
}
|
|
@@ -485,7 +485,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
485
485
|
call.reject(res.error)
|
|
486
486
|
} else {
|
|
487
487
|
if self._isAutoUpdateEnabled() && triggerAutoUpdate {
|
|
488
|
-
print("\(
|
|
488
|
+
print("\(CapgoUpdater.TAG) Calling autoupdater after channel change!")
|
|
489
489
|
self.backgroundDownload()
|
|
490
490
|
}
|
|
491
491
|
call.resolve(res.toDict())
|
|
@@ -505,7 +505,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
505
505
|
}
|
|
506
506
|
@objc func setCustomId(_ call: CAPPluginCall) {
|
|
507
507
|
guard let customId = call.getString("customId") else {
|
|
508
|
-
print("\(
|
|
508
|
+
print("\(CapgoUpdater.TAG) setCustomId called without customId")
|
|
509
509
|
call.reject("setCustomId called without customId")
|
|
510
510
|
return
|
|
511
511
|
}
|
|
@@ -521,11 +521,11 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
521
521
|
// If developer wants to reset to the last successful bundle, and that bundle is not
|
|
522
522
|
// the built-in bundle, set it as the bundle to use and reload.
|
|
523
523
|
if toLastSuccessful && !fallback.isBuiltin() {
|
|
524
|
-
print("\(
|
|
524
|
+
print("\(CapgoUpdater.TAG) Resetting to: \(fallback.toString())")
|
|
525
525
|
return self.implementation.set(bundle: fallback) && self._reload()
|
|
526
526
|
}
|
|
527
527
|
|
|
528
|
-
print("\(
|
|
528
|
+
print("\(CapgoUpdater.TAG) Resetting to builtin version")
|
|
529
529
|
|
|
530
530
|
// Otherwise, reset back to the built-in bundle and reload.
|
|
531
531
|
self.implementation.reset()
|
|
@@ -540,8 +540,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
540
540
|
if self._reset(toLastSuccessful: toLastSuccessful) {
|
|
541
541
|
call.resolve()
|
|
542
542
|
} else {
|
|
543
|
-
print("\(
|
|
544
|
-
call.reject("\(
|
|
543
|
+
print("\(CapgoUpdater.TAG) Reset failed")
|
|
544
|
+
call.reject("\(CapgoUpdater.TAG) Reset failed")
|
|
545
545
|
}
|
|
546
546
|
}
|
|
547
547
|
|
|
@@ -557,13 +557,13 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
557
557
|
self.semaphoreDown()
|
|
558
558
|
let bundle = self.implementation.getCurrentBundle()
|
|
559
559
|
self.implementation.setSuccess(bundle: bundle, autoDeletePrevious: self.autoDeletePrevious)
|
|
560
|
-
print("\(
|
|
560
|
+
print("\(CapgoUpdater.TAG) Current bundle loaded successfully. ['notifyAppReady()' was called] \(bundle.toString())")
|
|
561
561
|
call.resolve(["bundle": bundle.toJSON()])
|
|
562
562
|
}
|
|
563
563
|
|
|
564
564
|
@objc func setMultiDelay(_ call: CAPPluginCall) {
|
|
565
565
|
guard let delayConditionList = call.getValue("delayConditions") else {
|
|
566
|
-
print("\(
|
|
566
|
+
print("\(CapgoUpdater.TAG) setMultiDelay called without delayCondition")
|
|
567
567
|
call.reject("setMultiDelay called without delayCondition")
|
|
568
568
|
return
|
|
569
569
|
}
|
|
@@ -609,7 +609,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
609
609
|
private func _isAutoUpdateEnabled() -> Bool {
|
|
610
610
|
let instanceDescriptor = (self.bridge?.viewController as? CAPBridgeViewController)?.instanceDescriptor()
|
|
611
611
|
if instanceDescriptor?.serverURL != nil {
|
|
612
|
-
print("⚠️ \(
|
|
612
|
+
print("⚠️ \(CapgoUpdater.TAG) AutoUpdate is automatic disabled when serverUrl is set.")
|
|
613
613
|
}
|
|
614
614
|
return self.autoUpdate && self.updateUrl != "" && instanceDescriptor?.serverURL == nil
|
|
615
615
|
}
|
|
@@ -633,7 +633,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
633
633
|
self.appReadyCheck = DispatchWorkItem(block: {
|
|
634
634
|
self.DeferredNotifyAppReadyCheck()
|
|
635
635
|
})
|
|
636
|
-
print("\(
|
|
636
|
+
print("\(CapgoUpdater.TAG) Wait for \(self.appReadyTimeout) ms, then check for notifyAppReady")
|
|
637
637
|
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(self.appReadyTimeout), execute: self.appReadyCheck!)
|
|
638
638
|
}
|
|
639
639
|
|
|
@@ -641,15 +641,15 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
641
641
|
// Automatically roll back to fallback version if notifyAppReady has not been called yet
|
|
642
642
|
let current: BundleInfo = self.implementation.getCurrentBundle()
|
|
643
643
|
if current.isBuiltin() {
|
|
644
|
-
print("\(
|
|
644
|
+
print("\(CapgoUpdater.TAG) Built-in bundle is active. We skip the check for notifyAppReady.")
|
|
645
645
|
return
|
|
646
646
|
}
|
|
647
647
|
|
|
648
|
-
print("\(
|
|
648
|
+
print("\(CapgoUpdater.TAG) Current bundle is: \(current.toString())")
|
|
649
649
|
|
|
650
650
|
if BundleStatus.SUCCESS.localizedString != current.getStatus() {
|
|
651
|
-
print("\(
|
|
652
|
-
print("\(
|
|
651
|
+
print("\(CapgoUpdater.TAG) notifyAppReady was not called, roll back current bundle: \(current.toString())")
|
|
652
|
+
print("\(CapgoUpdater.TAG) Did you forget to call 'notifyAppReady()' in your Capacitor App code?")
|
|
653
653
|
self.notifyListeners("updateFailed", data: [
|
|
654
654
|
"bundle": current.toJSON()
|
|
655
655
|
])
|
|
@@ -657,16 +657,16 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
657
657
|
self.implementation.setError(bundle: current)
|
|
658
658
|
_ = self._reset(toLastSuccessful: true)
|
|
659
659
|
if self.autoDeleteFailed && !current.isBuiltin() {
|
|
660
|
-
print("\(
|
|
660
|
+
print("\(CapgoUpdater.TAG) Deleting failing bundle: \(current.toString())")
|
|
661
661
|
let res = self.implementation.delete(id: current.getId(), removeInfo: false)
|
|
662
662
|
if !res {
|
|
663
|
-
print("\(
|
|
663
|
+
print("\(CapgoUpdater.TAG) Delete version deleted: \(current.toString())")
|
|
664
664
|
} else {
|
|
665
|
-
print("\(
|
|
665
|
+
print("\(CapgoUpdater.TAG) Failed to delete failed bundle: \(current.toString())")
|
|
666
666
|
}
|
|
667
667
|
}
|
|
668
668
|
} else {
|
|
669
|
-
print("\(
|
|
669
|
+
print("\(CapgoUpdater.TAG) notifyAppReady was called. This is fine: \(current.toString())")
|
|
670
670
|
}
|
|
671
671
|
}
|
|
672
672
|
|
|
@@ -681,7 +681,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
681
681
|
}
|
|
682
682
|
|
|
683
683
|
func sendReadyToJs(current: BundleInfo, msg: String) {
|
|
684
|
-
print("\(
|
|
684
|
+
print("\(CapgoUpdater.TAG) sendReadyToJs")
|
|
685
685
|
DispatchQueue.global().async {
|
|
686
686
|
self.semaphoreWait(waitTime: self.appReadyTimeout)
|
|
687
687
|
self.notifyListeners("appReady", data: ["bundle": current.toJSON(), "status": msg])
|
|
@@ -695,14 +695,14 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
695
695
|
}
|
|
696
696
|
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
697
697
|
self.sendReadyToJs(current: current, msg: msg)
|
|
698
|
-
print("\(
|
|
698
|
+
print("\(CapgoUpdater.TAG) endBackGroundTaskWithNotif \(msg) current: \(current.getVersionName()) latestVersionName: \(latestVersionName)")
|
|
699
699
|
self.endBackGroundTask()
|
|
700
700
|
}
|
|
701
701
|
|
|
702
702
|
func backgroundDownload() {
|
|
703
703
|
let messageUpdate = self.directUpdate ? "Update will occur now." : "Update will occur next time app moves to background."
|
|
704
704
|
guard let url = URL(string: self.updateUrl) else {
|
|
705
|
-
print("\(
|
|
705
|
+
print("\(CapgoUpdater.TAG) Error no url or wrong format")
|
|
706
706
|
return
|
|
707
707
|
}
|
|
708
708
|
DispatchQueue.global(qos: .background).async {
|
|
@@ -710,12 +710,12 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
710
710
|
// End the task if time expires.
|
|
711
711
|
self.endBackGroundTask()
|
|
712
712
|
}
|
|
713
|
-
print("\(
|
|
713
|
+
print("\(CapgoUpdater.TAG) Check for update via \(self.updateUrl)")
|
|
714
714
|
let res = self.implementation.getLatest(url: url, channel: nil)
|
|
715
715
|
let current = self.implementation.getCurrentBundle()
|
|
716
716
|
|
|
717
717
|
if (res.message) != nil {
|
|
718
|
-
print("\(
|
|
718
|
+
print("\(CapgoUpdater.TAG) API message: \(res.message ?? "")")
|
|
719
719
|
if res.major == true {
|
|
720
720
|
self.notifyListeners("majorAvailable", data: ["version": res.version])
|
|
721
721
|
}
|
|
@@ -723,13 +723,13 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
723
723
|
return
|
|
724
724
|
}
|
|
725
725
|
if res.version == "builtin" {
|
|
726
|
-
print("\(
|
|
726
|
+
print("\(CapgoUpdater.TAG) Latest version is builtin")
|
|
727
727
|
if self.directUpdate {
|
|
728
|
-
print("\(
|
|
728
|
+
print("\(CapgoUpdater.TAG) Direct update to builtin version")
|
|
729
729
|
_ = self._reset(toLastSuccessful: false)
|
|
730
730
|
self.endBackGroundTaskWithNotif(msg: "Updated to builtin version", latestVersionName: res.version, current: self.implementation.getCurrentBundle(), error: false)
|
|
731
731
|
} else {
|
|
732
|
-
print("\(
|
|
732
|
+
print("\(CapgoUpdater.TAG) Setting next bundle to builtin")
|
|
733
733
|
_ = self.implementation.setNextBundle(next: BundleInfo.ID_BUILTIN)
|
|
734
734
|
self.endBackGroundTaskWithNotif(msg: "Next update will be to builtin version", latestVersionName: res.version, current: current, error: false)
|
|
735
735
|
}
|
|
@@ -737,23 +737,23 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
737
737
|
}
|
|
738
738
|
let sessionKey = res.sessionKey ?? ""
|
|
739
739
|
guard let downloadUrl = URL(string: res.url) else {
|
|
740
|
-
print("\(
|
|
740
|
+
print("\(CapgoUpdater.TAG) Error no url or wrong format")
|
|
741
741
|
self.endBackGroundTaskWithNotif(msg: "Error no url or wrong format", latestVersionName: res.version, current: current)
|
|
742
742
|
return
|
|
743
743
|
}
|
|
744
744
|
let latestVersionName = res.version
|
|
745
745
|
if latestVersionName != "" && current.getVersionName() != latestVersionName {
|
|
746
746
|
do {
|
|
747
|
-
print("\(
|
|
747
|
+
print("\(CapgoUpdater.TAG) New bundle: \(latestVersionName) found. Current is: \(current.getVersionName()). \(messageUpdate)")
|
|
748
748
|
var nextImpl = self.implementation.getBundleInfoByVersionName(version: latestVersionName)
|
|
749
749
|
if nextImpl == nil || nextImpl?.isDeleted() == true {
|
|
750
750
|
if nextImpl?.isDeleted() == true {
|
|
751
|
-
print("\(
|
|
751
|
+
print("\(CapgoUpdater.TAG) Latest bundle already exists and will be deleted, download will overwrite it.")
|
|
752
752
|
let res = self.implementation.delete(id: nextImpl!.getId(), removeInfo: true)
|
|
753
753
|
if res {
|
|
754
|
-
print("\(
|
|
754
|
+
print("\(CapgoUpdater.TAG) Failed bundle deleted: \(nextImpl!.toString())")
|
|
755
755
|
} else {
|
|
756
|
-
print("\(
|
|
756
|
+
print("\(CapgoUpdater.TAG) Failed to delete failed bundle: \(nextImpl!.toString())")
|
|
757
757
|
}
|
|
758
758
|
}
|
|
759
759
|
if res.manifest != nil {
|
|
@@ -763,23 +763,23 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
763
763
|
}
|
|
764
764
|
}
|
|
765
765
|
guard let next = nextImpl else {
|
|
766
|
-
print("\(
|
|
766
|
+
print("\(CapgoUpdater.TAG) Error downloading file")
|
|
767
767
|
self.endBackGroundTaskWithNotif(msg: "Error downloading file", latestVersionName: latestVersionName, current: current)
|
|
768
768
|
return
|
|
769
769
|
}
|
|
770
770
|
if next.isErrorStatus() {
|
|
771
|
-
print("\(
|
|
771
|
+
print("\(CapgoUpdater.TAG) Latest bundle already exists and is in error state. Aborting update.")
|
|
772
772
|
self.endBackGroundTaskWithNotif(msg: "Latest version is in error state. Aborting update.", latestVersionName: latestVersionName, current: current)
|
|
773
773
|
return
|
|
774
774
|
}
|
|
775
775
|
res.checksum = try CryptoCipherV2.decryptChecksum(checksum: res.checksum, publicKey: self.implementation.publicKey)
|
|
776
776
|
if res.checksum != "" && next.getChecksum() != res.checksum && res.manifest == nil {
|
|
777
|
-
print("\(
|
|
777
|
+
print("\(CapgoUpdater.TAG) Error checksum", next.getChecksum(), res.checksum)
|
|
778
778
|
self.implementation.sendStats(action: "checksum_fail", versionName: next.getVersionName())
|
|
779
779
|
let id = next.getId()
|
|
780
780
|
let resDel = self.implementation.delete(id: id)
|
|
781
781
|
if !resDel {
|
|
782
|
-
print("\(
|
|
782
|
+
print("\(CapgoUpdater.TAG) Delete failed, id \(id) doesn't exist")
|
|
783
783
|
}
|
|
784
784
|
self.endBackGroundTaskWithNotif(msg: "Error checksum", latestVersionName: latestVersionName, current: current)
|
|
785
785
|
return
|
|
@@ -792,7 +792,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
792
792
|
return DelayCondition(kind: kind, value: value)
|
|
793
793
|
}
|
|
794
794
|
if !delayConditionList.isEmpty {
|
|
795
|
-
print("\(
|
|
795
|
+
print("\(CapgoUpdater.TAG) Update delayed until delay conditions met")
|
|
796
796
|
self.endBackGroundTaskWithNotif(msg: "Update delayed until delay conditions met", latestVersionName: latestVersionName, current: next, error: false)
|
|
797
797
|
return
|
|
798
798
|
}
|
|
@@ -806,13 +806,13 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
806
806
|
}
|
|
807
807
|
return
|
|
808
808
|
} catch {
|
|
809
|
-
print("\(
|
|
809
|
+
print("\(CapgoUpdater.TAG) Error downloading file", error.localizedDescription)
|
|
810
810
|
let current: BundleInfo = self.implementation.getCurrentBundle()
|
|
811
811
|
self.endBackGroundTaskWithNotif(msg: "Error downloading file", latestVersionName: latestVersionName, current: current)
|
|
812
812
|
return
|
|
813
813
|
}
|
|
814
814
|
} else {
|
|
815
|
-
print("\(
|
|
815
|
+
print("\(CapgoUpdater.TAG) No need to update, \(current.getId()) is the latest bundle.")
|
|
816
816
|
self.endBackGroundTaskWithNotif(msg: "No need to update, \(current.getId()) is the latest bundle.", latestVersionName: latestVersionName, current: current, error: false)
|
|
817
817
|
return
|
|
818
818
|
}
|
|
@@ -820,7 +820,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
820
820
|
}
|
|
821
821
|
|
|
822
822
|
@objc func appKilled() {
|
|
823
|
-
print("\(
|
|
823
|
+
print("\(CapgoUpdater.TAG) onActivityDestroyed: all activity destroyed")
|
|
824
824
|
self.delayUpdateUtils.checkCancelDelay(source: .killed)
|
|
825
825
|
}
|
|
826
826
|
|
|
@@ -832,19 +832,19 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
832
832
|
return DelayCondition(kind: kind, value: value)
|
|
833
833
|
}
|
|
834
834
|
if !delayConditionList.isEmpty {
|
|
835
|
-
print("\(
|
|
835
|
+
print("\(CapgoUpdater.TAG) Update delayed until delay conditions met")
|
|
836
836
|
return
|
|
837
837
|
}
|
|
838
838
|
let current: BundleInfo = self.implementation.getCurrentBundle()
|
|
839
839
|
let next: BundleInfo? = self.implementation.getNextBundle()
|
|
840
840
|
|
|
841
841
|
if next != nil && !next!.isErrorStatus() && next!.getVersionName() != current.getVersionName() {
|
|
842
|
-
print("\(
|
|
842
|
+
print("\(CapgoUpdater.TAG) Next bundle is: \(next!.toString())")
|
|
843
843
|
if self.implementation.set(bundle: next!) && self._reload() {
|
|
844
|
-
print("\(
|
|
844
|
+
print("\(CapgoUpdater.TAG) Updated to bundle: \(next!.toString())")
|
|
845
845
|
_ = self.implementation.setNextBundle(next: Optional<String>.none)
|
|
846
846
|
} else {
|
|
847
|
-
print("\(
|
|
847
|
+
print("\(CapgoUpdater.TAG) Update to bundle: \(next!.toString()) Failed!")
|
|
848
848
|
}
|
|
849
849
|
}
|
|
850
850
|
}
|
|
@@ -874,12 +874,12 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
874
874
|
self.delayUpdateUtils.unsetBackgroundTimestamp()
|
|
875
875
|
if backgroundWork != nil && taskRunning {
|
|
876
876
|
backgroundWork!.cancel()
|
|
877
|
-
print("\(
|
|
877
|
+
print("\(CapgoUpdater.TAG) Background Timer Task canceled, Activity resumed before timer completes")
|
|
878
878
|
}
|
|
879
879
|
if self._isAutoUpdateEnabled() {
|
|
880
880
|
self.backgroundDownload()
|
|
881
881
|
} else {
|
|
882
|
-
print("\(
|
|
882
|
+
print("\(CapgoUpdater.TAG) Auto update is disabled")
|
|
883
883
|
self.sendReadyToJs(current: current, msg: "disabled")
|
|
884
884
|
}
|
|
885
885
|
self.checkAppReady()
|
|
@@ -890,7 +890,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
890
890
|
return
|
|
891
891
|
}
|
|
892
892
|
guard let url = URL(string: self.updateUrl) else {
|
|
893
|
-
print("\(
|
|
893
|
+
print("\(CapgoUpdater.TAG) Error no url or wrong format")
|
|
894
894
|
return
|
|
895
895
|
}
|
|
896
896
|
let timer = Timer.scheduledTimer(withTimeInterval: TimeInterval(periodCheckDelay), repeats: true) { _ in
|
|
@@ -899,7 +899,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
899
899
|
let current = self.implementation.getCurrentBundle()
|
|
900
900
|
|
|
901
901
|
if res.version != current.getVersionName() {
|
|
902
|
-
print("\(
|
|
902
|
+
print("\(CapgoUpdater.TAG) New version found: \(res.version)")
|
|
903
903
|
self.backgroundDownload()
|
|
904
904
|
}
|
|
905
905
|
}
|
|
@@ -910,7 +910,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
910
910
|
@objc func appMovedToBackground() {
|
|
911
911
|
let current: BundleInfo = self.implementation.getCurrentBundle()
|
|
912
912
|
self.implementation.sendStats(action: "app_moved_to_background", versionName: current.getVersionName())
|
|
913
|
-
print("\(
|
|
913
|
+
print("\(CapgoUpdater.TAG) Check for pending update")
|
|
914
914
|
|
|
915
915
|
// Set background timestamp
|
|
916
916
|
let backgroundTimestamp = Int64(Date().timeIntervalSince1970 * 1000) // Convert to milliseconds
|