@capgo/capacitor-updater 4.0.0-alpha.20 → 4.0.0-alpha.23

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.
@@ -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.20";
49
+ public static final String pluginVersion = "4.0.0-alpha.23";
50
50
 
51
51
  public SharedPreferences.Editor editor;
52
52
  public SharedPreferences prefs;
@@ -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.setFallbackVersion(bundle);
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.setFallbackVersion(null);
310
- this.setNext(null);
311
+ this.setFallbackBundle(null);
312
+ this.setNextBundle(null);
311
313
  if(!internal) {
312
314
  this.sendStats("reset", this.getCurrentBundle().getVersionName());
313
315
  }
@@ -489,33 +491,31 @@ public class CapacitorUpdater {
489
491
  return this.getCurrentBundlePath().equals("public");
490
492
  }
491
493
 
492
- public BundleInfo getFallbackVersion() {
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 setFallbackVersion(final BundleInfo fallback) {
499
+ private void setFallbackBundle(final BundleInfo fallback) {
498
500
  this.editor.putString(FALLBACK_VERSION,
499
501
  fallback == null
500
502
  ? BundleInfo.ID_BUILTIN
501
503
  : fallback.getId()
502
504
  );
505
+ this.editor.commit();
503
506
  }
504
507
 
505
- public BundleInfo getNextVersion() {
506
- final String id = this.prefs.getString(NEXT_VERSION, "");
507
- if(id != "") {
508
- return this.getBundleInfo(id);
509
- } else {
510
- return null;
511
- }
508
+ public BundleInfo getNextBundle() {
509
+ final String id = this.prefs.getString(NEXT_VERSION, BundleInfo.ID_BUILTIN);
510
+ return this.getBundleInfo(id);
512
511
  }
513
512
 
514
- public boolean setNext(final String next) {
513
+ public boolean setNextBundle(final String next) {
515
514
  if (next == null) {
516
515
  this.editor.remove(NEXT_VERSION);
517
516
  } else {
518
- if (!this.bundleExists(next)) {
517
+ final BundleInfo newBundle = this.getBundleInfo(next);
518
+ if (!newBundle.isBuiltin() && !this.bundleExists(next)) {
519
519
  return false;
520
520
  }
521
521
  this.editor.putString(NEXT_VERSION, next);
@@ -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.getContext().getSharedPreferences(WebView.WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
88
- this.implementation.editor = this.prefs.edit();
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.setNext(id)) {
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.getFallbackVersion();
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 delayUpdate(final PluginCall call) {
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");
@@ -531,7 +531,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
531
531
  }
532
532
  if(latest.isDownloaded()){
533
533
  Log.e(CapacitorUpdater.TAG, "Latest bundle already exists and download is NOT required. Update will occur next time app moves to background.");
534
- CapacitorUpdaterPlugin.this.implementation.setNext(latest.getId());
534
+ CapacitorUpdaterPlugin.this.implementation.setNextBundle(latest.getId());
535
535
  return;
536
536
  }
537
537
  }
@@ -546,7 +546,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
546
546
  final String url = (String) res.get("url");
547
547
  final BundleInfo next = CapacitorUpdaterPlugin.this.implementation.download(url, latestVersionName);
548
548
 
549
- CapacitorUpdaterPlugin.this.implementation.setNext(next.getId());
549
+ CapacitorUpdaterPlugin.this.implementation.setNextBundle(next.getId());
550
550
  } catch (final Exception e) {
551
551
  Log.e(CapacitorUpdater.TAG, "error downloading file", e);
552
552
  }
@@ -576,9 +576,9 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
576
576
  Log.i(CapacitorUpdater.TAG, "Update delayed to next backgrounding");
577
577
  return;
578
578
  }
579
- final BundleInfo fallback = this.implementation.getFallbackVersion();
579
+ final BundleInfo fallback = this.implementation.getFallbackBundle();
580
580
  final BundleInfo current = this.implementation.getCurrentBundle();
581
- final BundleInfo next = this.implementation.getNextVersion();
581
+ final BundleInfo next = this.implementation.getNextBundle();
582
582
 
583
583
  final Boolean success = current.getStatus() == BundleStatus.SUCCESS;
584
584
 
@@ -590,7 +590,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
590
590
  Log.d(CapacitorUpdater.TAG, "Next bundle is: " + next.getVersionName());
591
591
  if (this.implementation.set(next) && this._reload()) {
592
592
  Log.i(CapacitorUpdater.TAG, "Updated to bundle: " + next.getVersionName());
593
- this.implementation.setNext(null);
593
+ this.implementation.setNextBundle(null);
594
594
  } else {
595
595
  Log.e(CapacitorUpdater.TAG, "Update to bundle: " + next.getVersionName() + " Failed!");
596
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.20"
151
+ public let pluginVersion = "4.0.0-alpha.23"
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.setFallbackVersion(fallback: Optional<BundleInfo>.none)
404
- let _ = self.setNext(next: Optional<String>.none)
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.setFallbackVersion(fallback: bundle)
412
+ self.setFallbackBundle(fallback: bundle)
413
413
  }
414
414
 
415
415
  public func rollback(bundle: BundleInfo) {
@@ -515,43 +515,35 @@ extension CustomError: LocalizedError {
515
515
  return (UserDefaults.standard.string(forKey: self.CAP_SERVER_PATH) ?? "") == self.DEFAULT_FOLDER
516
516
  }
517
517
 
518
- public func getFallbackVersion() -> BundleInfo {
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 setFallbackVersion(fallback: BundleInfo?) {
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 getNextVersion() -> BundleInfo? {
529
- let id: String = UserDefaults.standard.string(forKey: self.NEXT_VERSION) ?? ""
530
- if(id != "") {
531
- return self.getBundleInfo(id: id)
532
- } else {
533
- return nil
534
- }
528
+ public func getNextBundle() -> BundleInfo? {
529
+ let id: String = UserDefaults.standard.string(forKey: self.NEXT_VERSION) ?? BundleInfo.ID_BUILTIN
530
+ return self.getBundleInfo(id: id)
535
531
  }
536
532
 
537
- public func setNext(next: String?) -> Bool {
533
+ public func setNextBundle(next: String?) -> Bool {
538
534
  guard let nextId = next else {
539
535
  UserDefaults.standard.removeObject(forKey: self.NEXT_VERSION)
540
536
  UserDefaults.standard.synchronize()
541
537
  return false
542
538
  }
543
539
  let newBundle: BundleInfo = self.getBundleInfo(id: nextId)
544
- if(newBundle.isBuiltin()) {
545
- self.reset()
546
- return true
547
- }
548
540
  let bundle: URL = self.getBundleDirectory(id: nextId)
549
- if (!bundle.exist) {
541
+ if (!newBundle.isBuiltin() && !bundle.exist) {
550
542
  return false
551
543
  }
552
- UserDefaults.standard.set(next, forKey: self.NEXT_VERSION)
544
+ UserDefaults.standard.set(nextId, forKey: self.NEXT_VERSION)
553
545
  UserDefaults.standard.synchronize()
554
- self.setBundleStatus(id: next!, status: BundleStatus.PENDING)
546
+ self.setBundleStatus(id: nextId, status: BundleStatus.PENDING)
555
547
  return true
556
548
  }
557
549
  }
@@ -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.setNext(next: id)) {
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.getFallbackVersion()
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()
@@ -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.setNext(next: latest!.getId())
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.setNext(next: next.getId())
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.getFallbackVersion()
404
+ let fallback: BundleInfo = self.implementation.getFallbackBundle()
405
405
  let current: BundleInfo = self.implementation.getCurrentBundle()
406
- let next: BundleInfo? = self.implementation.getNextVersion()
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.setNext(next: Optional<String>.none)
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.0.0-alpha.20",
3
+ "version": "4.0.0-alpha.23",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",