@capgo/capacitor-updater 5.2.10 → 5.2.12
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.
|
@@ -41,6 +41,8 @@ import java.util.Date;
|
|
|
41
41
|
import java.util.Iterator;
|
|
42
42
|
import java.util.List;
|
|
43
43
|
import java.util.UUID;
|
|
44
|
+
import java.util.concurrent.CountDownLatch;
|
|
45
|
+
import java.util.concurrent.TimeUnit;
|
|
44
46
|
import org.json.JSONException;
|
|
45
47
|
|
|
46
48
|
@CapacitorPlugin(name = "CapacitorUpdater")
|
|
@@ -56,7 +58,7 @@ public class CapacitorUpdaterPlugin
|
|
|
56
58
|
private static final String channelUrlDefault =
|
|
57
59
|
"https://api.capgo.app/channel_self";
|
|
58
60
|
|
|
59
|
-
private final String PLUGIN_VERSION = "5.2.
|
|
61
|
+
private final String PLUGIN_VERSION = "5.2.12";
|
|
60
62
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
61
63
|
|
|
62
64
|
private SharedPreferences.Editor editor;
|
|
@@ -78,6 +80,8 @@ public class CapacitorUpdaterPlugin
|
|
|
78
80
|
|
|
79
81
|
private volatile Thread appReadyCheck;
|
|
80
82
|
|
|
83
|
+
private static final CountDownLatch semaphoreReady = new CountDownLatch(1);
|
|
84
|
+
|
|
81
85
|
@Override
|
|
82
86
|
public void load() {
|
|
83
87
|
super.load();
|
|
@@ -181,6 +185,18 @@ public class CapacitorUpdaterPlugin
|
|
|
181
185
|
CapacitorUpdaterPlugin.this.implementation.set(latest);
|
|
182
186
|
CapacitorUpdaterPlugin.this._reload();
|
|
183
187
|
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
|
|
188
|
+
new Thread(() -> {
|
|
189
|
+
try {
|
|
190
|
+
CapacitorUpdaterPlugin.this.semaphoreReady.await(
|
|
191
|
+
CapacitorUpdaterPlugin.this.appReadyTimeout,
|
|
192
|
+
TimeUnit.SECONDS
|
|
193
|
+
);
|
|
194
|
+
} catch (InterruptedException e) {
|
|
195
|
+
e.printStackTrace();
|
|
196
|
+
}
|
|
197
|
+
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
|
|
198
|
+
})
|
|
199
|
+
.start();
|
|
184
200
|
}
|
|
185
201
|
|
|
186
202
|
private void cleanupObsoleteVersions() {
|
|
@@ -440,6 +456,7 @@ public class CapacitorUpdaterPlugin
|
|
|
440
456
|
|
|
441
457
|
private boolean _reload() {
|
|
442
458
|
final String path = this.implementation.getCurrentBundlePath();
|
|
459
|
+
this.semaphoreReady.countDown();
|
|
443
460
|
Log.i(CapacitorUpdater.TAG, "Reloading: " + path);
|
|
444
461
|
if (this.implementation.isUsingBuiltin()) {
|
|
445
462
|
this.bridge.setServerAssetPath(path);
|
|
@@ -657,6 +674,7 @@ public class CapacitorUpdaterPlugin
|
|
|
657
674
|
"Current bundle loaded successfully. ['notifyAppReady()' was called] " +
|
|
658
675
|
bundle
|
|
659
676
|
);
|
|
677
|
+
this.semaphoreReady.countDown();
|
|
660
678
|
call.resolve();
|
|
661
679
|
} catch (final Exception e) {
|
|
662
680
|
Log.e(
|
|
@@ -1237,20 +1255,21 @@ public class CapacitorUpdaterPlugin
|
|
|
1237
1255
|
this.backgroundDownload();
|
|
1238
1256
|
} else {
|
|
1239
1257
|
Log.i(CapacitorUpdater.TAG, "Auto update is disabled");
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1258
|
+
new Thread(() -> {
|
|
1259
|
+
try {
|
|
1260
|
+
CapacitorUpdaterPlugin.this.semaphoreReady.await(
|
|
1261
|
+
CapacitorUpdaterPlugin.this.appReadyTimeout,
|
|
1262
|
+
TimeUnit.SECONDS
|
|
1263
|
+
);
|
|
1264
|
+
} catch (InterruptedException e) {
|
|
1265
|
+
e.printStackTrace();
|
|
1266
|
+
}
|
|
1267
|
+
final JSObject ret = new JSObject();
|
|
1268
|
+
ret.put("bundle", current.toJSON());
|
|
1269
|
+
ret.put("status", "disabled");
|
|
1270
|
+
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
|
|
1271
|
+
})
|
|
1272
|
+
.start();
|
|
1254
1273
|
}
|
|
1255
1274
|
this.checkAppReady();
|
|
1256
1275
|
}
|
|
@@ -15,7 +15,7 @@ import Version
|
|
|
15
15
|
@objc(CapacitorUpdaterPlugin)
|
|
16
16
|
public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
17
17
|
private var implementation = CapacitorUpdater()
|
|
18
|
-
private let PLUGIN_VERSION: String = "5.2.
|
|
18
|
+
private let PLUGIN_VERSION: String = "5.2.12"
|
|
19
19
|
static let updateUrlDefault = "https://api.capgo.app/updates"
|
|
20
20
|
static let statsUrlDefault = "https://api.capgo.app/stats"
|
|
21
21
|
static let channelUrlDefault = "https://api.capgo.app/channel_self"
|
|
@@ -34,8 +34,10 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
34
34
|
private var autoDeletePrevious = false
|
|
35
35
|
private var backgroundWork: DispatchWorkItem?
|
|
36
36
|
private var taskRunning = false
|
|
37
|
+
let semaphoreReady = DispatchSemaphore(value: 0)
|
|
37
38
|
|
|
38
39
|
override public func load() {
|
|
40
|
+
_ = semaphoreReady.wait(timeout: .now())
|
|
39
41
|
print("\(self.implementation.TAG) init for device \(self.implementation.deviceID)")
|
|
40
42
|
do {
|
|
41
43
|
currentVersionNative = try Version(getConfig().getString("version", Bundle.main.versionName ?? "0.0.0")!)
|
|
@@ -158,6 +160,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
158
160
|
|
|
159
161
|
private func _reload() -> Bool {
|
|
160
162
|
guard let bridge = self.bridge else { return false }
|
|
163
|
+
_ = self.semaphoreReady.wait(timeout: .now())
|
|
161
164
|
let id = self.implementation.getCurrentBundleId()
|
|
162
165
|
let destHot = self.implementation.getPathHot(id: id)
|
|
163
166
|
print("\(self.implementation.TAG) Reloading \(id)")
|
|
@@ -326,6 +329,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
326
329
|
}
|
|
327
330
|
|
|
328
331
|
@objc func notifyAppReady(_ call: CAPPluginCall) {
|
|
332
|
+
self.semaphoreReady.signal()
|
|
329
333
|
let version = self.implementation.getCurrentBundle()
|
|
330
334
|
self.implementation.setSuccess(bundle: version, autoDeletePrevious: self.autoDeletePrevious)
|
|
331
335
|
print("\(self.implementation.TAG) Current bundle loaded successfully. ['notifyAppReady()' was called] \(version.toString())")
|
|
@@ -504,7 +508,11 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
504
508
|
self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
|
|
505
509
|
}
|
|
506
510
|
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
507
|
-
|
|
511
|
+
|
|
512
|
+
DispatchQueue.global().async {
|
|
513
|
+
_ = self.semaphoreReady.wait(timeout: .now() + .milliseconds(self.appReadyTimeout))
|
|
514
|
+
self.notifyListeners("appReady", data: ["bundle": current.toJSON(), "message": msg])
|
|
515
|
+
}
|
|
508
516
|
print("\(self.implementation.TAG) endBackGroundTaskWithNotif \(msg)")
|
|
509
517
|
self.endBackGroundTask()
|
|
510
518
|
}
|
|
@@ -576,6 +584,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
576
584
|
if self.directUpdate {
|
|
577
585
|
_ = self.implementation.set(bundle: next)
|
|
578
586
|
_ = self._reload()
|
|
587
|
+
self.directUpdate = false
|
|
579
588
|
self.endBackGroundTaskWithNotif(msg: "update installed", latestVersionName: latestVersionName, current: current)
|
|
580
589
|
} else {
|
|
581
590
|
self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
|
|
@@ -654,8 +663,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
654
663
|
self.backgroundDownload()
|
|
655
664
|
} else {
|
|
656
665
|
print("\(self.implementation.TAG) Auto update is disabled")
|
|
657
|
-
|
|
658
|
-
|
|
666
|
+
DispatchQueue.global().async {
|
|
667
|
+
_ = self.semaphoreReady.wait(timeout: .now() + .milliseconds(self.appReadyTimeout))
|
|
659
668
|
self.notifyListeners("appReady", data: ["bundle": current.toJSON(), "status": "disabled"])
|
|
660
669
|
}
|
|
661
670
|
}
|