@capgo/capacitor-updater 7.12.0 → 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.12.0";
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;
@@ -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.12.0"
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"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "7.12.0",
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",