@capgo/capacitor-updater 4.0.0-alpha.19 → 4.0.0-alpha.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/CapacitorUpdater.java +18 -11
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +38 -30
- package/ios/Plugin/CapacitorUpdater.swift +8 -8
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +8 -8
- package/package.json +1 -1
|
@@ -46,7 +46,7 @@ public class CapacitorUpdater {
|
|
|
46
46
|
private static final String bundleDirectory = "versions";
|
|
47
47
|
|
|
48
48
|
public static final String TAG = "Capacitor-updater";
|
|
49
|
-
public static final String pluginVersion = "4.0.0-alpha.
|
|
49
|
+
public static final String pluginVersion = "4.0.0-alpha.21";
|
|
50
50
|
|
|
51
51
|
public SharedPreferences.Editor editor;
|
|
52
52
|
public SharedPreferences prefs;
|
|
@@ -98,7 +98,7 @@ public class CapacitorUpdater {
|
|
|
98
98
|
this.notifyDownload(id, 75);
|
|
99
99
|
|
|
100
100
|
ZipEntry entry;
|
|
101
|
-
while ((entry = zis.
|
|
101
|
+
while ((entry = zis.getNextBundleEntry()) != null) {
|
|
102
102
|
final File file = new File(targetDirectory, entry.getName());
|
|
103
103
|
final String canonicalPath = file.getCanonicalPath();
|
|
104
104
|
final String canonicalDir = (new File(String.valueOf(targetDirectory))).getCanonicalPath();
|
|
@@ -276,10 +276,12 @@ public class CapacitorUpdater {
|
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
public Boolean set(final String id) {
|
|
279
|
-
|
|
280
279
|
final BundleInfo newBundle = this.getBundleInfo(id);
|
|
280
|
+
if(newBundle.isBuiltin()) {
|
|
281
|
+
this.reset();
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
281
284
|
final File bundle = this.getBundleDirectory(id);
|
|
282
|
-
|
|
283
285
|
Log.i(TAG, "Setting next active bundle: " + id);
|
|
284
286
|
if (this.bundleExists(id)) {
|
|
285
287
|
this.setCurrentBundle(bundle);
|
|
@@ -293,7 +295,7 @@ public class CapacitorUpdater {
|
|
|
293
295
|
|
|
294
296
|
public void commit(final BundleInfo bundle) {
|
|
295
297
|
this.setBundleStatus(bundle.getId(), BundleStatus.SUCCESS);
|
|
296
|
-
this.
|
|
298
|
+
this.setFallbackBundle(bundle);
|
|
297
299
|
}
|
|
298
300
|
|
|
299
301
|
public void reset() {
|
|
@@ -306,8 +308,8 @@ public class CapacitorUpdater {
|
|
|
306
308
|
|
|
307
309
|
public void reset(final boolean internal) {
|
|
308
310
|
this.setCurrentBundle(new File("public"));
|
|
309
|
-
this.
|
|
310
|
-
this.
|
|
311
|
+
this.setFallbackBundle(null);
|
|
312
|
+
this.setNextBundle(null);
|
|
311
313
|
if(!internal) {
|
|
312
314
|
this.sendStats("reset", this.getCurrentBundle().getVersionName());
|
|
313
315
|
}
|
|
@@ -489,12 +491,12 @@ public class CapacitorUpdater {
|
|
|
489
491
|
return this.getCurrentBundlePath().equals("public");
|
|
490
492
|
}
|
|
491
493
|
|
|
492
|
-
public BundleInfo
|
|
494
|
+
public BundleInfo getFallbackBundle() {
|
|
493
495
|
final String id = this.prefs.getString(FALLBACK_VERSION, BundleInfo.ID_BUILTIN);
|
|
494
496
|
return this.getBundleInfo(id);
|
|
495
497
|
}
|
|
496
498
|
|
|
497
|
-
private void
|
|
499
|
+
private void setFallbackBundle(final BundleInfo fallback) {
|
|
498
500
|
this.editor.putString(FALLBACK_VERSION,
|
|
499
501
|
fallback == null
|
|
500
502
|
? BundleInfo.ID_BUILTIN
|
|
@@ -502,7 +504,7 @@ public class CapacitorUpdater {
|
|
|
502
504
|
);
|
|
503
505
|
}
|
|
504
506
|
|
|
505
|
-
public BundleInfo
|
|
507
|
+
public BundleInfo getNextBundle() {
|
|
506
508
|
final String id = this.prefs.getString(NEXT_VERSION, "");
|
|
507
509
|
if(id != "") {
|
|
508
510
|
return this.getBundleInfo(id);
|
|
@@ -511,10 +513,15 @@ public class CapacitorUpdater {
|
|
|
511
513
|
}
|
|
512
514
|
}
|
|
513
515
|
|
|
514
|
-
public boolean
|
|
516
|
+
public boolean setNextBundle(final String next) {
|
|
515
517
|
if (next == null) {
|
|
516
518
|
this.editor.remove(NEXT_VERSION);
|
|
517
519
|
} else {
|
|
520
|
+
final BundleInfo newBundle = this.getBundleInfo(next);
|
|
521
|
+
if(newBundle.isBuiltin()) {
|
|
522
|
+
this.reset();
|
|
523
|
+
return true;
|
|
524
|
+
}
|
|
518
525
|
if (!this.bundleExists(next)) {
|
|
519
526
|
return false;
|
|
520
527
|
}
|
|
@@ -84,8 +84,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
84
84
|
this.implementation.appId = config.getString("appId", "");
|
|
85
85
|
this.implementation.statsUrl = this.getConfig().getString("statsUrl", statsUrlDefault);
|
|
86
86
|
this.implementation.documentsDir = this.getContext().getFilesDir();
|
|
87
|
-
this.implementation.prefs = this.
|
|
88
|
-
this.implementation.editor = this.
|
|
87
|
+
this.implementation.prefs = this.prefs;
|
|
88
|
+
this.implementation.editor = this.editor;
|
|
89
89
|
this.implementation.versionOs = Build.VERSION.RELEASE;
|
|
90
90
|
this.implementation.deviceID = Settings.Secure.getString(this.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
|
|
91
91
|
|
|
@@ -236,7 +236,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
236
236
|
|
|
237
237
|
try {
|
|
238
238
|
Log.i(CapacitorUpdater.TAG, "Setting next active id " + id);
|
|
239
|
-
if (!this.implementation.
|
|
239
|
+
if (!this.implementation.setNextBundle(id)) {
|
|
240
240
|
Log.e(CapacitorUpdater.TAG, "Set next id failed. Bundle " + id + " does not exist.");
|
|
241
241
|
call.reject("Set next id failed. Bundle " + id + " does not exist.");
|
|
242
242
|
} else {
|
|
@@ -329,7 +329,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
private boolean _reset(final Boolean toLastSuccessful) {
|
|
332
|
-
final BundleInfo fallback = this.implementation.
|
|
332
|
+
final BundleInfo fallback = this.implementation.getFallbackBundle();
|
|
333
333
|
this.implementation.reset();
|
|
334
334
|
|
|
335
335
|
if (toLastSuccessful && !fallback.isBuiltin()) {
|
|
@@ -388,7 +388,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
388
388
|
}
|
|
389
389
|
|
|
390
390
|
@PluginMethod
|
|
391
|
-
public void
|
|
391
|
+
public void setDelay(final PluginCall call) {
|
|
392
392
|
try {
|
|
393
393
|
final String kind = call.getString("kind");
|
|
394
394
|
final String value = call.getString("value");
|
|
@@ -409,54 +409,61 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
-
private boolean _cancelDelay() {
|
|
412
|
+
private boolean _cancelDelay(String source) {
|
|
413
413
|
try {
|
|
414
414
|
this.editor.remove(DELAY_UPDATE);
|
|
415
415
|
this.editor.remove(DELAY_UPDATE_VAL);
|
|
416
416
|
this.editor.commit();
|
|
417
|
-
Log.i(CapacitorUpdater.TAG, "delay
|
|
417
|
+
Log.i(CapacitorUpdater.TAG, "delay canceled from " + source);
|
|
418
|
+
return true;
|
|
418
419
|
}
|
|
419
420
|
catch(final Exception e) {
|
|
420
421
|
Log.e(CapacitorUpdater.TAG, "Failed to cancel update delay", e);
|
|
421
|
-
|
|
422
|
+
return false;
|
|
422
423
|
}
|
|
423
424
|
}
|
|
424
425
|
|
|
425
426
|
@PluginMethod
|
|
426
427
|
public void cancelDelay(final PluginCall call) {
|
|
427
|
-
this._cancelDelay()
|
|
428
|
-
|
|
428
|
+
if(this._cancelDelay("JS")) {
|
|
429
|
+
call.resolve();
|
|
430
|
+
} else {
|
|
431
|
+
call.reject("Failed to cancel delay");
|
|
432
|
+
}
|
|
429
433
|
}
|
|
430
434
|
|
|
431
435
|
private void _checkCancelDelay(Boolean killed) {
|
|
432
436
|
final String delayUpdate = this.prefs.getString(DELAY_UPDATE, "");
|
|
433
437
|
if ("".equals(delayUpdate)) {
|
|
434
438
|
if ("background".equals(delayUpdate) && !killed) {
|
|
435
|
-
this._cancelDelay();
|
|
439
|
+
this._cancelDelay("background check");
|
|
436
440
|
} else if ("kill".equals(delayUpdate) && killed) {
|
|
437
|
-
this._cancelDelay();
|
|
441
|
+
this._cancelDelay("kill check");
|
|
438
442
|
}
|
|
439
443
|
final String delayVal = this.prefs.getString(DELAY_UPDATE_VAL, "");
|
|
440
|
-
if (delayVal
|
|
441
|
-
this._cancelDelay();
|
|
444
|
+
if ("".equals(delayVal)) {
|
|
445
|
+
this._cancelDelay("delayVal absent");
|
|
442
446
|
} else if ("date".equals(delayUpdate)) {
|
|
443
447
|
try {
|
|
444
448
|
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
|
445
449
|
Date date = sdf.parse(delayVal);
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
this._cancelDelay();
|
|
450
|
+
if (date.compareTo(new Date()) > 0) {
|
|
451
|
+
this._cancelDelay("date expired");
|
|
449
452
|
}
|
|
450
453
|
}
|
|
451
454
|
catch(final Exception e) {
|
|
452
|
-
|
|
453
|
-
this._cancelDelay();
|
|
455
|
+
this._cancelDelay("date parsing issue");
|
|
454
456
|
}
|
|
455
457
|
|
|
456
458
|
} else if ("nativeVersion".equals(delayUpdate)) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
this.
|
|
459
|
+
try {
|
|
460
|
+
final Version versionLimit = new Version(delayVal);
|
|
461
|
+
if (this.currentVersionNative.isAtLeast(versionLimit)) {
|
|
462
|
+
this._cancelDelay("nativeVersion above limit");
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
catch(final Exception e) {
|
|
466
|
+
this._cancelDelay("nativeVersion parsing issue");
|
|
460
467
|
}
|
|
461
468
|
}
|
|
462
469
|
}
|
|
@@ -490,6 +497,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
490
497
|
}
|
|
491
498
|
}
|
|
492
499
|
|
|
500
|
+
|
|
501
|
+
|
|
493
502
|
@Override // appMovedToForeground
|
|
494
503
|
public void onActivityStarted(@NonNull final Activity activity) {
|
|
495
504
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled()) {
|
|
@@ -522,7 +531,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
522
531
|
}
|
|
523
532
|
if(latest.isDownloaded()){
|
|
524
533
|
Log.e(CapacitorUpdater.TAG, "Latest bundle already exists and download is NOT required. Update will occur next time app moves to background.");
|
|
525
|
-
CapacitorUpdaterPlugin.this.implementation.
|
|
534
|
+
CapacitorUpdaterPlugin.this.implementation.setNextBundle(latest.getId());
|
|
526
535
|
return;
|
|
527
536
|
}
|
|
528
537
|
}
|
|
@@ -537,7 +546,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
537
546
|
final String url = (String) res.get("url");
|
|
538
547
|
final BundleInfo next = CapacitorUpdaterPlugin.this.implementation.download(url, latestVersionName);
|
|
539
548
|
|
|
540
|
-
CapacitorUpdaterPlugin.this.implementation.
|
|
549
|
+
CapacitorUpdaterPlugin.this.implementation.setNextBundle(next.getId());
|
|
541
550
|
} catch (final Exception e) {
|
|
542
551
|
Log.e(CapacitorUpdater.TAG, "error downloading file", e);
|
|
543
552
|
}
|
|
@@ -561,16 +570,15 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
561
570
|
public void onActivityStopped(@NonNull final Activity activity) {
|
|
562
571
|
Log.i(CapacitorUpdater.TAG, "Checking for pending update");
|
|
563
572
|
try {
|
|
564
|
-
final
|
|
573
|
+
final String delayUpdate = this.prefs.getString(DELAY_UPDATE, "");
|
|
565
574
|
this._checkCancelDelay(false);
|
|
566
|
-
if (delayUpdate) {
|
|
575
|
+
if ("".equals(delayUpdate)) {
|
|
567
576
|
Log.i(CapacitorUpdater.TAG, "Update delayed to next backgrounding");
|
|
568
577
|
return;
|
|
569
578
|
}
|
|
570
|
-
|
|
571
|
-
final BundleInfo fallback = this.implementation.getFallbackVersion();
|
|
579
|
+
final BundleInfo fallback = this.implementation.getFallbackBundle();
|
|
572
580
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
573
|
-
final BundleInfo next = this.implementation.
|
|
581
|
+
final BundleInfo next = this.implementation.getNextBundle();
|
|
574
582
|
|
|
575
583
|
final Boolean success = current.getStatus() == BundleStatus.SUCCESS;
|
|
576
584
|
|
|
@@ -582,7 +590,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
582
590
|
Log.d(CapacitorUpdater.TAG, "Next bundle is: " + next.getVersionName());
|
|
583
591
|
if (this.implementation.set(next) && this._reload()) {
|
|
584
592
|
Log.i(CapacitorUpdater.TAG, "Updated to bundle: " + next.getVersionName());
|
|
585
|
-
this.implementation.
|
|
593
|
+
this.implementation.setNextBundle(null);
|
|
586
594
|
} else {
|
|
587
595
|
Log.e(CapacitorUpdater.TAG, "Update to bundle: " + next.getVersionName() + " Failed!");
|
|
588
596
|
}
|
|
@@ -148,7 +148,7 @@ extension CustomError: LocalizedError {
|
|
|
148
148
|
|
|
149
149
|
public let TAG = "✨ Capacitor-updater:";
|
|
150
150
|
public let CAP_SERVER_PATH = "serverBasePath"
|
|
151
|
-
public let pluginVersion = "4.0.0-alpha.
|
|
151
|
+
public let pluginVersion = "4.0.0-alpha.21"
|
|
152
152
|
public var statsUrl = ""
|
|
153
153
|
public var appId = ""
|
|
154
154
|
public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
|
|
@@ -400,8 +400,8 @@ extension CustomError: LocalizedError {
|
|
|
400
400
|
|
|
401
401
|
public func reset(isInternal: Bool) {
|
|
402
402
|
self.setCurrentBundle(bundle: "")
|
|
403
|
-
self.
|
|
404
|
-
let _ = self.
|
|
403
|
+
self.setFallbackBundle(fallback: Optional<BundleInfo>.none)
|
|
404
|
+
let _ = self.setNextBundle(next: Optional<String>.none)
|
|
405
405
|
if(!isInternal) {
|
|
406
406
|
sendStats(action: "reset", versionName: self.getCurrentBundle().getVersionName())
|
|
407
407
|
}
|
|
@@ -409,7 +409,7 @@ extension CustomError: LocalizedError {
|
|
|
409
409
|
|
|
410
410
|
public func commit(bundle: BundleInfo) {
|
|
411
411
|
self.setBundleStatus(id: bundle.getId(), status: BundleStatus.SUCCESS)
|
|
412
|
-
self.
|
|
412
|
+
self.setFallbackBundle(fallback: bundle)
|
|
413
413
|
}
|
|
414
414
|
|
|
415
415
|
public func rollback(bundle: BundleInfo) {
|
|
@@ -515,17 +515,17 @@ extension CustomError: LocalizedError {
|
|
|
515
515
|
return (UserDefaults.standard.string(forKey: self.CAP_SERVER_PATH) ?? "") == self.DEFAULT_FOLDER
|
|
516
516
|
}
|
|
517
517
|
|
|
518
|
-
public func
|
|
518
|
+
public func getFallbackBundle() -> BundleInfo {
|
|
519
519
|
let id: String = UserDefaults.standard.string(forKey: self.FALLBACK_VERSION) ?? BundleInfo.ID_BUILTIN
|
|
520
520
|
return self.getBundleInfo(id: id)
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
-
private func
|
|
523
|
+
private func setFallbackBundle(fallback: BundleInfo?) {
|
|
524
524
|
UserDefaults.standard.set(fallback == nil ? BundleInfo.ID_BUILTIN : fallback!.getId(), forKey: self.FALLBACK_VERSION)
|
|
525
525
|
UserDefaults.standard.synchronize()
|
|
526
526
|
}
|
|
527
527
|
|
|
528
|
-
public func
|
|
528
|
+
public func getNextBundle() -> BundleInfo? {
|
|
529
529
|
let id: String = UserDefaults.standard.string(forKey: self.NEXT_VERSION) ?? ""
|
|
530
530
|
if(id != "") {
|
|
531
531
|
return self.getBundleInfo(id: id)
|
|
@@ -534,7 +534,7 @@ extension CustomError: LocalizedError {
|
|
|
534
534
|
}
|
|
535
535
|
}
|
|
536
536
|
|
|
537
|
-
public func
|
|
537
|
+
public func setNextBundle(next: String?) -> Bool {
|
|
538
538
|
guard let nextId = next else {
|
|
539
539
|
UserDefaults.standard.removeObject(forKey: self.NEXT_VERSION)
|
|
540
540
|
UserDefaults.standard.synchronize()
|
|
@@ -140,7 +140,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
140
140
|
return
|
|
141
141
|
}
|
|
142
142
|
print("\(self.implementation.TAG) Setting next active id \(id)")
|
|
143
|
-
if (!self.implementation.
|
|
143
|
+
if (!self.implementation.setNextBundle(next: id)) {
|
|
144
144
|
print("\(self.implementation.TAG) Set next version failed. id \(id) does not exist.")
|
|
145
145
|
call.reject("Set next version failed. id \(id) does not exist.")
|
|
146
146
|
} else {
|
|
@@ -199,7 +199,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
199
199
|
guard let bridge = self.bridge else { return false }
|
|
200
200
|
|
|
201
201
|
if let vc = bridge.viewController as? CAPBridgeViewController {
|
|
202
|
-
let fallback: BundleInfo = self.implementation.
|
|
202
|
+
let fallback: BundleInfo = self.implementation.getFallbackBundle()
|
|
203
203
|
if (toLastSuccessful && !fallback.isBuiltin()) {
|
|
204
204
|
print("\(self.implementation.TAG) Resetting to: \(fallback.toString())")
|
|
205
205
|
return self.implementation.set(bundle: fallback) && self._reload()
|
|
@@ -294,7 +294,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
294
294
|
self._cancelDelay(source: "nativeVersion above limit")
|
|
295
295
|
}
|
|
296
296
|
} catch {
|
|
297
|
-
self._cancelDelay(source: "nativeVersion
|
|
297
|
+
self._cancelDelay(source: "nativeVersion parsing issue")
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
}
|
|
@@ -372,7 +372,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
372
372
|
}
|
|
373
373
|
if(latest!.isDownloaded()){
|
|
374
374
|
print("\(self.implementation.TAG) Latest version already exists and download is NOT required. Update will occur next time app moves to background.")
|
|
375
|
-
let _ = self.implementation.
|
|
375
|
+
let _ = self.implementation.setNextBundle(next: latest!.getId())
|
|
376
376
|
return
|
|
377
377
|
}
|
|
378
378
|
}
|
|
@@ -381,7 +381,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
381
381
|
print("\(self.implementation.TAG) New bundle: \(latestVersionName!) found. Current is: \(current.getVersionName()). Update will occur next time app moves to background.")
|
|
382
382
|
let next = try self.implementation.download(url: downloadUrl, version: latestVersionName!)
|
|
383
383
|
|
|
384
|
-
let _ = self.implementation.
|
|
384
|
+
let _ = self.implementation.setNextBundle(next: next.getId())
|
|
385
385
|
} catch {
|
|
386
386
|
print("\(self.implementation.TAG) Error downloading file", error.localizedDescription)
|
|
387
387
|
}
|
|
@@ -401,9 +401,9 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
401
401
|
return
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
let fallback: BundleInfo = self.implementation.
|
|
404
|
+
let fallback: BundleInfo = self.implementation.getFallbackBundle()
|
|
405
405
|
let current: BundleInfo = self.implementation.getCurrentBundle()
|
|
406
|
-
let next: BundleInfo? = self.implementation.
|
|
406
|
+
let next: BundleInfo? = self.implementation.getNextBundle()
|
|
407
407
|
|
|
408
408
|
let success: Bool = current.getStatus() == BundleStatus.SUCCESS.localizedString
|
|
409
409
|
|
|
@@ -414,7 +414,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
414
414
|
print("\(self.implementation.TAG) Next bundle is: \(next!.toString())")
|
|
415
415
|
if (self.implementation.set(bundle: next!) && self._reload()) {
|
|
416
416
|
print("\(self.implementation.TAG) Updated to bundle: \(next!)")
|
|
417
|
-
let _ = self.implementation.
|
|
417
|
+
let _ = self.implementation.setNextBundle(next: Optional<String>.none)
|
|
418
418
|
} else {
|
|
419
419
|
print("\(self.implementation.TAG) Updated to bundle: \(next!) Failed!")
|
|
420
420
|
}
|