@capgo/capacitor-updater 5.2.10 → 5.2.13

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.
@@ -376,6 +376,7 @@ public class CapacitorUpdater {
376
376
  if (setNext) {
377
377
  if (this.directUpdate) {
378
378
  CapacitorUpdater.this.directUpdateFinish(next);
379
+ this.directUpdate = false;
379
380
  } else {
380
381
  this.setNextBundle(next.getId());
381
382
  }
@@ -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.10";
61
+ private final String PLUGIN_VERSION = "5.2.13";
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();
@@ -180,7 +184,20 @@ public class CapacitorUpdaterPlugin
180
184
  ret.put("status", "update installed");
181
185
  CapacitorUpdaterPlugin.this.implementation.set(latest);
182
186
  CapacitorUpdaterPlugin.this._reload();
183
- CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
187
+ new Thread(() -> {
188
+ try {
189
+ // Log.i(CapacitorUpdater.TAG, "semaphoreReady directUpdateFinish");
190
+ CapacitorUpdaterPlugin.this.semaphoreReady.await(
191
+ CapacitorUpdaterPlugin.this.appReadyTimeout,
192
+ TimeUnit.SECONDS
193
+ );
194
+ // Log.i(CapacitorUpdater.TAG, "semaphoreReady directUpdateFinish done");
195
+ } catch (InterruptedException e) {
196
+ e.printStackTrace();
197
+ }
198
+ CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
199
+ })
200
+ .start();
184
201
  }
185
202
 
186
203
  private void cleanupObsoleteVersions() {
@@ -440,6 +457,16 @@ public class CapacitorUpdaterPlugin
440
457
 
441
458
  private boolean _reload() {
442
459
  final String path = this.implementation.getCurrentBundlePath();
460
+ new Thread(() -> {
461
+ try {
462
+ // Log.i(CapacitorUpdater.TAG, "semaphoreReady _reload");
463
+ CapacitorUpdaterPlugin.this.semaphoreReady.await(0, TimeUnit.SECONDS);
464
+ // Log.i(CapacitorUpdater.TAG, "semaphoreReady _reload done");
465
+ } catch (InterruptedException e) {
466
+ e.printStackTrace();
467
+ }
468
+ })
469
+ .start();
443
470
  Log.i(CapacitorUpdater.TAG, "Reloading: " + path);
444
471
  if (this.implementation.isUsingBuiltin()) {
445
472
  this.bridge.setServerAssetPath(path);
@@ -657,6 +684,9 @@ public class CapacitorUpdaterPlugin
657
684
  "Current bundle loaded successfully. ['notifyAppReady()' was called] " +
658
685
  bundle
659
686
  );
687
+ // Log.i(CapacitorUpdater.TAG, "semaphoreReady countDown");
688
+ this.semaphoreReady.countDown();
689
+ // Log.i(CapacitorUpdater.TAG, "semaphoreReady countDown done");
660
690
  call.resolve();
661
691
  } catch (final Exception e) {
662
692
  Log.e(
@@ -867,7 +897,18 @@ public class CapacitorUpdaterPlugin
867
897
  ret.put("bundle", current.toJSON());
868
898
  this.notifyListeners("noNeedUpdate", ret);
869
899
  ret.put("message", msg);
870
- this.notifyListeners("appReady", ret);
900
+ new Thread(() -> {
901
+ try {
902
+ CapacitorUpdaterPlugin.this.semaphoreReady.await(
903
+ CapacitorUpdaterPlugin.this.appReadyTimeout,
904
+ TimeUnit.SECONDS
905
+ );
906
+ } catch (InterruptedException e) {
907
+ e.printStackTrace();
908
+ }
909
+ CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
910
+ })
911
+ .start();
871
912
  Log.i(CapacitorUpdater.TAG, "endBackGroundTaskWithNotif " + msg);
872
913
  }
873
914
 
@@ -1237,20 +1278,23 @@ public class CapacitorUpdaterPlugin
1237
1278
  this.backgroundDownload();
1238
1279
  } else {
1239
1280
  Log.i(CapacitorUpdater.TAG, "Auto update is disabled");
1240
- // run after 1.5 s to make sure the listeners are registered
1241
- new Handler()
1242
- .postDelayed(
1243
- new Runnable() {
1244
- @Override
1245
- public void run() {
1246
- final JSObject ret = new JSObject();
1247
- ret.put("bundle", current.toJSON());
1248
- ret.put("status", "disabled");
1249
- CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
1250
- }
1251
- },
1252
- 1500
1253
- );
1281
+ new Thread(() -> {
1282
+ try {
1283
+ // Log.i(CapacitorUpdater.TAG, "semaphoreReady Auto update");
1284
+ CapacitorUpdaterPlugin.this.semaphoreReady.await(
1285
+ CapacitorUpdaterPlugin.this.appReadyTimeout,
1286
+ TimeUnit.SECONDS
1287
+ );
1288
+ // Log.i(CapacitorUpdater.TAG, "semaphoreReady Auto update done");
1289
+ } catch (InterruptedException e) {
1290
+ e.printStackTrace();
1291
+ }
1292
+ final JSObject ret = new JSObject();
1293
+ ret.put("bundle", current.toJSON());
1294
+ ret.put("status", "disabled");
1295
+ CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
1296
+ })
1297
+ .start();
1254
1298
  }
1255
1299
  this.checkAppReady();
1256
1300
  }
@@ -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.10"
18
+ private let PLUGIN_VERSION: String = "5.2.13"
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
- self.notifyListeners("appReady", data: ["bundle": current.toJSON(), "message": msg])
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
- // run after 1 second to make sure that the app is ready
658
- DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "5.2.10",
3
+ "version": "5.2.13",
4
4
  "packageManager": "pnpm@8.6.12",
5
5
  "license": "MPL-2.0",
6
6
  "description": "Live update for capacitor apps",