@capgo/capacitor-updater 6.14.24 → 6.14.26
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.
|
@@ -57,7 +57,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
57
57
|
private static final String statsUrlDefault = "https://plugin.capgo.app/stats";
|
|
58
58
|
private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
|
|
59
59
|
|
|
60
|
-
private final String PLUGIN_VERSION = "6.14.
|
|
60
|
+
private final String PLUGIN_VERSION = "6.14.26";
|
|
61
61
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
62
62
|
|
|
63
63
|
private SharedPreferences.Editor editor;
|
|
@@ -65,7 +65,6 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
65
65
|
protected CapacitorUpdater implementation;
|
|
66
66
|
|
|
67
67
|
private Integer appReadyTimeout = 10000;
|
|
68
|
-
private Integer counterActivityCreate = 0;
|
|
69
68
|
private Integer periodCheckDelay = 0;
|
|
70
69
|
private Boolean autoDeleteFailed = true;
|
|
71
70
|
private Boolean autoDeletePrevious = true;
|
|
@@ -108,7 +107,6 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
108
107
|
@Override
|
|
109
108
|
public void load() {
|
|
110
109
|
super.load();
|
|
111
|
-
this.counterActivityCreate++;
|
|
112
110
|
this.prefs = this.getContext().getSharedPreferences(WebView.WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
|
|
113
111
|
this.editor = this.prefs.edit();
|
|
114
112
|
|
|
@@ -199,6 +197,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
199
197
|
if (resetWhenUpdate) {
|
|
200
198
|
this.cleanupObsoleteVersions();
|
|
201
199
|
}
|
|
200
|
+
|
|
201
|
+
// Check for 'kill' delay condition on app launch
|
|
202
|
+
// This handles cases where the app was killed by the system (onDestroy is not reliable)
|
|
203
|
+
this._checkCancelDelay(true);
|
|
204
|
+
|
|
202
205
|
this.checkForUpdateAfterDelay();
|
|
203
206
|
}
|
|
204
207
|
|
|
@@ -1002,6 +1005,17 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1002
1005
|
}
|
|
1003
1006
|
|
|
1004
1007
|
private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
|
|
1008
|
+
endBackGroundTaskWithNotif(msg, latestVersionName, current, error, "download_fail", "downloadFailed");
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
private void endBackGroundTaskWithNotif(
|
|
1012
|
+
String msg,
|
|
1013
|
+
String latestVersionName,
|
|
1014
|
+
BundleInfo current,
|
|
1015
|
+
Boolean error,
|
|
1016
|
+
String failureAction,
|
|
1017
|
+
String failureEvent
|
|
1018
|
+
) {
|
|
1005
1019
|
if (error) {
|
|
1006
1020
|
Log.i(
|
|
1007
1021
|
CapacitorUpdater.TAG,
|
|
@@ -1012,10 +1026,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1012
1026
|
"latestVersionName: " +
|
|
1013
1027
|
latestVersionName
|
|
1014
1028
|
);
|
|
1015
|
-
this.implementation.sendStats(
|
|
1029
|
+
this.implementation.sendStats(failureAction, current.getVersionName());
|
|
1016
1030
|
final JSObject ret = new JSObject();
|
|
1017
1031
|
ret.put("version", latestVersionName);
|
|
1018
|
-
this.notifyListeners(
|
|
1032
|
+
this.notifyListeners(failureEvent, ret);
|
|
1019
1033
|
}
|
|
1020
1034
|
final JSObject ret = new JSObject();
|
|
1021
1035
|
ret.put("bundle", current.toJSON());
|
|
@@ -1034,6 +1048,34 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1034
1048
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
1035
1049
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
1036
1050
|
try {
|
|
1051
|
+
if (res.has("error")) {
|
|
1052
|
+
final String error = res.optString("error", "");
|
|
1053
|
+
if (error != null && !error.isEmpty()) {
|
|
1054
|
+
Log.e(CapacitorUpdater.TAG, "getLatest failed with error: " + error);
|
|
1055
|
+
final String latestVersion = res.has("version")
|
|
1056
|
+
? res.optString("version", current.getVersionName())
|
|
1057
|
+
: current.getVersionName();
|
|
1058
|
+
if ("response_error".equals(error)) {
|
|
1059
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1060
|
+
"Network error: " + error,
|
|
1061
|
+
latestVersion,
|
|
1062
|
+
current,
|
|
1063
|
+
true
|
|
1064
|
+
);
|
|
1065
|
+
} else {
|
|
1066
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1067
|
+
error,
|
|
1068
|
+
latestVersion,
|
|
1069
|
+
current,
|
|
1070
|
+
true,
|
|
1071
|
+
"backend_refusal",
|
|
1072
|
+
"backendRefused"
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1037
1079
|
if (res.has("message")) {
|
|
1038
1080
|
Log.i(CapacitorUpdater.TAG, "API message: " + res.get("message"));
|
|
1039
1081
|
if (res.has("major") && res.getBoolean("major") && res.has("version")) {
|
|
@@ -1041,11 +1083,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1041
1083
|
majorAvailable.put("version", res.getString("version"));
|
|
1042
1084
|
CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", majorAvailable);
|
|
1043
1085
|
}
|
|
1086
|
+
final String latestVersion = res.has("version")
|
|
1087
|
+
? res.optString("version", current.getVersionName())
|
|
1088
|
+
: current.getVersionName();
|
|
1044
1089
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1045
1090
|
res.getString("message"),
|
|
1046
|
-
|
|
1091
|
+
latestVersion,
|
|
1047
1092
|
current,
|
|
1048
|
-
true
|
|
1093
|
+
true,
|
|
1094
|
+
"backend_refusal",
|
|
1095
|
+
"backendRefused"
|
|
1049
1096
|
);
|
|
1050
1097
|
return;
|
|
1051
1098
|
}
|
|
@@ -1367,11 +1414,6 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1367
1414
|
}
|
|
1368
1415
|
}
|
|
1369
1416
|
|
|
1370
|
-
private void appKilled() {
|
|
1371
|
-
Log.d(CapacitorUpdater.TAG, "onActivityDestroyed: all activity destroyed");
|
|
1372
|
-
this._checkCancelDelay(true);
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
1417
|
@Override
|
|
1376
1418
|
public void handleOnStart() {
|
|
1377
1419
|
if (isPreviousMainActivity) {
|
|
@@ -1406,9 +1448,5 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1406
1448
|
public void handleOnDestroy() {
|
|
1407
1449
|
Log.i(CapacitorUpdater.TAG, "onActivityDestroyed " + getActivity().getClass().getName());
|
|
1408
1450
|
this.implementation.activity = getActivity();
|
|
1409
|
-
counterActivityCreate--;
|
|
1410
|
-
if (counterActivityCreate == 0) {
|
|
1411
|
-
this.appKilled();
|
|
1412
|
-
}
|
|
1413
1451
|
}
|
|
1414
1452
|
}
|
|
@@ -45,7 +45,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
45
45
|
CAPPluginMethod(name: "getNextBundle", returnType: CAPPluginReturnPromise)
|
|
46
46
|
]
|
|
47
47
|
public var implementation = CapacitorUpdater()
|
|
48
|
-
private let PLUGIN_VERSION: String = "6.14.
|
|
48
|
+
private let PLUGIN_VERSION: String = "6.14.26"
|
|
49
49
|
static let updateUrlDefault = "https://plugin.capgo.app/updates"
|
|
50
50
|
static let statsUrlDefault = "https://plugin.capgo.app/stats"
|
|
51
51
|
static let channelUrlDefault = "https://plugin.capgo.app/channel_self"
|
|
@@ -144,7 +144,11 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
144
144
|
let nc = NotificationCenter.default
|
|
145
145
|
nc.addObserver(self, selector: #selector(appMovedToBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
|
|
146
146
|
nc.addObserver(self, selector: #selector(appMovedToForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
|
|
147
|
-
|
|
147
|
+
|
|
148
|
+
// Check for 'kill' delay condition on app launch
|
|
149
|
+
// This handles cases where the app was killed (willTerminateNotification is not reliable for system kills)
|
|
150
|
+
self._checkCancelDelay(killed: true)
|
|
151
|
+
|
|
148
152
|
self.appMovedToForeground()
|
|
149
153
|
self.checkForUpdateAfterDelay()
|
|
150
154
|
}
|
|
@@ -732,10 +736,17 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
732
736
|
}
|
|
733
737
|
}
|
|
734
738
|
|
|
735
|
-
func endBackGroundTaskWithNotif(
|
|
739
|
+
func endBackGroundTaskWithNotif(
|
|
740
|
+
msg: String,
|
|
741
|
+
latestVersionName: String,
|
|
742
|
+
current: BundleInfo,
|
|
743
|
+
error: Bool = true,
|
|
744
|
+
failureAction: String = "download_fail",
|
|
745
|
+
failureEvent: String = "downloadFailed"
|
|
746
|
+
) {
|
|
736
747
|
if error {
|
|
737
|
-
self.implementation.sendStats(action:
|
|
738
|
-
self.notifyListeners(
|
|
748
|
+
self.implementation.sendStats(action: failureAction, versionName: current.getVersionName())
|
|
749
|
+
self.notifyListeners(failureEvent, data: ["version": latestVersionName])
|
|
739
750
|
}
|
|
740
751
|
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
741
752
|
self.sendReadyToJs(current: current, msg: msg)
|
|
@@ -758,12 +769,43 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
758
769
|
let res = self.implementation.getLatest(url: url, channel: nil)
|
|
759
770
|
let current = self.implementation.getCurrentBundle()
|
|
760
771
|
|
|
761
|
-
if
|
|
762
|
-
print("\(CapacitorUpdater.TAG)
|
|
772
|
+
if let backendError = res.error, !backendError.isEmpty {
|
|
773
|
+
print("\(CapacitorUpdater.TAG) getLatest failed with error: \(backendError)")
|
|
774
|
+
let latestVersionName = res.version.isEmpty ? current.getVersionName() : res.version
|
|
775
|
+
if backendError == "response_error" {
|
|
776
|
+
self.endBackGroundTaskWithNotif(
|
|
777
|
+
msg: "Network error: \(backendError)",
|
|
778
|
+
latestVersionName: latestVersionName,
|
|
779
|
+
current: current,
|
|
780
|
+
error: true
|
|
781
|
+
)
|
|
782
|
+
} else {
|
|
783
|
+
self.endBackGroundTaskWithNotif(
|
|
784
|
+
msg: backendError,
|
|
785
|
+
latestVersionName: latestVersionName,
|
|
786
|
+
current: current,
|
|
787
|
+
error: true,
|
|
788
|
+
failureAction: "backend_refusal",
|
|
789
|
+
failureEvent: "backendRefused"
|
|
790
|
+
)
|
|
791
|
+
}
|
|
792
|
+
return
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
if let message = res.message, !message.isEmpty {
|
|
796
|
+
print("\(CapacitorUpdater.TAG) API message: \(message)")
|
|
763
797
|
if res.major == true {
|
|
764
798
|
self.notifyListeners("majorAvailable", data: ["version": res.version])
|
|
765
799
|
}
|
|
766
|
-
|
|
800
|
+
let latestVersionName = res.version.isEmpty ? current.getVersionName() : res.version
|
|
801
|
+
self.endBackGroundTaskWithNotif(
|
|
802
|
+
msg: message,
|
|
803
|
+
latestVersionName: latestVersionName,
|
|
804
|
+
current: current,
|
|
805
|
+
error: true,
|
|
806
|
+
failureAction: "backend_refusal",
|
|
807
|
+
failureEvent: "backendRefused"
|
|
808
|
+
)
|
|
767
809
|
return
|
|
768
810
|
}
|
|
769
811
|
if res.version == "builtin" {
|
|
@@ -860,11 +902,6 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
860
902
|
}
|
|
861
903
|
}
|
|
862
904
|
|
|
863
|
-
@objc func appKilled() {
|
|
864
|
-
print("\(CapacitorUpdater.TAG) onActivityDestroyed: all activity destroyed")
|
|
865
|
-
self._checkCancelDelay(killed: true)
|
|
866
|
-
}
|
|
867
|
-
|
|
868
905
|
private func installNext() {
|
|
869
906
|
let delayUpdatePreferences = UserDefaults.standard.string(forKey: DELAY_CONDITION_PREFERENCES) ?? "[]"
|
|
870
907
|
let delayConditionList: [DelayCondition]? = fromJsonArr(json: delayUpdatePreferences).map { obj -> DelayCondition in
|