@capgo/capacitor-updater 4.0.0-alpha.52 → 4.0.0-alpha.55

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.
@@ -47,7 +47,7 @@ public class CapacitorUpdater {
47
47
  private static final String bundleDirectory = "versions";
48
48
 
49
49
  public static final String TAG = "Capacitor-updater";
50
- public static final String pluginVersion = "4.0.0-alpha.52";
50
+ public static final String pluginVersion = "4.0.0-alpha.55";
51
51
 
52
52
  public SharedPreferences.Editor editor;
53
53
  public SharedPreferences prefs;
@@ -261,7 +261,8 @@ public class CapacitorUpdater {
261
261
 
262
262
  public Boolean delete(final String id, final Boolean removeInfo) throws IOException {
263
263
  final BundleInfo deleted = this.getBundleInfo(id);
264
- if (deleted.isBuiltin()) {
264
+ if (deleted.isBuiltin() || self.getCurrentBundleId() == id) {
265
+ Log.e(TAG, "Cannot delete " + id);
265
266
  return false;
266
267
  }
267
268
  final File bundle = new File(this.documentsDir, bundleDirectory + "/" + id);
@@ -578,10 +578,10 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
578
578
  }
579
579
  if(latest.isDownloaded()){
580
580
  Log.e(CapacitorUpdater.TAG, "Latest bundle already exists and download is NOT required. Update will occur next time app moves to background.");
581
- CapacitorUpdaterPlugin.this.implementation.setNextBundle(latest.getId());
582
581
  final JSObject ret = new JSObject();
583
582
  ret.put("bundle", latest.toJSON());
584
583
  CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
584
+ CapacitorUpdaterPlugin.this.implementation.setNextBundle(latest.getId());
585
585
  return;
586
586
  }
587
587
  }
@@ -678,7 +678,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
678
678
  this.implementation.sendStats("update_fail", current.getVersionName());
679
679
  this.implementation.setError(current);
680
680
  this._reset(true);
681
- if (CapacitorUpdaterPlugin.this.autoDeleteFailed) {
681
+ if (CapacitorUpdaterPlugin.this.autoDeleteFailed && !current.isBuiltin()) {
682
682
  Log.i(CapacitorUpdater.TAG, "Deleting failing bundle: " + current.getVersionName());
683
683
  try {
684
684
  final Boolean res = this.implementation.delete(current.getId(), false);
@@ -146,7 +146,7 @@ extension CustomError: LocalizedError {
146
146
 
147
147
  public let TAG = "✨ Capacitor-updater:";
148
148
  public let CAP_SERVER_PATH = "serverBasePath"
149
- public let pluginVersion = "4.0.0-alpha.52"
149
+ public let pluginVersion = "4.0.0-alpha.55"
150
150
  public var statsUrl = ""
151
151
  public var appId = ""
152
152
  public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
@@ -343,7 +343,8 @@ extension CustomError: LocalizedError {
343
343
 
344
344
  public func delete(id: String, removeInfo: Bool) -> Bool {
345
345
  let deleted: BundleInfo = self.getBundleInfo(id: id)
346
- if (deleted.isBuiltin()) {
346
+ if (deleted.isBuiltin() || self.getCurrentBundleId() == id) {
347
+ print("\(self.TAG) Cannot delete \(id)")
347
348
  return false
348
349
  }
349
350
  let destHot = documentsDir.appendingPathComponent(bundleDirectoryHot).appendingPathComponent(id)
@@ -434,7 +435,7 @@ extension CustomError: LocalizedError {
434
435
  let fallback: BundleInfo = self.getFallbackBundle()
435
436
  print("\(self.TAG) Fallback bundle is: \(fallback.toString())")
436
437
  print("\(self.TAG) Version successfully loaded: \(bundle.toString())")
437
- if(autoDeletePrevious) {
438
+ if(autoDeletePrevious && !fallback.isBuiltin()) {
438
439
  let res = self.delete(id: fallback.getId())
439
440
  if (res) {
440
441
  print("\(self.TAG) Deleted previous bundle: \(fallback.toString())")
@@ -341,7 +341,7 @@ 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 (self.autoDeleteFailed) {
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
347
  if (!res) {
@@ -392,8 +392,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
392
392
  }
393
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
- let _ = self.implementation.setNextBundle(next: latest!.getId())
396
395
  self.notifyListeners("updateAvailable", data: ["bundle": current.toJSON()])
396
+ let _ = self.implementation.setNextBundle(next: latest!.getId())
397
397
  return
398
398
  }
399
399
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.0.0-alpha.52",
3
+ "version": "4.0.0-alpha.55",
4
4
  "license": "LGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",