@capgo/capacitor-updater 7.12.0 → 7.13.1
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/Package.swift
CHANGED
|
@@ -10,7 +10,7 @@ let package = Package(
|
|
|
10
10
|
targets: ["CapacitorUpdaterPlugin"])
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
|
13
|
-
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.4.
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.4.3"),
|
|
14
14
|
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.10.2")),
|
|
15
15
|
.package(url: "https://github.com/ZipArchive/ZipArchive.git", exact: "2.4.3"),
|
|
16
16
|
.package(url: "https://github.com/mrackwitz/Version.git", exact: "0.8.0"),
|
|
@@ -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.
|
|
61
|
+
private final String PLUGIN_VERSION = "7.13.1";
|
|
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
|
-
|
|
251
|
-
|
|
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
|
-
|
|
281
|
+
BundleInfo failedBundle = new BundleInfo(
|
|
272
282
|
id,
|
|
273
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
494
|
-
|
|
495
|
-
|
|
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
|
|
521
|
+
return result;
|
|
514
522
|
} catch (Exception e) {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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.
|
|
53
|
+
private let PLUGIN_VERSION: String = "7.13.1"
|
|
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"
|