@capgo/capacitor-updater 7.16.0 → 7.17.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.16.0";
63
+ private final String PLUGIN_VERSION = "7.17.0";
64
64
  private static final String DELAY_CONDITION_PREFERENCES = "";
65
65
 
66
66
  private SharedPreferences.Editor editor;
@@ -1198,7 +1198,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
1198
1198
  }
1199
1199
 
1200
1200
  private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
1201
- endBackGroundTaskWithNotif(msg, latestVersionName, current, error, false);
1201
+ endBackGroundTaskWithNotif(msg, latestVersionName, current, error, false, "download_fail", "downloadFailed");
1202
1202
  }
1203
1203
 
1204
1204
  private void endBackGroundTaskWithNotif(
@@ -1207,6 +1207,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
1207
1207
  BundleInfo current,
1208
1208
  Boolean error,
1209
1209
  Boolean isDirectUpdate
1210
+ ) {
1211
+ endBackGroundTaskWithNotif(msg, latestVersionName, current, error, isDirectUpdate, "download_fail", "downloadFailed");
1212
+ }
1213
+
1214
+ private void endBackGroundTaskWithNotif(
1215
+ String msg,
1216
+ String latestVersionName,
1217
+ BundleInfo current,
1218
+ Boolean error,
1219
+ Boolean isDirectUpdate,
1220
+ String failureAction,
1221
+ String failureEvent
1210
1222
  ) {
1211
1223
  if (error) {
1212
1224
  logger.info(
@@ -1217,10 +1229,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
1217
1229
  "latestVersionName: " +
1218
1230
  latestVersionName
1219
1231
  );
1220
- this.implementation.sendStats("download_fail", current.getVersionName());
1232
+ this.implementation.sendStats(failureAction, current.getVersionName());
1221
1233
  final JSObject ret = new JSObject();
1222
1234
  ret.put("version", latestVersionName);
1223
- this.notifyListeners("downloadFailed", ret);
1235
+ this.notifyListeners(failureEvent, ret);
1224
1236
  }
1225
1237
  final JSObject ret = new JSObject();
1226
1238
  ret.put("bundle", mapToJSObject(current.toJSONMap()));
@@ -1245,13 +1257,26 @@ public class CapacitorUpdaterPlugin extends Plugin {
1245
1257
  if (jsRes.has("error")) {
1246
1258
  String error = jsRes.getString("error");
1247
1259
  logger.error("getLatest failed with error: " + error);
1248
- CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
1249
- "Network error: " + error,
1250
- current.getVersionName(),
1251
- current,
1252
- true,
1253
- shouldDirectUpdate
1254
- );
1260
+ String latestVersion = jsRes.has("version") ? jsRes.getString("version") : current.getVersionName();
1261
+ if ("response_error".equals(error)) {
1262
+ CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
1263
+ "Network error: " + error,
1264
+ latestVersion,
1265
+ current,
1266
+ true,
1267
+ shouldDirectUpdate
1268
+ );
1269
+ } else {
1270
+ CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
1271
+ error,
1272
+ latestVersion,
1273
+ current,
1274
+ true,
1275
+ shouldDirectUpdate,
1276
+ "backend_refusal",
1277
+ "backendRefused"
1278
+ );
1279
+ }
1255
1280
  return;
1256
1281
  }
1257
1282
 
@@ -1263,12 +1288,15 @@ public class CapacitorUpdaterPlugin extends Plugin {
1263
1288
  majorAvailable.put("version", jsRes.getString("version"));
1264
1289
  CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", majorAvailable);
1265
1290
  }
1291
+ String latestVersion = jsRes.has("version") ? jsRes.getString("version") : current.getVersionName();
1266
1292
  CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
1267
1293
  jsRes.getString("message"),
1268
- current.getVersionName(),
1294
+ latestVersion,
1269
1295
  current,
1270
1296
  true,
1271
- shouldDirectUpdate
1297
+ shouldDirectUpdate,
1298
+ "backend_refusal",
1299
+ "backendRefused"
1272
1300
  );
1273
1301
  return;
1274
1302
  }
@@ -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.16.0"
53
+ private let PLUGIN_VERSION: String = "7.17.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"
@@ -882,10 +882,17 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
882
882
  }
883
883
  }
884
884
 
885
- func endBackGroundTaskWithNotif(msg: String, latestVersionName: String, current: BundleInfo, error: Bool = true) {
885
+ func endBackGroundTaskWithNotif(
886
+ msg: String,
887
+ latestVersionName: String,
888
+ current: BundleInfo,
889
+ error: Bool = true,
890
+ failureAction: String = "download_fail",
891
+ failureEvent: String = "downloadFailed"
892
+ ) {
886
893
  if error {
887
- self.implementation.sendStats(action: "download_fail", versionName: current.getVersionName())
888
- self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
894
+ self.implementation.sendStats(action: failureAction, versionName: current.getVersionName())
895
+ self.notifyListeners(failureEvent, data: ["version": latestVersionName])
889
896
  }
890
897
  self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
891
898
  self.sendReadyToJs(current: current, msg: msg)
@@ -910,18 +917,41 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
910
917
  let current = self.implementation.getCurrentBundle()
911
918
 
912
919
  // Handle network errors and other failures first
913
- if res.error != nil {
914
- self.logger.error("getLatest failed with error: \(res.error ?? "")")
915
- self.endBackGroundTaskWithNotif(msg: "Network error: \(res.error ?? "")", latestVersionName: res.version, current: current, error: true)
920
+ if let backendError = res.error, !backendError.isEmpty {
921
+ self.logger.error("getLatest failed with error: \(backendError)")
922
+ if backendError == "response_error" {
923
+ self.endBackGroundTaskWithNotif(
924
+ msg: "Network error: \(backendError)",
925
+ latestVersionName: res.version,
926
+ current: current,
927
+ error: true
928
+ )
929
+ } else {
930
+ self.endBackGroundTaskWithNotif(
931
+ msg: backendError,
932
+ latestVersionName: res.version,
933
+ current: current,
934
+ error: true,
935
+ failureAction: "backend_refusal",
936
+ failureEvent: "backendRefused"
937
+ )
938
+ }
916
939
  return
917
940
  }
918
941
 
919
- if (res.message) != nil {
920
- self.logger.info("API message: \(res.message ?? "")")
942
+ if let message = res.message, !message.isEmpty {
943
+ self.logger.info("API message: \(message)")
921
944
  if res.major == true {
922
945
  self.notifyListeners("majorAvailable", data: ["version": res.version])
923
946
  }
924
- self.endBackGroundTaskWithNotif(msg: res.message ?? "", latestVersionName: res.version, current: current, error: true)
947
+ self.endBackGroundTaskWithNotif(
948
+ msg: message,
949
+ latestVersionName: res.version,
950
+ current: current,
951
+ error: true,
952
+ failureAction: "backend_refusal",
953
+ failureEvent: "backendRefused"
954
+ )
925
955
  return
926
956
  }
927
957
  if res.version == "builtin" {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "7.16.0",
3
+ "version": "7.17.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",