@capgo/capacitor-updater 6.14.23 → 6.14.25

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.
@@ -315,6 +315,7 @@ public class CapacitorUpdater {
315
315
  Boolean isManifest
316
316
  ) {
317
317
  File downloaded = null;
318
+ File extractedDir = null;
318
319
  String checksum = "";
319
320
 
320
321
  try {
@@ -339,6 +340,9 @@ public class CapacitorUpdater {
339
340
  }
340
341
  // Remove the decryption for manifest downloads
341
342
  } catch (Exception e) {
343
+ if (!isManifest) {
344
+ safeDelete(downloaded);
345
+ }
342
346
  final Boolean res = this.delete(id);
343
347
  if (!res) {
344
348
  Log.i(CapacitorUpdater.TAG, "Double error, cannot cleanup: " + version);
@@ -354,10 +358,10 @@ public class CapacitorUpdater {
354
358
 
355
359
  try {
356
360
  if (!isManifest) {
357
- final File unzipped = this.unzip(id, downloaded, this.randomString());
361
+ extractedDir = this.unzip(id, downloaded, this.randomString());
358
362
  this.notifyDownload(id, 91);
359
363
  final String idName = bundleDirectory + "/" + id;
360
- this.flattenAssets(unzipped, idName);
364
+ this.flattenAssets(extractedDir, idName);
361
365
  } else {
362
366
  this.notifyDownload(id, 91);
363
367
  final String idName = bundleDirectory + "/" + id;
@@ -381,6 +385,10 @@ public class CapacitorUpdater {
381
385
  }
382
386
  }
383
387
  } catch (IOException e) {
388
+ if (!isManifest) {
389
+ safeDelete(extractedDir);
390
+ safeDelete(downloaded);
391
+ }
384
392
  e.printStackTrace();
385
393
  final JSObject ret = new JSObject();
386
394
  ret.put("version", CapacitorUpdater.this.getCurrentBundle().getVersionName());
@@ -388,6 +396,9 @@ public class CapacitorUpdater {
388
396
  CapacitorUpdater.this.sendStats("download_fail");
389
397
  return false;
390
398
  }
399
+ if (!isManifest) {
400
+ safeDelete(downloaded);
401
+ }
391
402
  return true;
392
403
  }
393
404
 
@@ -405,6 +416,21 @@ public class CapacitorUpdater {
405
416
  }
406
417
  }
407
418
 
419
+ private void safeDelete(final File target) {
420
+ if (target == null || !target.exists()) {
421
+ return;
422
+ }
423
+ try {
424
+ if (target.isDirectory()) {
425
+ this.deleteDirectory(target);
426
+ } else if (!target.delete()) {
427
+ Log.w(TAG, "Failed to delete file: " + target.getAbsolutePath());
428
+ }
429
+ } catch (IOException cleanupError) {
430
+ Log.w(TAG, "Cleanup failed for " + target.getAbsolutePath() + ": " + cleanupError.getMessage());
431
+ }
432
+ }
433
+
408
434
  private void setCurrentBundle(final File bundle) {
409
435
  this.editor.putString(WebView.CAP_SERVER_PATH, bundle.getPath());
410
436
  Log.i(TAG, "Current bundle set to: " + bundle);
@@ -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.23";
60
+ private final String PLUGIN_VERSION = "6.14.25";
61
61
  private static final String DELAY_CONDITION_PREFERENCES = "";
62
62
 
63
63
  private SharedPreferences.Editor editor;
@@ -1002,6 +1002,17 @@ public class CapacitorUpdaterPlugin extends Plugin {
1002
1002
  }
1003
1003
 
1004
1004
  private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
1005
+ endBackGroundTaskWithNotif(msg, latestVersionName, current, error, "download_fail", "downloadFailed");
1006
+ }
1007
+
1008
+ private void endBackGroundTaskWithNotif(
1009
+ String msg,
1010
+ String latestVersionName,
1011
+ BundleInfo current,
1012
+ Boolean error,
1013
+ String failureAction,
1014
+ String failureEvent
1015
+ ) {
1005
1016
  if (error) {
1006
1017
  Log.i(
1007
1018
  CapacitorUpdater.TAG,
@@ -1012,10 +1023,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
1012
1023
  "latestVersionName: " +
1013
1024
  latestVersionName
1014
1025
  );
1015
- this.implementation.sendStats("download_fail", current.getVersionName());
1026
+ this.implementation.sendStats(failureAction, current.getVersionName());
1016
1027
  final JSObject ret = new JSObject();
1017
1028
  ret.put("version", latestVersionName);
1018
- this.notifyListeners("downloadFailed", ret);
1029
+ this.notifyListeners(failureEvent, ret);
1019
1030
  }
1020
1031
  final JSObject ret = new JSObject();
1021
1032
  ret.put("bundle", current.toJSON());
@@ -1034,6 +1045,34 @@ public class CapacitorUpdaterPlugin extends Plugin {
1034
1045
  CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
1035
1046
  final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
1036
1047
  try {
1048
+ if (res.has("error")) {
1049
+ final String error = res.optString("error", "");
1050
+ if (error != null && !error.isEmpty()) {
1051
+ Log.e(CapacitorUpdater.TAG, "getLatest failed with error: " + error);
1052
+ final String latestVersion = res.has("version")
1053
+ ? res.optString("version", current.getVersionName())
1054
+ : current.getVersionName();
1055
+ if ("response_error".equals(error)) {
1056
+ CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
1057
+ "Network error: " + error,
1058
+ latestVersion,
1059
+ current,
1060
+ true
1061
+ );
1062
+ } else {
1063
+ CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
1064
+ error,
1065
+ latestVersion,
1066
+ current,
1067
+ true,
1068
+ "backend_refusal",
1069
+ "backendRefused"
1070
+ );
1071
+ }
1072
+ return;
1073
+ }
1074
+ }
1075
+
1037
1076
  if (res.has("message")) {
1038
1077
  Log.i(CapacitorUpdater.TAG, "API message: " + res.get("message"));
1039
1078
  if (res.has("major") && res.getBoolean("major") && res.has("version")) {
@@ -1041,11 +1080,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
1041
1080
  majorAvailable.put("version", res.getString("version"));
1042
1081
  CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", majorAvailable);
1043
1082
  }
1083
+ final String latestVersion = res.has("version")
1084
+ ? res.optString("version", current.getVersionName())
1085
+ : current.getVersionName();
1044
1086
  CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
1045
1087
  res.getString("message"),
1046
- current.getVersionName(),
1088
+ latestVersion,
1047
1089
  current,
1048
- true
1090
+ true,
1091
+ "backend_refusal",
1092
+ "backendRefused"
1049
1093
  );
1050
1094
  return;
1051
1095
  }
@@ -27,7 +27,7 @@ struct LocalizedString: ExpressibleByStringLiteral, Equatable {
27
27
  }
28
28
  }
29
29
 
30
- func ==(lhs: LocalizedString, rhs: LocalizedString) -> Bool {
30
+ func == (lhs: LocalizedString, rhs: LocalizedString) -> Bool {
31
31
  return lhs.v == rhs.v
32
32
  }
33
33
 
@@ -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.23"
48
+ private let PLUGIN_VERSION: String = "6.14.25"
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"
@@ -732,10 +732,17 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
732
732
  }
733
733
  }
734
734
 
735
- func endBackGroundTaskWithNotif(msg: String, latestVersionName: String, current: BundleInfo, error: Bool = true) {
735
+ func endBackGroundTaskWithNotif(
736
+ msg: String,
737
+ latestVersionName: String,
738
+ current: BundleInfo,
739
+ error: Bool = true,
740
+ failureAction: String = "download_fail",
741
+ failureEvent: String = "downloadFailed"
742
+ ) {
736
743
  if error {
737
- self.implementation.sendStats(action: "download_fail", versionName: current.getVersionName())
738
- self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
744
+ self.implementation.sendStats(action: failureAction, versionName: current.getVersionName())
745
+ self.notifyListeners(failureEvent, data: ["version": latestVersionName])
739
746
  }
740
747
  self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
741
748
  self.sendReadyToJs(current: current, msg: msg)
@@ -758,12 +765,43 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
758
765
  let res = self.implementation.getLatest(url: url, channel: nil)
759
766
  let current = self.implementation.getCurrentBundle()
760
767
 
761
- if (res.message) != nil {
762
- print("\(CapacitorUpdater.TAG) API message: \(res.message ?? "")")
768
+ if let backendError = res.error, !backendError.isEmpty {
769
+ print("\(CapacitorUpdater.TAG) getLatest failed with error: \(backendError)")
770
+ let latestVersionName = res.version.isEmpty ? current.getVersionName() : res.version
771
+ if backendError == "response_error" {
772
+ self.endBackGroundTaskWithNotif(
773
+ msg: "Network error: \(backendError)",
774
+ latestVersionName: latestVersionName,
775
+ current: current,
776
+ error: true
777
+ )
778
+ } else {
779
+ self.endBackGroundTaskWithNotif(
780
+ msg: backendError,
781
+ latestVersionName: latestVersionName,
782
+ current: current,
783
+ error: true,
784
+ failureAction: "backend_refusal",
785
+ failureEvent: "backendRefused"
786
+ )
787
+ }
788
+ return
789
+ }
790
+
791
+ if let message = res.message, !message.isEmpty {
792
+ print("\(CapacitorUpdater.TAG) API message: \(message)")
763
793
  if res.major == true {
764
794
  self.notifyListeners("majorAvailable", data: ["version": res.version])
765
795
  }
766
- self.endBackGroundTaskWithNotif(msg: res.message ?? "", latestVersionName: res.version, current: current, error: true)
796
+ let latestVersionName = res.version.isEmpty ? current.getVersionName() : res.version
797
+ self.endBackGroundTaskWithNotif(
798
+ msg: message,
799
+ latestVersionName: latestVersionName,
800
+ current: current,
801
+ error: true,
802
+ failureAction: "backend_refusal",
803
+ failureEvent: "backendRefused"
804
+ )
767
805
  return
768
806
  }
769
807
  if res.version == "builtin" {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "6.14.23",
3
+ "version": "6.14.25",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",