@capgo/capacitor-updater 7.18.12 → 7.18.14
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/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +277 -289
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +5 -5
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +27 -27
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +7 -7
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +1 -1
- package/package.json +1 -1
|
@@ -58,7 +58,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
58
58
|
private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
|
|
59
59
|
private static final String CUSTOM_ID_PREF_KEY = "CapacitorUpdater.customId";
|
|
60
60
|
|
|
61
|
-
private final String PLUGIN_VERSION = "7.18.
|
|
61
|
+
private final String PLUGIN_VERSION = "7.18.14";
|
|
62
62
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
63
63
|
|
|
64
64
|
private SharedPreferences.Editor editor;
|
|
@@ -342,8 +342,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
342
342
|
} catch (Exception e) {
|
|
343
343
|
logger.error(
|
|
344
344
|
"Error hiding splashscreen with autoSplashscreen: " +
|
|
345
|
-
|
|
346
|
-
|
|
345
|
+
e.getMessage() +
|
|
346
|
+
". Make sure @capacitor/splash-screen plugin is installed and configured."
|
|
347
347
|
);
|
|
348
348
|
}
|
|
349
349
|
}
|
|
@@ -605,24 +605,24 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
605
605
|
logger.info("unsetChannel triggerAutoUpdate: " + triggerAutoUpdate);
|
|
606
606
|
startNewThread(() ->
|
|
607
607
|
CapacitorUpdaterPlugin.this.implementation.unsetChannel((res) -> {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
608
|
+
JSObject jsRes = mapToJSObject(res);
|
|
609
|
+
if (jsRes.has("error")) {
|
|
610
|
+
String errorMessage = jsRes.has("message") ? jsRes.getString("message") : jsRes.getString("error");
|
|
611
|
+
String errorCode = jsRes.getString("error");
|
|
612
612
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
613
|
+
JSObject errorObj = new JSObject();
|
|
614
|
+
errorObj.put("message", errorMessage);
|
|
615
|
+
errorObj.put("error", errorCode);
|
|
616
616
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
call.resolve(jsRes);
|
|
617
|
+
call.reject(errorMessage, "UNSETCHANNEL_FAILED", null, errorObj);
|
|
618
|
+
} else {
|
|
619
|
+
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() && Boolean.TRUE.equals(triggerAutoUpdate)) {
|
|
620
|
+
logger.info("Calling autoupdater after channel change!");
|
|
621
|
+
backgroundDownload();
|
|
624
622
|
}
|
|
625
|
-
|
|
623
|
+
call.resolve(jsRes);
|
|
624
|
+
}
|
|
625
|
+
})
|
|
626
626
|
);
|
|
627
627
|
} catch (final Exception e) {
|
|
628
628
|
logger.error("Failed to unsetChannel: " + e.getMessage());
|
|
@@ -647,24 +647,24 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
647
647
|
logger.info("setChannel " + channel + " triggerAutoUpdate: " + triggerAutoUpdate);
|
|
648
648
|
startNewThread(() ->
|
|
649
649
|
CapacitorUpdaterPlugin.this.implementation.setChannel(channel, (res) -> {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
650
|
+
JSObject jsRes = mapToJSObject(res);
|
|
651
|
+
if (jsRes.has("error")) {
|
|
652
|
+
String errorMessage = jsRes.has("message") ? jsRes.getString("message") : jsRes.getString("error");
|
|
653
|
+
String errorCode = jsRes.getString("error");
|
|
654
654
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
655
|
+
JSObject errorObj = new JSObject();
|
|
656
|
+
errorObj.put("message", errorMessage);
|
|
657
|
+
errorObj.put("error", errorCode);
|
|
658
658
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
}
|
|
665
|
-
call.resolve(jsRes);
|
|
659
|
+
call.reject(errorMessage, "SETCHANNEL_FAILED", null, errorObj);
|
|
660
|
+
} else {
|
|
661
|
+
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() && Boolean.TRUE.equals(triggerAutoUpdate)) {
|
|
662
|
+
logger.info("Calling autoupdater after channel change!");
|
|
663
|
+
backgroundDownload();
|
|
666
664
|
}
|
|
667
|
-
|
|
665
|
+
call.resolve(jsRes);
|
|
666
|
+
}
|
|
667
|
+
})
|
|
668
668
|
);
|
|
669
669
|
} catch (final Exception e) {
|
|
670
670
|
logger.error("Failed to setChannel: " + channel + " " + e.getMessage());
|
|
@@ -678,20 +678,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
678
678
|
logger.info("getChannel");
|
|
679
679
|
startNewThread(() ->
|
|
680
680
|
CapacitorUpdaterPlugin.this.implementation.getChannel((res) -> {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
681
|
+
JSObject jsRes = mapToJSObject(res);
|
|
682
|
+
if (jsRes.has("error")) {
|
|
683
|
+
String errorMessage = jsRes.has("message") ? jsRes.getString("message") : jsRes.getString("error");
|
|
684
|
+
String errorCode = jsRes.getString("error");
|
|
685
685
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
686
|
+
JSObject errorObj = new JSObject();
|
|
687
|
+
errorObj.put("message", errorMessage);
|
|
688
|
+
errorObj.put("error", errorCode);
|
|
689
689
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
690
|
+
call.reject(errorMessage, "GETCHANNEL_FAILED", null, errorObj);
|
|
691
|
+
} else {
|
|
692
|
+
call.resolve(jsRes);
|
|
693
|
+
}
|
|
694
|
+
})
|
|
695
695
|
);
|
|
696
696
|
} catch (final Exception e) {
|
|
697
697
|
logger.error("Failed to getChannel " + e.getMessage());
|
|
@@ -705,20 +705,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
705
705
|
logger.info("listChannels");
|
|
706
706
|
startNewThread(() ->
|
|
707
707
|
CapacitorUpdaterPlugin.this.implementation.listChannels((res) -> {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
708
|
+
JSObject jsRes = mapToJSObject(res);
|
|
709
|
+
if (jsRes.has("error")) {
|
|
710
|
+
String errorMessage = jsRes.has("message") ? jsRes.getString("message") : jsRes.getString("error");
|
|
711
|
+
String errorCode = jsRes.getString("error");
|
|
712
712
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
713
|
+
JSObject errorObj = new JSObject();
|
|
714
|
+
errorObj.put("message", errorMessage);
|
|
715
|
+
errorObj.put("error", errorCode);
|
|
716
716
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
717
|
+
call.reject(errorMessage, "LISTCHANNELS_FAILED", null, errorObj);
|
|
718
|
+
} else {
|
|
719
|
+
call.resolve(jsRes);
|
|
720
|
+
}
|
|
721
|
+
})
|
|
722
722
|
);
|
|
723
723
|
} catch (final Exception e) {
|
|
724
724
|
logger.error("Failed to listChannels: " + e.getMessage());
|
|
@@ -797,18 +797,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
797
797
|
if (Looper.myLooper() != Looper.getMainLooper()) {
|
|
798
798
|
Semaphore mainThreadSemaphore = new Semaphore(0);
|
|
799
799
|
this.bridge.executeOnMainThread(() -> {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
}
|
|
800
|
+
try {
|
|
801
|
+
if (this.bridge != null && this.bridge.getWebView() != null) {
|
|
802
|
+
String currentUrl = this.bridge.getWebView().getUrl();
|
|
803
|
+
if (currentUrl != null) {
|
|
804
|
+
url.set(new URL(currentUrl));
|
|
806
805
|
}
|
|
807
|
-
} catch (Exception e) {
|
|
808
|
-
logger.error("Error executing on main thread " + e.getMessage());
|
|
809
806
|
}
|
|
810
|
-
|
|
811
|
-
|
|
807
|
+
} catch (Exception e) {
|
|
808
|
+
logger.error("Error executing on main thread " + e.getMessage());
|
|
809
|
+
}
|
|
810
|
+
mainThreadSemaphore.release();
|
|
811
|
+
});
|
|
812
812
|
|
|
813
813
|
// Add timeout to prevent indefinite blocking
|
|
814
814
|
if (!mainThreadSemaphore.tryAcquire(10, TimeUnit.SECONDS)) {
|
|
@@ -845,9 +845,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
845
845
|
finalUrl = new URL(finalUrl.getProtocol(), finalUrl.getHost(), finalUrl.getPort(), url.get().getPath());
|
|
846
846
|
URL finalUrl1 = finalUrl;
|
|
847
847
|
this.bridge.getWebView().post(() -> {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
848
|
+
this.bridge.getWebView().loadUrl(finalUrl1.toString());
|
|
849
|
+
this.bridge.getWebView().clearHistory();
|
|
850
|
+
});
|
|
851
851
|
} catch (MalformedURLException e) {
|
|
852
852
|
logger.error("Cannot get finalUrl from capacitor bridge " + e.getMessage());
|
|
853
853
|
|
|
@@ -984,17 +984,17 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
984
984
|
final String channel = call.getString("channel");
|
|
985
985
|
startNewThread(() ->
|
|
986
986
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, channel, (res) -> {
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
987
|
+
JSObject jsRes = mapToJSObject(res);
|
|
988
|
+
if (jsRes.has("error")) {
|
|
989
|
+
call.reject(jsRes.getString("error"));
|
|
990
|
+
return;
|
|
991
|
+
} else if (jsRes.has("message")) {
|
|
992
|
+
call.reject(jsRes.getString("message"));
|
|
993
|
+
return;
|
|
994
|
+
} else {
|
|
995
|
+
call.resolve(jsRes);
|
|
996
|
+
}
|
|
997
|
+
})
|
|
998
998
|
);
|
|
999
999
|
}
|
|
1000
1000
|
|
|
@@ -1069,18 +1069,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1069
1069
|
public void run() {
|
|
1070
1070
|
try {
|
|
1071
1071
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, (res) -> {
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
}
|
|
1072
|
+
JSObject jsRes = mapToJSObject(res);
|
|
1073
|
+
if (jsRes.has("error")) {
|
|
1074
|
+
logger.error(Objects.requireNonNull(jsRes.getString("error")));
|
|
1075
|
+
} else if (jsRes.has("version")) {
|
|
1076
|
+
String newVersion = jsRes.getString("version");
|
|
1077
|
+
String currentVersion = String.valueOf(CapacitorUpdaterPlugin.this.implementation.getCurrentBundle());
|
|
1078
|
+
if (!Objects.equals(newVersion, currentVersion)) {
|
|
1079
|
+
logger.info("New version found: " + newVersion);
|
|
1080
|
+
CapacitorUpdaterPlugin.this.backgroundDownload();
|
|
1082
1081
|
}
|
|
1083
|
-
}
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
1084
|
} catch (final Exception e) {
|
|
1085
1085
|
logger.error("Failed to check for update " + e.getMessage());
|
|
1086
1086
|
}
|
|
@@ -1239,11 +1239,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1239
1239
|
if (error) {
|
|
1240
1240
|
logger.info(
|
|
1241
1241
|
"endBackGroundTaskWithNotif error: " +
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1242
|
+
error +
|
|
1243
|
+
" current: " +
|
|
1244
|
+
current.getVersionName() +
|
|
1245
|
+
"latestVersionName: " +
|
|
1246
|
+
latestVersionName
|
|
1247
1247
|
);
|
|
1248
1248
|
this.implementation.sendStats(failureAction, current.getVersionName());
|
|
1249
1249
|
final JSObject ret = new JSObject();
|
|
@@ -1266,238 +1266,226 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1266
1266
|
logger.info("Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl);
|
|
1267
1267
|
try {
|
|
1268
1268
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, (res) -> {
|
|
1269
|
-
|
|
1270
|
-
|
|
1269
|
+
JSObject jsRes = mapToJSObject(res);
|
|
1270
|
+
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
1271
|
+
|
|
1272
|
+
// Handle network errors and other failures first
|
|
1273
|
+
if (jsRes.has("error")) {
|
|
1274
|
+
String error = jsRes.getString("error");
|
|
1275
|
+
logger.error("getLatest failed with error: " + error);
|
|
1276
|
+
String latestVersion = jsRes.has("version") ? jsRes.getString("version") : current.getVersionName();
|
|
1277
|
+
if ("response_error".equals(error)) {
|
|
1278
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1279
|
+
"Network error: " + error,
|
|
1280
|
+
latestVersion,
|
|
1281
|
+
current,
|
|
1282
|
+
true,
|
|
1283
|
+
shouldDirectUpdate
|
|
1284
|
+
);
|
|
1285
|
+
} else {
|
|
1286
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1287
|
+
error,
|
|
1288
|
+
latestVersion,
|
|
1289
|
+
current,
|
|
1290
|
+
true,
|
|
1291
|
+
shouldDirectUpdate,
|
|
1292
|
+
"backend_refusal",
|
|
1293
|
+
"backendRefused"
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1271
1298
|
|
|
1272
|
-
|
|
1273
|
-
if (jsRes.has("
|
|
1274
|
-
|
|
1275
|
-
|
|
1299
|
+
try {
|
|
1300
|
+
if (jsRes.has("message")) {
|
|
1301
|
+
logger.info("API message: " + jsRes.get("message"));
|
|
1302
|
+
if (jsRes.has("major") && jsRes.getBoolean("major") && jsRes.has("version")) {
|
|
1303
|
+
final JSObject majorAvailable = new JSObject();
|
|
1304
|
+
majorAvailable.put("version", jsRes.getString("version"));
|
|
1305
|
+
CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", majorAvailable);
|
|
1306
|
+
}
|
|
1276
1307
|
String latestVersion = jsRes.has("version") ? jsRes.getString("version") : current.getVersionName();
|
|
1277
|
-
|
|
1308
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1309
|
+
jsRes.getString("message"),
|
|
1310
|
+
latestVersion,
|
|
1311
|
+
current,
|
|
1312
|
+
true,
|
|
1313
|
+
shouldDirectUpdate,
|
|
1314
|
+
"backend_refusal",
|
|
1315
|
+
"backendRefused"
|
|
1316
|
+
);
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
final String latestVersionName = jsRes.getString("version");
|
|
1321
|
+
|
|
1322
|
+
if ("builtin".equals(latestVersionName)) {
|
|
1323
|
+
logger.info("Latest version is builtin");
|
|
1324
|
+
if (shouldDirectUpdate) {
|
|
1325
|
+
logger.info("Direct update to builtin version");
|
|
1326
|
+
this._reset(false);
|
|
1278
1327
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1279
|
-
"
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1328
|
+
"Updated to builtin version",
|
|
1329
|
+
latestVersionName,
|
|
1330
|
+
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle(),
|
|
1331
|
+
false,
|
|
1332
|
+
true
|
|
1284
1333
|
);
|
|
1285
1334
|
} else {
|
|
1335
|
+
logger.info("Setting next bundle to builtin");
|
|
1336
|
+
CapacitorUpdaterPlugin.this.implementation.setNextBundle(BundleInfo.ID_BUILTIN);
|
|
1286
1337
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1287
|
-
|
|
1288
|
-
|
|
1338
|
+
"Next update will be to builtin version",
|
|
1339
|
+
latestVersionName,
|
|
1289
1340
|
current,
|
|
1290
|
-
|
|
1291
|
-
shouldDirectUpdate,
|
|
1292
|
-
"backend_refusal",
|
|
1293
|
-
"backendRefused"
|
|
1341
|
+
false
|
|
1294
1342
|
);
|
|
1295
1343
|
}
|
|
1296
1344
|
return;
|
|
1297
1345
|
}
|
|
1298
1346
|
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
latestVersion,
|
|
1311
|
-
current,
|
|
1312
|
-
true,
|
|
1313
|
-
shouldDirectUpdate,
|
|
1314
|
-
"backend_refusal",
|
|
1315
|
-
"backendRefused"
|
|
1316
|
-
);
|
|
1317
|
-
return;
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
final String latestVersionName = jsRes.getString("version");
|
|
1347
|
+
if (!jsRes.has("url") || !CapacitorUpdaterPlugin.this.isValidURL(jsRes.getString("url"))) {
|
|
1348
|
+
logger.error("Error no url or wrong format");
|
|
1349
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1350
|
+
"Error no url or wrong format",
|
|
1351
|
+
current.getVersionName(),
|
|
1352
|
+
current,
|
|
1353
|
+
true,
|
|
1354
|
+
shouldDirectUpdate
|
|
1355
|
+
);
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1321
1358
|
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
false,
|
|
1332
|
-
true
|
|
1333
|
-
);
|
|
1334
|
-
} else {
|
|
1335
|
-
logger.info("Setting next bundle to builtin");
|
|
1336
|
-
CapacitorUpdaterPlugin.this.implementation.setNextBundle(BundleInfo.ID_BUILTIN);
|
|
1359
|
+
if (
|
|
1360
|
+
latestVersionName != null && !latestVersionName.isEmpty() && !current.getVersionName().equals(latestVersionName)
|
|
1361
|
+
) {
|
|
1362
|
+
final BundleInfo latest = CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(latestVersionName);
|
|
1363
|
+
if (latest != null) {
|
|
1364
|
+
final JSObject ret = new JSObject();
|
|
1365
|
+
ret.put("bundle", mapToJSObject(latest.toJSONMap()));
|
|
1366
|
+
if (latest.isErrorStatus()) {
|
|
1367
|
+
logger.error("Latest bundle already exists, and is in error state. Aborting update.");
|
|
1337
1368
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1338
|
-
"
|
|
1369
|
+
"Latest bundle already exists, and is in error state. Aborting update.",
|
|
1339
1370
|
latestVersionName,
|
|
1340
1371
|
current,
|
|
1341
|
-
|
|
1372
|
+
true,
|
|
1373
|
+
shouldDirectUpdate
|
|
1342
1374
|
);
|
|
1375
|
+
return;
|
|
1343
1376
|
}
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
"Error no url or wrong format",
|
|
1351
|
-
current.getVersionName(),
|
|
1352
|
-
current,
|
|
1353
|
-
true,
|
|
1354
|
-
shouldDirectUpdate
|
|
1355
|
-
);
|
|
1356
|
-
return;
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
if (
|
|
1360
|
-
latestVersionName != null &&
|
|
1361
|
-
!latestVersionName.isEmpty() &&
|
|
1362
|
-
!current.getVersionName().equals(latestVersionName)
|
|
1363
|
-
) {
|
|
1364
|
-
final BundleInfo latest = CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(latestVersionName);
|
|
1365
|
-
if (latest != null) {
|
|
1366
|
-
final JSObject ret = new JSObject();
|
|
1367
|
-
ret.put("bundle", mapToJSObject(latest.toJSONMap()));
|
|
1368
|
-
if (latest.isErrorStatus()) {
|
|
1369
|
-
logger.error("Latest bundle already exists, and is in error state. Aborting update.");
|
|
1370
|
-
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1371
|
-
"Latest bundle already exists, and is in error state. Aborting update.",
|
|
1372
|
-
latestVersionName,
|
|
1373
|
-
current,
|
|
1374
|
-
true,
|
|
1375
|
-
shouldDirectUpdate
|
|
1377
|
+
if (latest.isDownloaded()) {
|
|
1378
|
+
logger.info("Latest bundle already exists and download is NOT required. " + messageUpdate);
|
|
1379
|
+
if (shouldDirectUpdate) {
|
|
1380
|
+
String delayUpdatePreferences = prefs.getString(DelayUpdateUtils.DELAY_CONDITION_PREFERENCES, "[]");
|
|
1381
|
+
ArrayList<DelayCondition> delayConditionList = delayUpdateUtils.parseDelayConditions(
|
|
1382
|
+
delayUpdatePreferences
|
|
1376
1383
|
);
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
if (latest.isDownloaded()) {
|
|
1380
|
-
logger.info("Latest bundle already exists and download is NOT required. " + messageUpdate);
|
|
1381
|
-
if (shouldDirectUpdate) {
|
|
1382
|
-
String delayUpdatePreferences = prefs.getString(
|
|
1383
|
-
DelayUpdateUtils.DELAY_CONDITION_PREFERENCES,
|
|
1384
|
-
"[]"
|
|
1385
|
-
);
|
|
1386
|
-
ArrayList<DelayCondition> delayConditionList = delayUpdateUtils.parseDelayConditions(
|
|
1387
|
-
delayUpdatePreferences
|
|
1388
|
-
);
|
|
1389
|
-
if (!delayConditionList.isEmpty()) {
|
|
1390
|
-
logger.info("Update delayed until delay conditions met");
|
|
1391
|
-
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1392
|
-
"Update delayed until delay conditions met",
|
|
1393
|
-
latestVersionName,
|
|
1394
|
-
latest,
|
|
1395
|
-
false,
|
|
1396
|
-
shouldDirectUpdate
|
|
1397
|
-
);
|
|
1398
|
-
return;
|
|
1399
|
-
}
|
|
1400
|
-
CapacitorUpdaterPlugin.this.implementation.set(latest);
|
|
1401
|
-
CapacitorUpdaterPlugin.this._reload();
|
|
1384
|
+
if (!delayConditionList.isEmpty()) {
|
|
1385
|
+
logger.info("Update delayed until delay conditions met");
|
|
1402
1386
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1403
|
-
"Update
|
|
1387
|
+
"Update delayed until delay conditions met",
|
|
1404
1388
|
latestVersionName,
|
|
1405
1389
|
latest,
|
|
1406
1390
|
false,
|
|
1407
|
-
|
|
1408
|
-
);
|
|
1409
|
-
} else {
|
|
1410
|
-
CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
|
|
1411
|
-
CapacitorUpdaterPlugin.this.implementation.setNextBundle(latest.getId());
|
|
1412
|
-
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1413
|
-
"update downloaded, will install next background",
|
|
1414
|
-
latestVersionName,
|
|
1415
|
-
latest,
|
|
1416
|
-
false
|
|
1391
|
+
shouldDirectUpdate
|
|
1417
1392
|
);
|
|
1393
|
+
return;
|
|
1418
1394
|
}
|
|
1419
|
-
|
|
1395
|
+
CapacitorUpdaterPlugin.this.implementation.set(latest);
|
|
1396
|
+
CapacitorUpdaterPlugin.this._reload();
|
|
1397
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1398
|
+
"Update installed",
|
|
1399
|
+
latestVersionName,
|
|
1400
|
+
latest,
|
|
1401
|
+
false,
|
|
1402
|
+
true
|
|
1403
|
+
);
|
|
1404
|
+
} else {
|
|
1405
|
+
CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
|
|
1406
|
+
CapacitorUpdaterPlugin.this.implementation.setNextBundle(latest.getId());
|
|
1407
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1408
|
+
"update downloaded, will install next background",
|
|
1409
|
+
latestVersionName,
|
|
1410
|
+
latest,
|
|
1411
|
+
false
|
|
1412
|
+
);
|
|
1420
1413
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
logger.error(
|
|
1430
|
-
"Failed to delete failed bundle: " + latest.getVersionName() + " " + e.getMessage()
|
|
1431
|
-
);
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
if (latest.isDeleted()) {
|
|
1417
|
+
logger.info("Latest bundle already exists and will be deleted, download will overwrite it.");
|
|
1418
|
+
try {
|
|
1419
|
+
final Boolean deleted = CapacitorUpdaterPlugin.this.implementation.delete(latest.getId(), true);
|
|
1420
|
+
if (deleted) {
|
|
1421
|
+
logger.info("Failed bundle deleted: " + latest.getVersionName());
|
|
1432
1422
|
}
|
|
1423
|
+
} catch (final IOException e) {
|
|
1424
|
+
logger.error("Failed to delete failed bundle: " + latest.getVersionName() + " " + e.getMessage());
|
|
1433
1425
|
}
|
|
1434
1426
|
}
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1427
|
+
}
|
|
1428
|
+
startNewThread(() -> {
|
|
1429
|
+
try {
|
|
1430
|
+
logger.info(
|
|
1431
|
+
"New bundle: " +
|
|
1439
1432
|
latestVersionName +
|
|
1440
1433
|
" found. Current is: " +
|
|
1441
1434
|
current.getVersionName() +
|
|
1442
1435
|
". " +
|
|
1443
1436
|
messageUpdate
|
|
1444
|
-
|
|
1437
|
+
);
|
|
1445
1438
|
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1439
|
+
final String url = jsRes.getString("url");
|
|
1440
|
+
final String sessionKey = jsRes.has("sessionKey") ? jsRes.getString("sessionKey") : "";
|
|
1441
|
+
final String checksum = jsRes.has("checksum") ? jsRes.getString("checksum") : "";
|
|
1449
1442
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
latestVersionName,
|
|
1465
|
-
sessionKey,
|
|
1466
|
-
checksum,
|
|
1467
|
-
null
|
|
1468
|
-
);
|
|
1469
|
-
}
|
|
1470
|
-
} catch (final Exception e) {
|
|
1471
|
-
logger.error("error downloading file " + e.getMessage());
|
|
1472
|
-
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1473
|
-
"Error downloading file",
|
|
1443
|
+
if (jsRes.has("manifest")) {
|
|
1444
|
+
// Handle manifest-based download
|
|
1445
|
+
JSONArray manifest = jsRes.getJSONArray("manifest");
|
|
1446
|
+
CapacitorUpdaterPlugin.this.implementation.downloadBackground(
|
|
1447
|
+
url,
|
|
1448
|
+
latestVersionName,
|
|
1449
|
+
sessionKey,
|
|
1450
|
+
checksum,
|
|
1451
|
+
manifest
|
|
1452
|
+
);
|
|
1453
|
+
} else {
|
|
1454
|
+
// Handle single file download (existing code)
|
|
1455
|
+
CapacitorUpdaterPlugin.this.implementation.downloadBackground(
|
|
1456
|
+
url,
|
|
1474
1457
|
latestVersionName,
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1458
|
+
sessionKey,
|
|
1459
|
+
checksum,
|
|
1460
|
+
null
|
|
1478
1461
|
);
|
|
1479
1462
|
}
|
|
1480
|
-
})
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
current.getVersionName(),
|
|
1495
|
-
current,
|
|
1496
|
-
true,
|
|
1497
|
-
shouldDirectUpdate
|
|
1498
|
-
);
|
|
1463
|
+
} catch (final Exception e) {
|
|
1464
|
+
logger.error("error downloading file " + e.getMessage());
|
|
1465
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1466
|
+
"Error downloading file",
|
|
1467
|
+
latestVersionName,
|
|
1468
|
+
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle(),
|
|
1469
|
+
true,
|
|
1470
|
+
shouldDirectUpdate
|
|
1471
|
+
);
|
|
1472
|
+
}
|
|
1473
|
+
});
|
|
1474
|
+
} else {
|
|
1475
|
+
logger.info("No need to update, " + current.getId() + " is the latest bundle.");
|
|
1476
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif("No need to update", latestVersionName, current, false);
|
|
1499
1477
|
}
|
|
1500
|
-
})
|
|
1478
|
+
} catch (final JSONException e) {
|
|
1479
|
+
logger.error("error parsing JSON " + e.getMessage());
|
|
1480
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1481
|
+
"Error parsing JSON",
|
|
1482
|
+
current.getVersionName(),
|
|
1483
|
+
current,
|
|
1484
|
+
true,
|
|
1485
|
+
shouldDirectUpdate
|
|
1486
|
+
);
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1501
1489
|
} catch (final Exception e) {
|
|
1502
1490
|
logger.error("getLatest call failed: " + e.getMessage());
|
|
1503
1491
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
@@ -1235,11 +1235,11 @@ public class CapgoUpdater {
|
|
|
1235
1235
|
} catch (JSONException e) {
|
|
1236
1236
|
logger.error(
|
|
1237
1237
|
"Failed to parse info for bundle [" +
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1238
|
+
trueId +
|
|
1239
|
+
"] stored value: '" +
|
|
1240
|
+
this.prefs.getString(trueId + INFO_SUFFIX, "") +
|
|
1241
|
+
"' error: " +
|
|
1242
|
+
e.getMessage()
|
|
1243
1243
|
);
|
|
1244
1244
|
// Clear corrupted data
|
|
1245
1245
|
this.editor.remove(trueId + INFO_SUFFIX);
|
|
@@ -62,35 +62,35 @@ public class DelayUpdateUtils {
|
|
|
62
62
|
} catch (NumberFormatException e) {
|
|
63
63
|
logger.error(
|
|
64
64
|
"Background condition (value: " +
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
value +
|
|
66
|
+
") had an invalid value at index " +
|
|
67
|
+
index +
|
|
68
|
+
". We will likely remove it."
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (delta > longValue) {
|
|
73
73
|
logger.info(
|
|
74
74
|
"Background condition (value: " +
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
value +
|
|
76
|
+
") deleted at index " +
|
|
77
|
+
index +
|
|
78
|
+
". Delta: " +
|
|
79
|
+
delta +
|
|
80
|
+
", longValue: " +
|
|
81
|
+
longValue
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
84
|
} else {
|
|
85
85
|
delayConditionListToKeep.add(condition);
|
|
86
86
|
logger.info(
|
|
87
87
|
"Background delay (value: " +
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
value +
|
|
89
|
+
") condition kept at index " +
|
|
90
|
+
index +
|
|
91
|
+
" (source: " +
|
|
92
|
+
source.toString() +
|
|
93
|
+
")"
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
96
|
break;
|
|
@@ -119,11 +119,11 @@ public class DelayUpdateUtils {
|
|
|
119
119
|
} catch (final Exception e) {
|
|
120
120
|
logger.error(
|
|
121
121
|
"Date delay (value: " +
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
value +
|
|
123
|
+
") condition removed due to parsing issue at index " +
|
|
124
|
+
index +
|
|
125
|
+
" " +
|
|
126
|
+
e.getMessage()
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
} else {
|
|
@@ -145,11 +145,11 @@ public class DelayUpdateUtils {
|
|
|
145
145
|
} catch (final Exception e) {
|
|
146
146
|
logger.error(
|
|
147
147
|
"Native version delay (value: " +
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
value +
|
|
149
|
+
") condition removed due to parsing issue at index " +
|
|
150
|
+
index +
|
|
151
|
+
" " +
|
|
152
|
+
e.getMessage()
|
|
153
153
|
);
|
|
154
154
|
}
|
|
155
155
|
} else {
|
|
@@ -549,13 +549,13 @@ public class DownloadService extends Worker {
|
|
|
549
549
|
finalTargetFile.delete();
|
|
550
550
|
throw new IOException(
|
|
551
551
|
"Checksum verification failed for: " +
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
552
|
+
downloadUrl +
|
|
553
|
+
" " +
|
|
554
|
+
targetFile.getName() +
|
|
555
|
+
" expected: " +
|
|
556
|
+
expectedHash +
|
|
557
|
+
" calculated: " +
|
|
558
|
+
calculatedHash
|
|
559
559
|
);
|
|
560
560
|
}
|
|
561
561
|
} catch (Exception e) {
|
|
@@ -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.18.
|
|
53
|
+
private let PLUGIN_VERSION: String = "7.18.14"
|
|
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"
|