@capgo/capacitor-updater 4.2.2 → 4.2.4
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/BundleInfo.java +13 -11
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +3 -2
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +71 -77
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +185 -168
- package/dist/docs.json +2 -2
- package/dist/esm/definitions.d.ts +8 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.js +9 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +10 -4
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +10 -4
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/BundleInfo.swift +5 -7
- package/ios/Plugin/BundleStatus.swift +3 -3
- package/ios/Plugin/CapacitorUpdater.swift +82 -82
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +43 -43
- package/ios/Plugin/ObjectPreferences.swift +1 -1
- package/package.json +2 -2
|
@@ -22,7 +22,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
22
22
|
private var resetWhenUpdate = true
|
|
23
23
|
private var autoDeleteFailed = false
|
|
24
24
|
private var autoDeletePrevious = false
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
override public func load() {
|
|
27
27
|
print("\(self.implementation.TAG) init for device \(self.implementation.deviceID)")
|
|
28
28
|
do {
|
|
@@ -40,11 +40,11 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
40
40
|
implementation.appId = Bundle.main.bundleIdentifier ?? ""
|
|
41
41
|
implementation.notifyDownload = notifyDownload
|
|
42
42
|
let config = (self.bridge?.viewController as? CAPBridgeViewController)?.instanceDescriptor().legacyConfig
|
|
43
|
-
if
|
|
43
|
+
if config?["appId"] != nil {
|
|
44
44
|
implementation.appId = config?["appId"] as! String
|
|
45
45
|
}
|
|
46
46
|
implementation.statsUrl = getConfig().getString("statsUrl") ?? CapacitorUpdaterPlugin.updateUrlDefault
|
|
47
|
-
if
|
|
47
|
+
if resetWhenUpdate {
|
|
48
48
|
self.cleanupObsoleteVersions()
|
|
49
49
|
}
|
|
50
50
|
let nc = NotificationCenter.default
|
|
@@ -61,7 +61,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
61
61
|
} catch {
|
|
62
62
|
print("\(self.implementation.TAG) Cannot get version native \(currentVersionNative)")
|
|
63
63
|
}
|
|
64
|
-
if
|
|
64
|
+
if LatestVersionNative != "0.0.0" && currentVersionNative.major > LatestVersionNative.major {
|
|
65
65
|
_ = self._reset(toLastSuccessful: false)
|
|
66
66
|
let res = implementation.list()
|
|
67
67
|
res.forEach { version in
|
|
@@ -76,7 +76,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
76
76
|
@objc func notifyDownload(id: String, percent: Int) {
|
|
77
77
|
let bundle = self.implementation.getBundleInfo(id: id)
|
|
78
78
|
self.notifyListeners("download", data: ["percent": percent, "bundle": bundle.toJSON()])
|
|
79
|
-
if
|
|
79
|
+
if percent == 100 {
|
|
80
80
|
self.notifyListeners("downloadComplete", data: ["bundle": bundle.toJSON()])
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -88,7 +88,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
88
88
|
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
|
89
89
|
call.resolve(["version": implementation.pluginVersion])
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
@objc func download(_ call: CAPPluginCall) {
|
|
93
93
|
guard let urlString = call.getString("url") else {
|
|
94
94
|
print("\(self.implementation.TAG) Download called without url")
|
|
@@ -124,9 +124,9 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
124
124
|
}
|
|
125
125
|
return false
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
@objc func reload(_ call: CAPPluginCall) {
|
|
129
|
-
if
|
|
129
|
+
if self._reload() {
|
|
130
130
|
call.resolve()
|
|
131
131
|
} else {
|
|
132
132
|
print("\(self.implementation.TAG) Reload failed")
|
|
@@ -141,14 +141,14 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
141
141
|
return
|
|
142
142
|
}
|
|
143
143
|
print("\(self.implementation.TAG) Setting next active id \(id)")
|
|
144
|
-
if
|
|
144
|
+
if !self.implementation.setNextBundle(next: id) {
|
|
145
145
|
print("\(self.implementation.TAG) Set next version failed. id \(id) does not exist.")
|
|
146
146
|
call.reject("Set next version failed. id \(id) does not exist.")
|
|
147
147
|
} else {
|
|
148
148
|
call.resolve(self.implementation.getBundleInfo(id: id).toJSON())
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
|
|
152
152
|
@objc func set(_ call: CAPPluginCall) {
|
|
153
153
|
guard let id = call.getString("id") else {
|
|
154
154
|
print("\(self.implementation.TAG) Set called without id")
|
|
@@ -157,7 +157,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
157
157
|
}
|
|
158
158
|
let res = implementation.set(id: id)
|
|
159
159
|
print("\(self.implementation.TAG) Set active bundle: \(id)")
|
|
160
|
-
if
|
|
160
|
+
if !res {
|
|
161
161
|
print("\(self.implementation.TAG) Bundle successfully set to: \(id) ")
|
|
162
162
|
call.reject("Update failed, id \(id) doesn't exist")
|
|
163
163
|
} else {
|
|
@@ -172,7 +172,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
172
172
|
return
|
|
173
173
|
}
|
|
174
174
|
let res = implementation.delete(id: id)
|
|
175
|
-
if
|
|
175
|
+
if res {
|
|
176
176
|
call.resolve()
|
|
177
177
|
} else {
|
|
178
178
|
print("\(self.implementation.TAG) Delete failed, id \(id) doesn't exist")
|
|
@@ -201,7 +201,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
201
201
|
|
|
202
202
|
if let vc = bridge.viewController as? CAPBridgeViewController {
|
|
203
203
|
let fallback: BundleInfo = self.implementation.getFallbackBundle()
|
|
204
|
-
if
|
|
204
|
+
if toLastSuccessful && !fallback.isBuiltin() {
|
|
205
205
|
print("\(self.implementation.TAG) Resetting to: \(fallback.toString())")
|
|
206
206
|
return self.implementation.set(bundle: fallback) && self._reload()
|
|
207
207
|
}
|
|
@@ -219,13 +219,13 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
219
219
|
|
|
220
220
|
@objc func reset(_ call: CAPPluginCall) {
|
|
221
221
|
let toLastSuccessful = call.getBool("toLastSuccessful") ?? false
|
|
222
|
-
if
|
|
222
|
+
if self._reset(toLastSuccessful: toLastSuccessful) {
|
|
223
223
|
return call.resolve()
|
|
224
224
|
}
|
|
225
225
|
print("\(self.implementation.TAG) Reset failed")
|
|
226
226
|
call.reject("\(self.implementation.TAG) Reset failed")
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
|
|
229
229
|
@objc func current(_ call: CAPPluginCall) {
|
|
230
230
|
let bundle: BundleInfo = self.implementation.getCurrentBundle()
|
|
231
231
|
call.resolve([
|
|
@@ -240,7 +240,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
240
240
|
print("\(self.implementation.TAG) Current bundle loaded successfully. ['notifyAppReady()' was called] \(version.toString())")
|
|
241
241
|
call.resolve()
|
|
242
242
|
}
|
|
243
|
-
|
|
243
|
+
|
|
244
244
|
@objc func setDelay(_ call: CAPPluginCall) {
|
|
245
245
|
guard let kind = call.getString("kind") else {
|
|
246
246
|
print("\(self.implementation.TAG) setDelay called without kind")
|
|
@@ -255,7 +255,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
255
255
|
call.resolve()
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
private func _cancelDelay(source: String)
|
|
258
|
+
private func _cancelDelay(source: String) {
|
|
259
259
|
print("\(self.implementation.TAG) delay Canceled from \(source)")
|
|
260
260
|
UserDefaults.standard.removeObject(forKey: DELAY_UPDATE)
|
|
261
261
|
UserDefaults.standard.removeObject(forKey: DELAY_UPDATE_VAL)
|
|
@@ -267,31 +267,31 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
267
267
|
call.resolve()
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
private func _checkCancelDelay(killed: Bool)
|
|
270
|
+
private func _checkCancelDelay(killed: Bool) {
|
|
271
271
|
let delayUpdate = UserDefaults.standard.string(forKey: DELAY_UPDATE)
|
|
272
|
-
if
|
|
273
|
-
if
|
|
272
|
+
if delayUpdate != nil {
|
|
273
|
+
if delayUpdate == "background" && !killed {
|
|
274
274
|
self._cancelDelay(source: "background check")
|
|
275
|
-
} else if
|
|
275
|
+
} else if delayUpdate == "kill" && killed {
|
|
276
276
|
self._cancelDelay(source: "kill check")
|
|
277
277
|
}
|
|
278
278
|
guard let delayVal = UserDefaults.standard.string(forKey: DELAY_UPDATE_VAL) else {
|
|
279
279
|
self._cancelDelay(source: "delayVal absent")
|
|
280
280
|
return
|
|
281
281
|
}
|
|
282
|
-
if
|
|
282
|
+
if delayUpdate == "date" {
|
|
283
283
|
let dateFormatter = ISO8601DateFormatter()
|
|
284
284
|
guard let ExpireDate = dateFormatter.date(from: delayVal) else {
|
|
285
285
|
self._cancelDelay(source: "date parsing issue")
|
|
286
286
|
return
|
|
287
287
|
}
|
|
288
|
-
if
|
|
288
|
+
if ExpireDate < Date() {
|
|
289
289
|
self._cancelDelay(source: "date expired")
|
|
290
290
|
}
|
|
291
|
-
} else if
|
|
291
|
+
} else if delayUpdate == "nativeVersion" {
|
|
292
292
|
do {
|
|
293
293
|
let versionLimit = try Version(delayVal)
|
|
294
|
-
if
|
|
294
|
+
if self.currentVersionNative >= versionLimit {
|
|
295
295
|
self._cancelDelay(source: "nativeVersion above limit")
|
|
296
296
|
}
|
|
297
297
|
} catch {
|
|
@@ -325,14 +325,14 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
325
325
|
func checkRevert() {
|
|
326
326
|
// Automatically roll back to fallback version if notifyAppReady has not been called yet
|
|
327
327
|
let current: BundleInfo = self.implementation.getCurrentBundle()
|
|
328
|
-
if
|
|
328
|
+
if current.isBuiltin() {
|
|
329
329
|
print("\(self.implementation.TAG) Built-in bundle is active. Nothing to do.")
|
|
330
330
|
return
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
print("\(self.implementation.TAG) Current bundle is: \(current.toString())")
|
|
334
334
|
|
|
335
|
-
if
|
|
335
|
+
if BundleStatus.SUCCESS.localizedString != current.getStatus() {
|
|
336
336
|
print("\(self.implementation.TAG) notifyAppReady was not called, roll back current bundle: \(current.toString())")
|
|
337
337
|
print("\(self.implementation.TAG) Did you forget to call 'notifyAppReady()' in your Capacitor App code?")
|
|
338
338
|
self.notifyListeners("updateFailed", data: [
|
|
@@ -341,10 +341,10 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
341
341
|
self.implementation.sendStats(action: "update_fail", versionName: current.getVersionName())
|
|
342
342
|
self.implementation.setError(bundle: current)
|
|
343
343
|
_ = self._reset(toLastSuccessful: true)
|
|
344
|
-
if
|
|
344
|
+
if self.autoDeleteFailed && !current.isBuiltin() {
|
|
345
345
|
print("\(self.implementation.TAG) Deleting failing bundle: \(current.toString())")
|
|
346
346
|
let res = self.implementation.delete(id: current.getId(), removeInfo: false)
|
|
347
|
-
if
|
|
347
|
+
if !res {
|
|
348
348
|
print("\(self.implementation.TAG) Delete version deleted: \(current.toString())")
|
|
349
349
|
} else {
|
|
350
350
|
print("\(self.implementation.TAG) Failed to delete failed bundle: \(current.toString())")
|
|
@@ -361,16 +361,16 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
361
361
|
}
|
|
362
362
|
|
|
363
363
|
@objc func appMovedToForeground() {
|
|
364
|
-
if
|
|
364
|
+
if self._isAutoUpdateEnabled() {
|
|
365
365
|
DispatchQueue.global(qos: .background).async {
|
|
366
366
|
print("\(self.implementation.TAG) Check for update via \(self.updateUrl)")
|
|
367
367
|
let url = URL(string: self.updateUrl)!
|
|
368
368
|
let res = self.implementation.getLatest(url: url)
|
|
369
369
|
let current = self.implementation.getCurrentBundle()
|
|
370
|
-
|
|
371
|
-
if (
|
|
370
|
+
|
|
371
|
+
if (res.message) != nil {
|
|
372
372
|
print("\(self.implementation.TAG) message \(res.message ?? "")")
|
|
373
|
-
if
|
|
373
|
+
if res.major == true {
|
|
374
374
|
self.notifyListeners("majorAvailable", data: ["version": res.version])
|
|
375
375
|
}
|
|
376
376
|
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
@@ -382,18 +382,18 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
382
382
|
return
|
|
383
383
|
}
|
|
384
384
|
let latestVersionName = res.version
|
|
385
|
-
if
|
|
385
|
+
if latestVersionName != "" && current.getVersionName() != latestVersionName {
|
|
386
386
|
let latest = self.implementation.getBundleInfoByVersionName(version: latestVersionName)
|
|
387
|
-
if
|
|
388
|
-
if
|
|
387
|
+
if latest != nil {
|
|
388
|
+
if latest!.isErrorStatus() {
|
|
389
389
|
print("\(self.implementation.TAG) Latest version already exists, and is in error state. Aborting update.")
|
|
390
390
|
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
391
391
|
return
|
|
392
392
|
}
|
|
393
|
-
if
|
|
393
|
+
if latest!.isDownloaded() {
|
|
394
394
|
print("\(self.implementation.TAG) Latest version already exists and download is NOT required. Update will occur next time app moves to background.")
|
|
395
395
|
self.notifyListeners("updateAvailable", data: ["bundle": current.toJSON()])
|
|
396
|
-
|
|
396
|
+
_ = self.implementation.setNextBundle(next: latest!.getId())
|
|
397
397
|
return
|
|
398
398
|
}
|
|
399
399
|
}
|
|
@@ -402,7 +402,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
402
402
|
print("\(self.implementation.TAG) New bundle: \(latestVersionName) found. Current is: \(current.getVersionName()). Update will occur next time app moves to background.")
|
|
403
403
|
let next = try self.implementation.download(url: downloadUrl, version: latestVersionName)
|
|
404
404
|
self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
|
|
405
|
-
|
|
405
|
+
_ = self.implementation.setNextBundle(next: next.getId())
|
|
406
406
|
} catch {
|
|
407
407
|
print("\(self.implementation.TAG) Error downloading file", error.localizedDescription)
|
|
408
408
|
self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
|
|
@@ -422,7 +422,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
422
422
|
print("\(self.implementation.TAG) Check for pending update")
|
|
423
423
|
let delayUpdate = UserDefaults.standard.string(forKey: DELAY_UPDATE)
|
|
424
424
|
self._checkCancelDelay(killed: false)
|
|
425
|
-
if
|
|
425
|
+
if delayUpdate != nil {
|
|
426
426
|
print("\(self.implementation.TAG) Update delayed to next backgrounding")
|
|
427
427
|
return
|
|
428
428
|
}
|
|
@@ -430,11 +430,11 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
430
430
|
let current: BundleInfo = self.implementation.getCurrentBundle()
|
|
431
431
|
let next: BundleInfo? = self.implementation.getNextBundle()
|
|
432
432
|
|
|
433
|
-
if
|
|
433
|
+
if next != nil && !next!.isErrorStatus() && next!.getVersionName() != current.getVersionName() {
|
|
434
434
|
print("\(self.implementation.TAG) Next bundle is: \(next!.toString())")
|
|
435
|
-
if
|
|
435
|
+
if self.implementation.set(bundle: next!) && self._reload() {
|
|
436
436
|
print("\(self.implementation.TAG) Updated to bundle: \(next!.toString())")
|
|
437
|
-
|
|
437
|
+
_ = self.implementation.setNextBundle(next: Optional<String>.none)
|
|
438
438
|
} else {
|
|
439
439
|
print("\(self.implementation.TAG) Update to bundle: \(next!.toString()) Failed!")
|
|
440
440
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-updater",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.4",
|
|
4
4
|
"license": "LGPL-3.0-only",
|
|
5
5
|
"description": "OTA update for capacitor apps",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
41
41
|
"verify:web": "npm run build",
|
|
42
42
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
43
|
-
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- autocorrect --format",
|
|
43
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
|
|
44
44
|
"eslint": "eslint . --ext ts",
|
|
45
45
|
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
46
46
|
"swiftlint": "node-swiftlint",
|