@capgo/capacitor-updater 4.3.7 → 4.4.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.
@@ -45,7 +45,7 @@ public class CapacitorUpdater {
45
45
  private static final String bundleDirectory = "versions";
46
46
 
47
47
  public static final String TAG = "Capacitor-updater";
48
- public static final String pluginVersion = "4.3.7";
48
+ public static final String pluginVersion = "4.4.0";
49
49
 
50
50
  public SharedPreferences.Editor editor;
51
51
  public SharedPreferences prefs;
@@ -357,7 +357,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
357
357
  }
358
358
  call.resolve(ret);
359
359
  }
360
- );
360
+ );
361
361
  }
362
362
  }
363
363
  );
@@ -619,11 +619,11 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
619
619
 
620
620
  if (
621
621
  latestVersionName != null &&
622
- !"".equals(latestVersionName) &&
623
- !current.getVersionName().equals(latestVersionName)
622
+ !"".equals(latestVersionName) &&
623
+ !current.getVersionName().equals(latestVersionName)
624
624
  ) {
625
625
  final BundleInfo latest =
626
- CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(latestVersionName);
626
+ CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(latestVersionName);
627
627
  if (latest != null) {
628
628
  if (latest.isErrorStatus()) {
629
629
  Log.e(
@@ -648,16 +648,24 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
648
648
  }
649
649
  if (latest.isDeleted()) {
650
650
  Log.i(
651
- CapacitorUpdater.TAG,
652
- "Latest bundle already exists and will be deleted, download will overwrite it."
651
+ CapacitorUpdater.TAG,
652
+ "Latest bundle already exists and will be deleted, download will overwrite it."
653
653
  );
654
654
  try {
655
- final Boolean deleted = CapacitorUpdaterPlugin.this.implementation.delete(latest.getId(), true);
655
+ final Boolean deleted =
656
+ CapacitorUpdaterPlugin.this.implementation.delete(latest.getId(), true);
656
657
  if (deleted) {
657
- Log.i(CapacitorUpdater.TAG, "Failed bundle deleted: " + latest.getVersionName());
658
+ Log.i(
659
+ CapacitorUpdater.TAG,
660
+ "Failed bundle deleted: " + latest.getVersionName()
661
+ );
658
662
  }
659
663
  } catch (final IOException e) {
660
- Log.e(CapacitorUpdater.TAG, "Failed to delete failed bundle: " + latest.getVersionName(), e);
664
+ Log.e(
665
+ CapacitorUpdater.TAG,
666
+ "Failed to delete failed bundle: " + latest.getVersionName(),
667
+ e
668
+ );
661
669
  }
662
670
  }
663
671
  }
@@ -679,6 +687,22 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
679
687
  final String url = (String) res.get("url");
680
688
  final BundleInfo next =
681
689
  CapacitorUpdaterPlugin.this.implementation.download(url, latestVersionName);
690
+ final String checksum = (String) res.get("checksum");
691
+ if (!checksum.equals("") && next.getChecksum() != checksum) {
692
+ Log.e(
693
+ CapacitorUpdater.TAG,
694
+ "Error checksum " + next.getChecksum() + " " + checksum
695
+ );
696
+ final Boolean res =
697
+ CapacitorUpdaterPlugin.this.implementation.delete(next.getId());
698
+ if (res) {
699
+ Log.i(
700
+ CapacitorUpdater.TAG,
701
+ "Failed bundle deleted: " + next.getVersionName()
702
+ );
703
+ }
704
+ return;
705
+ }
682
706
  final JSObject ret = new JSObject();
683
707
  ret.put("bundle", next.toJSON());
684
708
  CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
@@ -709,7 +733,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
709
733
  CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
710
734
  }
711
735
  }
712
- );
736
+ );
713
737
  }
714
738
  }
715
739
  )
@@ -737,10 +761,11 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
737
761
  if (backgroundValue != null) {
738
762
  taskRunning = true;
739
763
  final Long timeout = Long.parseLong(backgroundValue);
740
- if(backgroundTask != null) {
764
+ if (backgroundTask != null) {
741
765
  backgroundTask.interrupt();
742
766
  }
743
- backgroundTask = new Thread(
767
+ backgroundTask =
768
+ new Thread(
744
769
  new Runnable() {
745
770
  @Override
746
771
  public void run() {
@@ -754,7 +779,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
754
779
  }
755
780
  }
756
781
  }
757
- );
782
+ );
758
783
  backgroundTask.start();
759
784
  } else {
760
785
  this._checkCancelDelay(false);
@@ -834,8 +859,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
834
859
  public void run() {
835
860
  try {
836
861
  Log.i(
837
- CapacitorUpdater.TAG,
838
- "Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady"
862
+ CapacitorUpdater.TAG,
863
+ "Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady"
839
864
  );
840
865
  Thread.sleep(CapacitorUpdaterPlugin.this.appReadyTimeout);
841
866
  CapacitorUpdaterPlugin.this.checkRevert();
@@ -18,12 +18,14 @@ extension Date {
18
18
  }
19
19
  struct AppVersionDec: Decodable {
20
20
  let version: String?
21
+ let checksum: String?
21
22
  let url: String?
22
23
  let message: String?
23
24
  let major: Bool?
24
25
  }
25
26
  public class AppVersion: NSObject {
26
27
  var version: String = ""
28
+ var checksum: String = ""
27
29
  var url: String = ""
28
30
  var message: String?
29
31
  var major: Bool?
@@ -146,7 +148,7 @@ extension CustomError: LocalizedError {
146
148
 
147
149
  public let TAG = "✨ Capacitor-updater:"
148
150
  public let CAP_SERVER_PATH = "serverBasePath"
149
- public let pluginVersion = "4.3.7"
151
+ public let pluginVersion = "4.4.0"
150
152
  public var statsUrl = ""
151
153
  public var appId = ""
152
154
  public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
@@ -248,6 +250,9 @@ extension CustomError: LocalizedError {
248
250
  if let url = response.value?.url {
249
251
  latest.url = url
250
252
  }
253
+ if let checksum = response.value?.checksum {
254
+ latest.checksum = checksum
255
+ }
251
256
  if let version = response.value?.version {
252
257
  latest.version = version
253
258
  }
@@ -67,7 +67,10 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
67
67
  let res = implementation.list()
68
68
  res.forEach { version in
69
69
  print("\(self.implementation.TAG) Deleting obsolete bundle: \(version)")
70
- _ = implementation.delete(id: version.getId())
70
+ let res = implementation.delete(id: version.getId())
71
+ if !res {
72
+ print("\(self.implementation.TAG) Delete failed, id \(version.getId()) doesn't exist")
73
+ }
71
74
  }
72
75
  }
73
76
  UserDefaults.standard.set( self.currentVersionNative.description, forKey: "LatestVersionNative")
@@ -465,6 +468,14 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
465
468
  do {
466
469
  print("\(self.implementation.TAG) New bundle: \(latestVersionName) found. Current is: \(current.getVersionName()). Update will occur next time app moves to background.")
467
470
  let next = try self.implementation.download(url: downloadUrl, version: latestVersionName)
471
+ if res.checksum != "" && next.getChecksum() != res.checksum {
472
+ print("\(self.implementation.TAG) Error checksum", next.getChecksum(), res.checksum)
473
+ let resDel = self.implementation.delete(id: next.getId())
474
+ if !resDel {
475
+ print("\(self.implementation.TAG) Delete failed, id \(next.getId()) doesn't exist")
476
+ }
477
+ return
478
+ }
468
479
  self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
469
480
  _ = self.implementation.setNextBundle(next: next.getId())
470
481
  } catch {
@@ -515,8 +526,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
515
526
  }
516
527
 
517
528
  }
518
-
519
- @objc func appKilled(){
529
+
530
+ @objc func appKilled() {
520
531
  self._checkCancelDelay(killed: true)
521
532
  }
522
533
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.3.7",
3
+ "version": "4.4.0",
4
4
  "license": "LGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",