@capgo/capacitor-updater 7.11.13 → 7.13.0

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.
@@ -58,7 +58,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
58
58
  private static final String statsUrlDefault = "https://plugin.capgo.app/stats";
59
59
  private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
60
60
 
61
- private final String PLUGIN_VERSION = "7.11.13";
61
+ private final String PLUGIN_VERSION = "7.13.0";
62
62
  private static final String DELAY_CONDITION_PREFERENCES = "";
63
63
 
64
64
  private SharedPreferences.Editor editor;
@@ -73,6 +73,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
73
73
  private Boolean autoUpdate = false;
74
74
  private String updateUrl = "";
75
75
  private Version currentVersionNative;
76
+ private String currentBuildVersion;
76
77
  private Thread backgroundTask;
77
78
  private Boolean taskRunning = false;
78
79
  private Boolean keepUrlPathAfterReload = false;
@@ -169,6 +170,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
169
170
  }
170
171
  }
171
172
  this.currentVersionNative = new Version(this.getConfig().getString("version", pInfo.versionName));
173
+ this.currentBuildVersion = Integer.toString(pInfo.versionCode);
172
174
  this.delayUpdateUtils = new DelayUpdateUtils(
173
175
  this.prefs,
174
176
  this.editor,
@@ -389,8 +391,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
389
391
  }
390
392
 
391
393
  private boolean checkIfRecentlyInstalledOrUpdated() {
392
- String currentVersion = this.currentVersionNative.getOriginalString();
393
- String lastKnownVersion = this.prefs.getString("LatestVersionNative", "");
394
+ String currentVersion = this.currentBuildVersion;
395
+ String lastKnownVersion = this.prefs.getString("LatestNativeBuildVersion", "");
394
396
 
395
397
  if (lastKnownVersion.isEmpty()) {
396
398
  // First time running, consider it as recently installed
@@ -428,32 +430,21 @@ public class CapacitorUpdaterPlugin extends Plugin {
428
430
  }
429
431
 
430
432
  private void cleanupObsoleteVersions() {
431
- try {
432
- final Version previous = new Version(this.prefs.getString("LatestVersionNative", ""));
433
- try {
434
- if (
435
- !"".equals(previous.getOriginalString()) &&
436
- !Objects.equals(this.currentVersionNative.getOriginalString(), previous.getOriginalString())
437
- ) {
438
- logger.info("New native version detected: " + this.currentVersionNative);
439
- this.implementation.reset(true);
440
- final List<BundleInfo> installed = this.implementation.list(false);
441
- for (final BundleInfo bundle : installed) {
442
- try {
443
- logger.info("Deleting obsolete bundle: " + bundle.getId());
444
- this.implementation.delete(bundle.getId());
445
- } catch (final Exception e) {
446
- logger.error("Failed to delete: " + bundle.getId() + " " + e.getMessage());
447
- }
448
- }
433
+ final String previous = this.prefs.getString("LatestNativeBuildVersion", "");
434
+ if (!"".equals(previous) && !Objects.equals(this.currentBuildVersion, previous)) {
435
+ logger.info("New native build version detected: " + this.currentBuildVersion);
436
+ this.implementation.reset(true);
437
+ final List<BundleInfo> installed = this.implementation.list(false);
438
+ for (final BundleInfo bundle : installed) {
439
+ try {
440
+ logger.info("Deleting obsolete bundle: " + bundle.getId());
441
+ this.implementation.delete(bundle.getId());
442
+ } catch (final Exception e) {
443
+ logger.error("Failed to delete: " + bundle.getId() + " " + e.getMessage());
449
444
  }
450
- } catch (final Exception e) {
451
- logger.error("Could not determine the current version " + e.getMessage());
452
445
  }
453
- } catch (final Exception e) {
454
- logger.error("Error calculating previous native version " + e.getMessage());
455
446
  }
456
- this.editor.putString("LatestVersionNative", this.currentVersionNative.toString());
447
+ this.editor.putString("LatestNativeBuildVersion", this.currentBuildVersion);
457
448
  this.editor.apply();
458
449
  }
459
450
 
@@ -32,6 +32,8 @@ import java.util.Iterator;
32
32
  import java.util.List;
33
33
  import java.util.Map;
34
34
  import java.util.Objects;
35
+ import java.util.concurrent.CompletableFuture;
36
+ import java.util.concurrent.ConcurrentHashMap;
35
37
  import java.util.concurrent.TimeUnit;
36
38
  import java.util.zip.ZipEntry;
37
39
  import java.util.zip.ZipInputStream;
@@ -78,6 +80,8 @@ public class CapgoUpdater {
78
80
  public String deviceID = "";
79
81
  public int timeout = 20000;
80
82
 
83
+ private final Map<String, CompletableFuture<BundleInfo>> downloadFutures = new ConcurrentHashMap<>();
84
+
81
85
  public CapgoUpdater(Logger logger) {
82
86
  this.logger = logger;
83
87
  // Simple OkHttpClient - actual configuration happens in plugin
@@ -245,12 +249,11 @@ public class CapgoUpdater {
245
249
  boolean isManifest = outputData.getBoolean(DownloadService.IS_MANIFEST, false);
246
250
 
247
251
  boolean success = finishDownload(id, dest, version, sessionKey, checksum, true, isManifest);
252
+ BundleInfo resultBundle;
248
253
  if (!success) {
249
254
  logger.error("Finish download failed: " + version);
250
- saveBundleInfo(
251
- id,
252
- new BundleInfo(id, version, BundleStatus.ERROR, new Date(System.currentTimeMillis()), "")
253
- );
255
+ resultBundle = new BundleInfo(id, version, BundleStatus.ERROR, new Date(System.currentTimeMillis()), "");
256
+ saveBundleInfo(id, resultBundle);
254
257
  // Cleanup download tracking
255
258
  DownloadWorkerManager.cancelBundleDownload(activity, id, version);
256
259
  Map<String, Object> ret = new HashMap<>();
@@ -261,6 +264,13 @@ public class CapgoUpdater {
261
264
  } else {
262
265
  // Successful download - cleanup tracking
263
266
  DownloadWorkerManager.cancelBundleDownload(activity, id, version);
267
+ resultBundle = getBundleInfo(id);
268
+ }
269
+
270
+ // Complete the future if it exists
271
+ CompletableFuture<BundleInfo> future = downloadFutures.remove(id);
272
+ if (future != null) {
273
+ future.complete(resultBundle);
264
274
  }
265
275
  break;
266
276
  case FAILED:
@@ -268,10 +278,14 @@ public class CapgoUpdater {
268
278
  String error = failedData.getString(DownloadService.ERROR);
269
279
  logger.error("Download failed: " + error + " " + workInfo.getState());
270
280
  String failedVersion = failedData.getString(DownloadService.VERSION);
271
- saveBundleInfo(
281
+ BundleInfo failedBundle = new BundleInfo(
272
282
  id,
273
- new BundleInfo(id, failedVersion, BundleStatus.ERROR, new Date(System.currentTimeMillis()), "")
283
+ failedVersion,
284
+ BundleStatus.ERROR,
285
+ new Date(System.currentTimeMillis()),
286
+ ""
274
287
  );
288
+ saveBundleInfo(id, failedBundle);
275
289
  // Cleanup download tracking for failed downloads
276
290
  DownloadWorkerManager.cancelBundleDownload(activity, id, failedVersion);
277
291
  Map<String, Object> ret = new HashMap<>();
@@ -282,6 +296,12 @@ public class CapgoUpdater {
282
296
  ret.put("error", error != null ? error : "download_fail");
283
297
  sendStats("download_fail", failedVersion);
284
298
  notifyListeners("downloadFailed", ret);
299
+
300
+ // Complete the future with error status
301
+ CompletableFuture<BundleInfo> failedFuture = downloadFutures.remove(id);
302
+ if (failedFuture != null) {
303
+ failedFuture.complete(failedBundle);
304
+ }
285
305
  break;
286
306
  }
287
307
  });
@@ -485,36 +505,30 @@ public class CapgoUpdater {
485
505
  this.notifyDownload(id, 5);
486
506
  final String dest = this.randomString();
487
507
 
488
- // Use the new WorkManager-based download
508
+ // Create a CompletableFuture to track download completion
509
+ CompletableFuture<BundleInfo> downloadFuture = new CompletableFuture<>();
510
+ downloadFutures.put(id, downloadFuture);
511
+
512
+ // Start the download
489
513
  this.download(id, url, dest, version, sessionKey, checksum, null);
490
514
 
491
- // Wait for completion
515
+ // Wait for completion without timeout
492
516
  try {
493
- ListenableFuture<List<WorkInfo>> future = WorkManager.getInstance(activity).getWorkInfosByTag(id);
494
-
495
- List<WorkInfo> workInfos = Futures.getChecked(future, IOException.class);
496
-
497
- if (workInfos != null && !workInfos.isEmpty()) {
498
- WorkInfo workInfo = workInfos.get(0);
499
- while (!workInfo.getState().isFinished()) {
500
- Thread.sleep(100);
501
- workInfos = Futures.getChecked(WorkManager.getInstance(activity).getWorkInfosByTag(id), IOException.class);
502
- if (workInfos != null && !workInfos.isEmpty()) {
503
- workInfo = workInfos.get(0);
504
- }
505
- }
506
-
507
- if (workInfo.getState() != WorkInfo.State.SUCCEEDED) {
508
- Data outputData = workInfo.getOutputData();
509
- String error = outputData.getString(DownloadService.ERROR);
510
- throw new IOException(error != null ? error : "Download failed: " + workInfo.getState());
511
- }
517
+ BundleInfo result = downloadFuture.get();
518
+ if (result.isErrorStatus()) {
519
+ throw new IOException("Download failed with status: " + result.getStatus());
512
520
  }
513
- return getBundleInfo(id);
521
+ return result;
514
522
  } catch (Exception e) {
515
- logger.error("Error waiting for download " + e.getMessage());
516
- saveBundleInfo(id, new BundleInfo(id, version, BundleStatus.ERROR, new Date(System.currentTimeMillis()), ""));
517
- throw new IOException("Error waiting for download: " + e.getMessage());
523
+ // Clean up on failure
524
+ downloadFutures.remove(id);
525
+ logger.error("Error waiting for download: " + e.getMessage());
526
+ BundleInfo errorBundle = new BundleInfo(id, version, BundleStatus.ERROR, new Date(System.currentTimeMillis()), "");
527
+ saveBundleInfo(id, errorBundle);
528
+ if (e instanceof IOException) {
529
+ throw (IOException) e;
530
+ }
531
+ throw new IOException("Error waiting for download: " + e.getMessage(), e);
518
532
  }
519
533
  }
520
534
 
@@ -50,7 +50,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
50
50
  CAPPluginMethod(name: "isShakeMenuEnabled", returnType: CAPPluginReturnPromise)
51
51
  ]
52
52
  public var implementation = CapgoUpdater()
53
- private let PLUGIN_VERSION: String = "7.11.13"
53
+ private let PLUGIN_VERSION: String = "7.13.0"
54
54
  static let updateUrlDefault = "https://plugin.capgo.app/updates"
55
55
  static let statsUrlDefault = "https://plugin.capgo.app/stats"
56
56
  static let channelUrlDefault = "https://plugin.capgo.app/channel_self"
@@ -59,6 +59,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
59
59
  private var statsUrl = ""
60
60
  private var backgroundTaskID: UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier.invalid
61
61
  private var currentVersionNative: Version = "0.0.0"
62
+ private var currentBuildVersion: String = "0"
62
63
  private var autoUpdate = false
63
64
  private var appReadyTimeout = 10000
64
65
  private var appReadyCheck: DispatchWorkItem?
@@ -107,6 +108,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
107
108
  } catch {
108
109
  logger.error("Cannot parse versionName \(versionName)")
109
110
  }
111
+ currentBuildVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "0"
110
112
  logger.info("version native \(self.currentVersionNative.description)")
111
113
  implementation.versionBuild = getConfig().getString("version", Bundle.main.versionName)!
112
114
  autoDeleteFailed = getConfig().getBoolean("autoDeleteFailed", true)
@@ -235,13 +237,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
235
237
  }
236
238
 
237
239
  private func cleanupObsoleteVersions() {
238
- var LatestVersionNative: Version = "0.0.0"
239
- do {
240
- LatestVersionNative = try Version(UserDefaults.standard.string(forKey: "LatestVersionNative") ?? "0.0.0")
241
- } catch {
242
- logger.error("Cannot get version native \(currentVersionNative)")
243
- }
244
- if LatestVersionNative != "0.0.0" && self.currentVersionNative.description != LatestVersionNative.description {
240
+ let previous = UserDefaults.standard.string(forKey: "LatestNativeBuildVersion") ?? "0"
241
+ if previous != "0" && self.currentBuildVersion != previous {
245
242
  _ = self._reset(toLastSuccessful: false)
246
243
  let res = implementation.list()
247
244
  res.forEach { version in
@@ -252,7 +249,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
252
249
  }
253
250
  }
254
251
  }
255
- UserDefaults.standard.set( self.currentVersionNative.description, forKey: "LatestVersionNative")
252
+ UserDefaults.standard.set(self.currentBuildVersion, forKey: "LatestNativeBuildVersion")
256
253
  UserDefaults.standard.synchronize()
257
254
  }
258
255
 
@@ -846,10 +843,10 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
846
843
 
847
844
  private func checkIfRecentlyInstalledOrUpdated() -> Bool {
848
845
  let userDefaults = UserDefaults.standard
849
- let currentVersion = self.currentVersionNative.description
850
- let lastKnownVersion = userDefaults.string(forKey: "LatestVersionNative") ?? "0.0.0"
846
+ let currentVersion = self.currentBuildVersion
847
+ let lastKnownVersion = userDefaults.string(forKey: "LatestNativeBuildVersion") ?? "0"
851
848
 
852
- if lastKnownVersion == "0.0.0" {
849
+ if lastKnownVersion == "0" {
853
850
  // First time running, consider it as recently installed
854
851
  return true
855
852
  } else if lastKnownVersion != currentVersion {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "7.11.13",
3
+ "version": "7.13.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",