@capgo/capacitor-updater 7.6.0 → 7.7.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.
@@ -60,7 +60,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
60
60
  private static final String statsUrlDefault = "https://plugin.capgo.app/stats";
61
61
  private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
62
62
 
63
- private final String PLUGIN_VERSION = "7.6.0";
63
+ private final String PLUGIN_VERSION = "7.7.0";
64
64
  private static final String DELAY_CONDITION_PREFERENCES = "";
65
65
 
66
66
  private SharedPreferences.Editor editor;
@@ -282,37 +282,41 @@ public class CapacitorUpdaterPlugin extends Plugin {
282
282
  }
283
283
 
284
284
  private void sendReadyToJs(final BundleInfo current, final String msg) {
285
- logger.info("sendReadyToJs");
285
+ sendReadyToJs(current, msg, false);
286
+ }
287
+
288
+ private void sendReadyToJs(final BundleInfo current, final String msg, final boolean isDirectUpdate) {
289
+ logger.info("sendReadyToJs: " + msg);
286
290
  final JSObject ret = new JSObject();
287
291
  ret.put("bundle", mapToJSObject(current.toJSONMap()));
288
292
  ret.put("status", msg);
289
- startNewThread(() -> {
290
- logger.info("semaphoreReady sendReadyToJs");
291
- semaphoreWait(CapacitorUpdaterPlugin.this.appReadyTimeout);
292
- logger.info("semaphoreReady sendReadyToJs done");
293
- CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
294
-
295
- // Auto hide splashscreen if enabled
296
- if (CapacitorUpdaterPlugin.this.autoSplashscreen && CapacitorUpdaterPlugin.this.shouldUseDirectUpdate()) {
297
- CapacitorUpdaterPlugin.this.hideSplashscreen();
298
- }
299
- });
293
+
294
+ // No need to wait for semaphore anymore since _reload() has already waited
295
+ this.notifyListeners("appReady", ret);
296
+
297
+ // Auto hide splashscreen if enabled and this is a direct update
298
+ if (this.autoSplashscreen && isDirectUpdate) {
299
+ this.hideSplashscreen();
300
+ }
300
301
  }
301
302
 
302
303
  private void hideSplashscreen() {
303
304
  try {
304
- // Create a simple PluginCall for the hide method
305
- PluginCall call = new PluginCall(
306
- null, // MessageHandler - can be null for this use case
307
- "hideSplashscreen",
308
- "hide",
309
- "autoHideSplashscreen",
310
- new JSObject()
311
- );
312
-
313
- // Use bridge's callPluginMethod to call SplashScreen.hide()
314
- getBridge().callPluginMethod("SplashScreen", "hide", call);
315
- logger.info("Splashscreen hidden automatically via callPluginMethod");
305
+ // Use JavaScript evaluation to hide the splashscreen - simpler and more reliable
306
+ getBridge()
307
+ .getWebView()
308
+ .post(() -> {
309
+ getBridge()
310
+ .eval(
311
+ "(function() { " +
312
+ " if (window.Capacitor && window.Capacitor.Plugins && window.Capacitor.Plugins.SplashScreen) { " +
313
+ " window.Capacitor.Plugins.SplashScreen.hide(); " +
314
+ " } " +
315
+ "})()",
316
+ null
317
+ );
318
+ });
319
+ logger.info("Splashscreen hidden automatically via JavaScript");
316
320
  } catch (Exception e) {
317
321
  logger.error("Error hiding splashscreen: " + e.getMessage());
318
322
  }
@@ -354,7 +358,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
354
358
  private void directUpdateFinish(final BundleInfo latest) {
355
359
  CapacitorUpdaterPlugin.this.implementation.set(latest);
356
360
  CapacitorUpdaterPlugin.this._reload();
357
- sendReadyToJs(latest, "update installed");
361
+ sendReadyToJs(latest, "update installed", true);
358
362
  }
359
363
 
360
364
  private void cleanupObsoleteVersions() {
@@ -766,6 +770,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
766
770
 
767
771
  this.checkAppReady();
768
772
  this.notifyListeners("appReloaded", new JSObject());
773
+
774
+ // Wait for the reload to complete (until notifyAppReady is called)
775
+ this.semaphoreWait(this.appReadyTimeout);
776
+
769
777
  return true;
770
778
  }
771
779
 
@@ -1104,6 +1112,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
1104
1112
  }
1105
1113
 
1106
1114
  private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
1115
+ endBackGroundTaskWithNotif(msg, latestVersionName, current, error, false);
1116
+ }
1117
+
1118
+ private void endBackGroundTaskWithNotif(
1119
+ String msg,
1120
+ String latestVersionName,
1121
+ BundleInfo current,
1122
+ Boolean error,
1123
+ Boolean isDirectUpdate
1124
+ ) {
1107
1125
  if (error) {
1108
1126
  logger.info(
1109
1127
  "endBackGroundTaskWithNotif error: " +
@@ -1121,7 +1139,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
1121
1139
  final JSObject ret = new JSObject();
1122
1140
  ret.put("bundle", mapToJSObject(current.toJSONMap()));
1123
1141
  this.notifyListeners("noNeedUpdate", ret);
1124
- this.sendReadyToJs(current, msg);
1142
+ this.sendReadyToJs(current, msg, isDirectUpdate);
1125
1143
  this.backgroundDownloadTask = null;
1126
1144
  logger.info("endBackGroundTaskWithNotif " + msg);
1127
1145
  }
@@ -1146,7 +1164,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
1146
1164
  jsRes.getString("message"),
1147
1165
  current.getVersionName(),
1148
1166
  current,
1149
- true
1167
+ true,
1168
+ shouldDirectUpdate
1150
1169
  );
1151
1170
  return;
1152
1171
  }
@@ -1162,7 +1181,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
1162
1181
  "Updated to builtin version",
1163
1182
  latestVersionName,
1164
1183
  CapacitorUpdaterPlugin.this.implementation.getCurrentBundle(),
1165
- false
1184
+ false,
1185
+ true
1166
1186
  );
1167
1187
  } else {
1168
1188
  logger.info("Setting next bundle to builtin");
@@ -1183,7 +1203,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
1183
1203
  "Error no url or wrong format",
1184
1204
  current.getVersionName(),
1185
1205
  current,
1186
- true
1206
+ true,
1207
+ shouldDirectUpdate
1187
1208
  );
1188
1209
  return;
1189
1210
  }
@@ -1201,7 +1222,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
1201
1222
  "Latest bundle already exists, and is in error state. Aborting update.",
1202
1223
  latestVersionName,
1203
1224
  current,
1204
- true
1225
+ true,
1226
+ shouldDirectUpdate
1205
1227
  );
1206
1228
  return;
1207
1229
  }
@@ -1218,7 +1240,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
1218
1240
  "Update delayed until delay conditions met",
1219
1241
  latestVersionName,
1220
1242
  latest,
1221
- false
1243
+ false,
1244
+ shouldDirectUpdate
1222
1245
  );
1223
1246
  return;
1224
1247
  }
@@ -1228,7 +1251,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
1228
1251
  "Update installed",
1229
1252
  latestVersionName,
1230
1253
  latest,
1231
- false
1254
+ false,
1255
+ true
1232
1256
  );
1233
1257
  } else {
1234
1258
  CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
@@ -1295,7 +1319,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
1295
1319
  "Error downloading file",
1296
1320
  latestVersionName,
1297
1321
  CapacitorUpdaterPlugin.this.implementation.getCurrentBundle(),
1298
- true
1322
+ true,
1323
+ shouldDirectUpdate
1299
1324
  );
1300
1325
  }
1301
1326
  });
@@ -1309,7 +1334,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
1309
1334
  "Error parsing JSON",
1310
1335
  current.getVersionName(),
1311
1336
  current,
1312
- true
1337
+ true,
1338
+ shouldDirectUpdate
1313
1339
  );
1314
1340
  }
1315
1341
  });
@@ -1455,62 +1481,82 @@ public class CapacitorUpdaterPlugin extends Plugin {
1455
1481
 
1456
1482
  @Override
1457
1483
  public void handleOnStart() {
1458
- if (isPreviousMainActivity) {
1459
- this.appMovedToForeground();
1460
- }
1461
- logger.info("onActivityStarted " + getActivity().getClass().getName());
1462
- isPreviousMainActivity = true;
1484
+ try {
1485
+ if (isPreviousMainActivity) {
1486
+ this.appMovedToForeground();
1487
+ }
1488
+ logger.info("onActivityStarted " + getActivity().getClass().getName());
1489
+ isPreviousMainActivity = true;
1463
1490
 
1464
- // Initialize shake menu if enabled and activity is BridgeActivity
1465
- if (shakeMenuEnabled && getActivity() instanceof com.getcapacitor.BridgeActivity && shakeMenu == null) {
1466
- try {
1467
- shakeMenu = new ShakeMenu(this, (com.getcapacitor.BridgeActivity) getActivity(), logger);
1468
- logger.info("Shake menu initialized");
1469
- } catch (Exception e) {
1470
- logger.error("Failed to initialize shake menu: " + e.getMessage());
1491
+ // Initialize shake menu if enabled and activity is BridgeActivity
1492
+ if (shakeMenuEnabled && getActivity() instanceof com.getcapacitor.BridgeActivity && shakeMenu == null) {
1493
+ try {
1494
+ shakeMenu = new ShakeMenu(this, (com.getcapacitor.BridgeActivity) getActivity(), logger);
1495
+ logger.info("Shake menu initialized");
1496
+ } catch (Exception e) {
1497
+ logger.error("Failed to initialize shake menu: " + e.getMessage());
1498
+ }
1471
1499
  }
1500
+ } catch (Exception e) {
1501
+ logger.error("Failed to run handleOnStart: " + e.getMessage());
1472
1502
  }
1473
1503
  }
1474
1504
 
1475
1505
  @Override
1476
1506
  public void handleOnStop() {
1477
- isPreviousMainActivity = isMainActivity();
1478
- if (isPreviousMainActivity) {
1479
- this.appMovedToBackground();
1507
+ try {
1508
+ isPreviousMainActivity = isMainActivity();
1509
+ if (isPreviousMainActivity) {
1510
+ this.appMovedToBackground();
1511
+ }
1512
+ } catch (Exception e) {
1513
+ logger.error("Failed to run handleOnStop: " + e.getMessage());
1480
1514
  }
1481
1515
  }
1482
1516
 
1483
1517
  @Override
1484
1518
  public void handleOnResume() {
1485
- if (backgroundTask != null && taskRunning) {
1486
- backgroundTask.interrupt();
1519
+ try {
1520
+ if (backgroundTask != null && taskRunning) {
1521
+ backgroundTask.interrupt();
1522
+ }
1523
+ this.implementation.activity = getActivity();
1524
+ } catch (Exception e) {
1525
+ logger.error("Failed to run handleOnResume: " + e.getMessage());
1487
1526
  }
1488
- this.implementation.activity = getActivity();
1489
1527
  }
1490
1528
 
1491
1529
  @Override
1492
1530
  public void handleOnPause() {
1493
- this.implementation.activity = getActivity();
1531
+ try {
1532
+ this.implementation.activity = getActivity();
1533
+ } catch (Exception e) {
1534
+ logger.error("Failed to run handleOnPause: " + e.getMessage());
1535
+ }
1494
1536
  }
1495
1537
 
1496
1538
  @Override
1497
1539
  public void handleOnDestroy() {
1498
- logger.info("onActivityDestroyed " + getActivity().getClass().getName());
1499
- this.implementation.activity = getActivity();
1500
- counterActivityCreate--;
1501
- if (counterActivityCreate == 0) {
1502
- this.appKilled();
1503
- }
1540
+ try {
1541
+ logger.info("onActivityDestroyed " + getActivity().getClass().getName());
1542
+ this.implementation.activity = getActivity();
1543
+ counterActivityCreate--;
1544
+ if (counterActivityCreate == 0) {
1545
+ this.appKilled();
1546
+ }
1504
1547
 
1505
- // Clean up shake menu
1506
- if (shakeMenu != null) {
1507
- try {
1508
- shakeMenu.stop();
1509
- shakeMenu = null;
1510
- logger.info("Shake menu cleaned up");
1511
- } catch (Exception e) {
1512
- logger.error("Failed to clean up shake menu: " + e.getMessage());
1548
+ // Clean up shake menu
1549
+ if (shakeMenu != null) {
1550
+ try {
1551
+ shakeMenu.stop();
1552
+ shakeMenu = null;
1553
+ logger.info("Shake menu cleaned up");
1554
+ } catch (Exception e) {
1555
+ logger.error("Failed to clean up shake menu: " + e.getMessage());
1556
+ }
1513
1557
  }
1558
+ } catch (Exception e) {
1559
+ logger.error("Failed to run handleOnDestroy: " + e.getMessage());
1514
1560
  }
1515
1561
  }
1516
1562
 
@@ -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.6.0"
53
+ private let PLUGIN_VERSION: String = "7.7.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.6.0",
3
+ "version": "7.7.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",