@capgo/capacitor-updater 4.13.7 → 4.13.8

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.
@@ -54,7 +54,7 @@ public class CapacitorUpdater {
54
54
  private static final String bundleDirectory = "versions";
55
55
 
56
56
  public static final String TAG = "Capacitor-updater";
57
- public static final String pluginVersion = "4.13.7";
57
+ public static final String pluginVersion = "4.13.8";
58
58
 
59
59
  public SharedPreferences.Editor editor;
60
60
  public SharedPreferences prefs;
@@ -803,245 +803,231 @@ public class CapacitorUpdaterPlugin
803
803
  }
804
804
  }
805
805
 
806
- @Override // appMovedToForeground
807
- public void onActivityStarted(@NonNull final Activity activity) {
808
- if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled()) {
809
- new Thread(
810
- new Runnable() {
811
- @Override
812
- public void run() {
813
- Log.i(
814
- CapacitorUpdater.TAG,
815
- "Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl
816
- );
817
- CapacitorUpdaterPlugin.this.implementation.getLatest(
818
- CapacitorUpdaterPlugin.this.updateUrl,
819
- res -> {
820
- final BundleInfo current =
821
- CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
822
- try {
823
- if (res.has("message")) {
824
- Log.i(
825
- CapacitorUpdater.TAG,
826
- "message " + res.get("message")
827
- );
828
- if (
829
- res.has("major") &&
830
- res.getBoolean("major") &&
831
- res.has("version")
832
- ) {
833
- final JSObject majorAvailable = new JSObject();
834
- majorAvailable.put("version", res.getString("version"));
835
- CapacitorUpdaterPlugin.this.notifyListeners(
836
- "majorAvailable",
837
- majorAvailable
838
- );
839
- }
840
- final JSObject retNoNeed = new JSObject();
841
- retNoNeed.put("bundle", current.toJSON());
842
- CapacitorUpdaterPlugin.this.notifyListeners(
843
- "noNeedUpdate",
844
- retNoNeed
845
- );
846
- return;
847
- }
848
-
806
+ private void backgroundDownload() {
807
+ new Thread(
808
+ new Runnable() {
809
+ @Override
810
+ public void run() {
811
+ Log.i(
812
+ CapacitorUpdater.TAG,
813
+ "Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl
814
+ );
815
+ CapacitorUpdaterPlugin.this.implementation.getLatest(
816
+ CapacitorUpdaterPlugin.this.updateUrl,
817
+ res -> {
818
+ final BundleInfo current =
819
+ CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
820
+ try {
821
+ if (res.has("message")) {
822
+ Log.i(
823
+ CapacitorUpdater.TAG,
824
+ "message " + res.get("message")
825
+ );
849
826
  if (
850
- !res.has("url") ||
851
- !CapacitorUpdaterPlugin.this.isValidURL(
852
- res.getString("url")
853
- )
827
+ res.has("major") &&
828
+ res.getBoolean("major") &&
829
+ res.has("version")
854
830
  ) {
855
- Log.e(
856
- CapacitorUpdater.TAG,
857
- "Error no url or wrong format"
858
- );
859
- final JSObject retNoNeed = new JSObject();
860
- retNoNeed.put("bundle", current.toJSON());
831
+ final JSObject majorAvailable = new JSObject();
832
+ majorAvailable.put("version", res.getString("version"));
861
833
  CapacitorUpdaterPlugin.this.notifyListeners(
862
- "noNeedUpdate",
863
- retNoNeed
834
+ "majorAvailable",
835
+ majorAvailable
864
836
  );
865
837
  }
866
- final String latestVersionName = res.getString("version");
838
+ final JSObject retNoNeed = new JSObject();
839
+ retNoNeed.put("bundle", current.toJSON());
840
+ CapacitorUpdaterPlugin.this.notifyListeners(
841
+ "noNeedUpdate",
842
+ retNoNeed
843
+ );
844
+ return;
845
+ }
867
846
 
868
- if (
869
- latestVersionName != null &&
870
- !"".equals(latestVersionName) &&
871
- !current.getVersionName().equals(latestVersionName)
872
- ) {
873
- final BundleInfo latest =
874
- CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(
875
- latestVersionName
876
- );
877
- if (latest != null) {
878
- if (latest.isErrorStatus()) {
879
- Log.e(
880
- CapacitorUpdater.TAG,
881
- "Latest bundle already exists, and is in error state. Aborting update."
847
+ if (
848
+ !res.has("url") ||
849
+ !CapacitorUpdaterPlugin.this.isValidURL(
850
+ res.getString("url")
851
+ )
852
+ ) {
853
+ Log.e(CapacitorUpdater.TAG, "Error no url or wrong format");
854
+ final JSObject retNoNeed = new JSObject();
855
+ retNoNeed.put("bundle", current.toJSON());
856
+ CapacitorUpdaterPlugin.this.notifyListeners(
857
+ "noNeedUpdate",
858
+ retNoNeed
859
+ );
860
+ }
861
+ final String latestVersionName = res.getString("version");
862
+
863
+ if (
864
+ latestVersionName != null &&
865
+ !"".equals(latestVersionName) &&
866
+ !current.getVersionName().equals(latestVersionName)
867
+ ) {
868
+ final BundleInfo latest =
869
+ CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(
870
+ latestVersionName
871
+ );
872
+ if (latest != null) {
873
+ if (latest.isErrorStatus()) {
874
+ Log.e(
875
+ CapacitorUpdater.TAG,
876
+ "Latest bundle already exists, and is in error state. Aborting update."
877
+ );
878
+ final JSObject retNoNeed = new JSObject();
879
+ retNoNeed.put("bundle", current.toJSON());
880
+ CapacitorUpdaterPlugin.this.notifyListeners(
881
+ "noNeedUpdate",
882
+ retNoNeed
882
883
  );
883
- final JSObject retNoNeed = new JSObject();
884
- retNoNeed.put("bundle", current.toJSON());
885
- CapacitorUpdaterPlugin.this.notifyListeners(
886
- "noNeedUpdate",
887
- retNoNeed
888
- );
889
- return;
890
- }
891
- if (latest.isDownloaded()) {
892
- Log.i(
893
- CapacitorUpdater.TAG,
894
- "Latest bundle already exists and download is NOT required. Update will occur next time app moves to background."
884
+ return;
885
+ }
886
+ if (latest.isDownloaded()) {
887
+ Log.i(
888
+ CapacitorUpdater.TAG,
889
+ "Latest bundle already exists and download is NOT required. Update will occur next time app moves to background."
890
+ );
891
+ final JSObject ret = new JSObject();
892
+ ret.put("bundle", latest.toJSON());
893
+ CapacitorUpdaterPlugin.this.notifyListeners(
894
+ "updateAvailable",
895
+ ret
895
896
  );
896
- final JSObject ret = new JSObject();
897
- ret.put("bundle", latest.toJSON());
898
- CapacitorUpdaterPlugin.this.notifyListeners(
899
- "updateAvailable",
900
- ret
901
- );
902
- CapacitorUpdaterPlugin.this.implementation.setNextBundle(
903
- latest.getId()
904
- );
905
- return;
906
- }
907
- if (latest.isDeleted()) {
908
- Log.i(
909
- CapacitorUpdater.TAG,
910
- "Latest bundle already exists and will be deleted, download will overwrite it."
897
+ CapacitorUpdaterPlugin.this.implementation.setNextBundle(
898
+ latest.getId()
911
899
  );
912
- try {
913
- final Boolean deleted =
914
- CapacitorUpdaterPlugin.this.implementation.delete(
915
- latest.getId(),
916
- true
917
- );
918
- if (deleted) {
919
- Log.i(
920
- CapacitorUpdater.TAG,
921
- "Failed bundle deleted: " +
922
- latest.getVersionName()
900
+ return;
901
+ }
902
+ if (latest.isDeleted()) {
903
+ Log.i(
904
+ CapacitorUpdater.TAG,
905
+ "Latest bundle already exists and will be deleted, download will overwrite it."
906
+ );
907
+ try {
908
+ final Boolean deleted =
909
+ CapacitorUpdaterPlugin.this.implementation.delete(
910
+ latest.getId(),
911
+ true
923
912
  );
924
- }
925
- } catch (final IOException e) {
926
- Log.e(
913
+ if (deleted) {
914
+ Log.i(
927
915
  CapacitorUpdater.TAG,
928
- "Failed to delete failed bundle: " +
929
- latest.getVersionName(),
930
- e
916
+ "Failed bundle deleted: " +
917
+ latest.getVersionName()
931
918
  );
932
919
  }
920
+ } catch (final IOException e) {
921
+ Log.e(
922
+ CapacitorUpdater.TAG,
923
+ "Failed to delete failed bundle: " +
924
+ latest.getVersionName(),
925
+ e
926
+ );
933
927
  }
934
928
  }
929
+ }
935
930
 
936
- new Thread(
937
- new Runnable() {
938
- @Override
939
- public void run() {
940
- try {
941
- Log.i(
942
- CapacitorUpdater.TAG,
943
- "New bundle: " +
944
- latestVersionName +
945
- " found. Current is: " +
946
- current.getVersionName() +
947
- ". Update will occur next time app moves to background."
948
- );
931
+ new Thread(
932
+ new Runnable() {
933
+ @Override
934
+ public void run() {
935
+ try {
936
+ Log.i(
937
+ CapacitorUpdater.TAG,
938
+ "New bundle: " +
939
+ latestVersionName +
940
+ " found. Current is: " +
941
+ current.getVersionName() +
942
+ ". Update will occur next time app moves to background."
943
+ );
949
944
 
950
- final String url = res.getString("url");
951
- final String session_key = res.has("session_key")
952
- ? res.getString("session_key")
953
- : "";
954
- final BundleInfo next =
955
- CapacitorUpdaterPlugin.this.implementation.download(
956
- url,
957
- latestVersionName,
958
- session_key
959
- );
960
- final String checksum = res.has("checksum")
961
- ? res.getString("checksum")
962
- : "";
963
- if (
964
- !checksum.equals("") &&
965
- !next.getChecksum().equals(checksum)
966
- ) {
967
- Log.e(
968
- CapacitorUpdater.TAG,
969
- "Error checksum " +
970
- next.getChecksum() +
971
- " " +
972
- checksum
945
+ final String url = res.getString("url");
946
+ final String session_key = res.has("session_key")
947
+ ? res.getString("session_key")
948
+ : "";
949
+ final BundleInfo next =
950
+ CapacitorUpdaterPlugin.this.implementation.download(
951
+ url,
952
+ latestVersionName,
953
+ session_key
973
954
  );
974
- CapacitorUpdaterPlugin.this.implementation.sendStats(
975
- "checksum_fail",
976
- current.getVersionName()
977
- );
978
- final Boolean res =
979
- CapacitorUpdaterPlugin.this.implementation.delete(
980
- next.getId()
981
- );
982
- if (res) {
983
- Log.i(
984
- CapacitorUpdater.TAG,
985
- "Failed bundle deleted: " +
986
- next.getVersionName()
987
- );
988
- }
989
- return;
990
- }
991
- final JSObject ret = new JSObject();
992
- ret.put("bundle", next.toJSON());
993
- CapacitorUpdaterPlugin.this.notifyListeners(
994
- "updateAvailable",
995
- ret
996
- );
997
- CapacitorUpdaterPlugin.this.implementation.setNextBundle(
998
- next.getId()
999
- );
1000
- } catch (final Exception e) {
955
+ final String checksum = res.has("checksum")
956
+ ? res.getString("checksum")
957
+ : "";
958
+ if (
959
+ !checksum.equals("") &&
960
+ !next.getChecksum().equals(checksum)
961
+ ) {
1001
962
  Log.e(
1002
963
  CapacitorUpdater.TAG,
1003
- "error downloading file",
1004
- e
964
+ "Error checksum " +
965
+ next.getChecksum() +
966
+ " " +
967
+ checksum
1005
968
  );
1006
- final JSObject ret = new JSObject();
1007
- ret.put("version", latestVersionName);
1008
- CapacitorUpdaterPlugin.this.notifyListeners(
1009
- "downloadFailed",
1010
- ret
1011
- );
1012
- final BundleInfo current =
1013
- CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
1014
969
  CapacitorUpdaterPlugin.this.implementation.sendStats(
1015
- "download_fail",
970
+ "checksum_fail",
1016
971
  current.getVersionName()
1017
972
  );
1018
- final JSObject retNoNeed = new JSObject();
1019
- retNoNeed.put("bundle", current.toJSON());
1020
- CapacitorUpdaterPlugin.this.notifyListeners(
1021
- "noNeedUpdate",
1022
- retNoNeed
973
+ final Boolean res =
974
+ CapacitorUpdaterPlugin.this.implementation.delete(
975
+ next.getId()
976
+ );
977
+ if (res) {
978
+ Log.i(
979
+ CapacitorUpdater.TAG,
980
+ "Failed bundle deleted: " +
981
+ next.getVersionName()
1023
982
  );
983
+ }
984
+ return;
1024
985
  }
986
+ final JSObject ret = new JSObject();
987
+ ret.put("bundle", next.toJSON());
988
+ CapacitorUpdaterPlugin.this.notifyListeners(
989
+ "updateAvailable",
990
+ ret
991
+ );
992
+ CapacitorUpdaterPlugin.this.implementation.setNextBundle(
993
+ next.getId()
994
+ );
995
+ } catch (final Exception e) {
996
+ Log.e(
997
+ CapacitorUpdater.TAG,
998
+ "error downloading file",
999
+ e
1000
+ );
1001
+ final JSObject ret = new JSObject();
1002
+ ret.put("version", latestVersionName);
1003
+ CapacitorUpdaterPlugin.this.notifyListeners(
1004
+ "downloadFailed",
1005
+ ret
1006
+ );
1007
+ final BundleInfo current =
1008
+ CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
1009
+ CapacitorUpdaterPlugin.this.implementation.sendStats(
1010
+ "download_fail",
1011
+ current.getVersionName()
1012
+ );
1013
+ final JSObject retNoNeed = new JSObject();
1014
+ retNoNeed.put("bundle", current.toJSON());
1015
+ CapacitorUpdaterPlugin.this.notifyListeners(
1016
+ "noNeedUpdate",
1017
+ retNoNeed
1018
+ );
1025
1019
  }
1026
1020
  }
1027
- )
1028
- .start();
1029
- } else {
1030
- Log.i(
1031
- CapacitorUpdater.TAG,
1032
- "No need to update, " +
1033
- current.getId() +
1034
- " is the latest bundle."
1035
- );
1036
- final JSObject retNoNeed = new JSObject();
1037
- retNoNeed.put("bundle", current.toJSON());
1038
- CapacitorUpdaterPlugin.this.notifyListeners(
1039
- "noNeedUpdate",
1040
- retNoNeed
1041
- );
1042
- }
1043
- } catch (final JSONException e) {
1044
- Log.e(CapacitorUpdater.TAG, "error parsing JSON", e);
1021
+ }
1022
+ )
1023
+ .start();
1024
+ } else {
1025
+ Log.i(
1026
+ CapacitorUpdater.TAG,
1027
+ "No need to update, " +
1028
+ current.getId() +
1029
+ " is the latest bundle."
1030
+ );
1045
1031
  final JSObject retNoNeed = new JSObject();
1046
1032
  retNoNeed.put("bundle", current.toJSON());
1047
1033
  CapacitorUpdaterPlugin.this.notifyListeners(
@@ -1049,14 +1035,28 @@ public class CapacitorUpdaterPlugin
1049
1035
  retNoNeed
1050
1036
  );
1051
1037
  }
1038
+ } catch (final JSONException e) {
1039
+ Log.e(CapacitorUpdater.TAG, "error parsing JSON", e);
1040
+ final JSObject retNoNeed = new JSObject();
1041
+ retNoNeed.put("bundle", current.toJSON());
1042
+ CapacitorUpdaterPlugin.this.notifyListeners(
1043
+ "noNeedUpdate",
1044
+ retNoNeed
1045
+ );
1052
1046
  }
1053
- );
1054
- }
1047
+ }
1048
+ );
1055
1049
  }
1056
- )
1057
- .start();
1058
- }
1050
+ }
1051
+ )
1052
+ .start();
1053
+ }
1059
1054
 
1055
+ @Override // appMovedToForeground
1056
+ public void onActivityStarted(@NonNull final Activity activity) {
1057
+ if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled()) {
1058
+ this.backgroundDownload();
1059
+ }
1060
1060
  this.checkAppReady();
1061
1061
  }
1062
1062
 
@@ -466,101 +466,105 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
466
466
  self.appReadyCheck = nil
467
467
  }
468
468
 
469
- func EndBackGroundTask() {
469
+ func endBackGroundTask() {
470
470
  UIApplication.shared.endBackgroundTask(self.backgroundTaskID)
471
471
  self.backgroundTaskID = UIBackgroundTaskIdentifier.invalid
472
472
  }
473
- @objc func appMovedToForeground() {
474
- if backgroundWork != nil && taskRunning {
475
- backgroundWork!.cancel()
476
- print("\(self.implementation.TAG) Background Timer Task canceled, Activity resumed before timer completes")
477
- }
478
- if self._isAutoUpdateEnabled() {
479
- DispatchQueue.global(qos: .background).async {
480
- self.backgroundTaskID = UIApplication.shared.beginBackgroundTask(withName: "Finish Download Tasks") {
481
- // End the task if time expires.
482
- UIApplication.shared.endBackgroundTask(self.backgroundTaskID)
483
- self.backgroundTaskID = UIBackgroundTaskIdentifier.invalid
473
+
474
+ func backgroundDownload() {
475
+ DispatchQueue.global(qos: .background).async {
476
+ self.backgroundTaskID = UIApplication.shared.beginBackgroundTask(withName: "Finish Download Tasks") {
477
+ // End the task if time expires.
478
+ self.endBackGroundTask()
479
+ }
480
+ print("\(self.implementation.TAG) Check for update via \(self.updateUrl)")
481
+ let url = URL(string: self.updateUrl)!
482
+ let res = self.implementation.getLatest(url: url)
483
+ let current = self.implementation.getCurrentBundle()
484
+
485
+ if (res.message) != nil {
486
+ print("\(self.implementation.TAG) message \(res.message ?? "")")
487
+ if res.major == true {
488
+ self.notifyListeners("majorAvailable", data: ["version": res.version])
484
489
  }
485
- print("\(self.implementation.TAG) Check for update via \(self.updateUrl)")
486
- let url = URL(string: self.updateUrl)!
487
- let res = self.implementation.getLatest(url: url)
488
- let current = self.implementation.getCurrentBundle()
489
-
490
- if (res.message) != nil {
491
- print("\(self.implementation.TAG) message \(res.message ?? "")")
492
- if res.major == true {
493
- self.notifyListeners("majorAvailable", data: ["version": res.version])
490
+ self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
491
+ self.endBackGroundTask()
492
+ return
493
+ }
494
+ let sessionKey = res.sessionKey ?? ""
495
+ guard let downloadUrl = URL(string: res.url) else {
496
+ print("\(self.implementation.TAG) Error no url or wrong format")
497
+ self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
498
+ self.endBackGroundTask()
499
+ return
500
+ }
501
+ let latestVersionName = res.version
502
+ if latestVersionName != "" && current.getVersionName() != latestVersionName {
503
+ let latest = self.implementation.getBundleInfoByVersionName(version: latestVersionName)
504
+ if latest != nil {
505
+ if latest!.isErrorStatus() {
506
+ print("\(self.implementation.TAG) Latest version already exists, and is in error state. Aborting update.")
507
+ self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
508
+ self.endBackGroundTask()
509
+ return
494
510
  }
495
- self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
496
- self.EndBackGroundTask()
497
- return
498
- }
499
- let sessionKey = res.sessionKey ?? ""
500
- guard let downloadUrl = URL(string: res.url) else {
501
- print("\(self.implementation.TAG) Error no url or wrong format")
502
- self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
503
- self.EndBackGroundTask()
504
- return
505
- }
506
- let latestVersionName = res.version
507
- if latestVersionName != "" && current.getVersionName() != latestVersionName {
508
- let latest = self.implementation.getBundleInfoByVersionName(version: latestVersionName)
509
- if latest != nil {
510
- if latest!.isErrorStatus() {
511
- print("\(self.implementation.TAG) Latest version already exists, and is in error state. Aborting update.")
512
- self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
513
- self.EndBackGroundTask()
514
- return
515
- }
516
- if latest!.isDownloaded() {
517
- print("\(self.implementation.TAG) Latest version already exists and download is NOT required. Update will occur next time app moves to background.")
518
- self.notifyListeners("updateAvailable", data: ["bundle": current.toJSON()])
519
- _ = self.implementation.setNextBundle(next: latest!.getId())
520
- self.EndBackGroundTask()
521
- return
522
- }
523
- if latest!.isDeleted() {
524
- print("\(self.implementation.TAG) Latest bundle already exists and will be deleted, download will overwrite it.")
525
- let res = self.implementation.delete(id: latest!.getId(), removeInfo: true)
526
- if !res {
527
- print("\(self.implementation.TAG) Delete version deleted: \(latest!.toString())")
528
- } else {
529
- print("\(self.implementation.TAG) Failed to delete failed bundle: \(latest!.toString())")
530
- }
511
+ if latest!.isDownloaded() {
512
+ print("\(self.implementation.TAG) Latest version already exists and download is NOT required. Update will occur next time app moves to background.")
513
+ self.notifyListeners("updateAvailable", data: ["bundle": current.toJSON()])
514
+ _ = self.implementation.setNextBundle(next: latest!.getId())
515
+ self.endBackGroundTask()
516
+ return
517
+ }
518
+ if latest!.isDeleted() {
519
+ print("\(self.implementation.TAG) Latest bundle already exists and will be deleted, download will overwrite it.")
520
+ let res = self.implementation.delete(id: latest!.getId(), removeInfo: true)
521
+ if !res {
522
+ print("\(self.implementation.TAG) Delete version deleted: \(latest!.toString())")
523
+ } else {
524
+ print("\(self.implementation.TAG) Failed to delete failed bundle: \(latest!.toString())")
531
525
  }
532
526
  }
527
+ }
533
528
 
534
- do {
535
- print("\(self.implementation.TAG) New bundle: \(latestVersionName) found. Current is: \(current.getVersionName()). Update will occur next time app moves to background.")
536
- let next = try self.implementation.download(url: downloadUrl, version: latestVersionName, sessionKey: sessionKey)
537
- if res.checksum != "" && next.getChecksum() != res.checksum {
538
- print("\(self.implementation.TAG) Error checksum", next.getChecksum(), res.checksum)
539
- self.implementation.sendStats(action: "checksum_fail", versionName: next.getVersionName())
540
- let resDel = self.implementation.delete(id: next.getId())
541
- if !resDel {
542
- print("\(self.implementation.TAG) Delete failed, id \(next.getId()) doesn't exist")
543
- }
544
- self.EndBackGroundTask()
545
- return
529
+ do {
530
+ print("\(self.implementation.TAG) New bundle: \(latestVersionName) found. Current is: \(current.getVersionName()). Update will occur next time app moves to background.")
531
+ let next = try self.implementation.download(url: downloadUrl, version: latestVersionName, sessionKey: sessionKey)
532
+ if res.checksum != "" && next.getChecksum() != res.checksum {
533
+ print("\(self.implementation.TAG) Error checksum", next.getChecksum(), res.checksum)
534
+ self.implementation.sendStats(action: "checksum_fail", versionName: next.getVersionName())
535
+ let resDel = self.implementation.delete(id: next.getId())
536
+ if !resDel {
537
+ print("\(self.implementation.TAG) Delete failed, id \(next.getId()) doesn't exist")
546
538
  }
547
- self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
548
- _ = self.implementation.setNextBundle(next: next.getId())
549
- } catch {
550
- print("\(self.implementation.TAG) Error downloading file", error.localizedDescription)
551
- let current: BundleInfo = self.implementation.getCurrentBundle()
552
- self.implementation.sendStats(action: "download_fail", versionName: current.getVersionName())
553
- self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
554
- self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
539
+ self.endBackGroundTask()
540
+ return
555
541
  }
556
- } else {
557
- print("\(self.implementation.TAG) No need to update, \(current.getId()) is the latest bundle.")
542
+ self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
543
+ _ = self.implementation.setNextBundle(next: next.getId())
544
+ } catch {
545
+ print("\(self.implementation.TAG) Error downloading file", error.localizedDescription)
546
+ let current: BundleInfo = self.implementation.getCurrentBundle()
547
+ self.implementation.sendStats(action: "download_fail", versionName: current.getVersionName())
548
+ self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
558
549
  self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
559
550
  }
551
+ } else {
552
+ print("\(self.implementation.TAG) No need to update, \(current.getId()) is the latest bundle.")
553
+ self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
560
554
  }
555
+ self.endBackGroundTask()
556
+ }
557
+ }
558
+
559
+ @objc func appMovedToForeground() {
560
+ if backgroundWork != nil && taskRunning {
561
+ backgroundWork!.cancel()
562
+ print("\(self.implementation.TAG) Background Timer Task canceled, Activity resumed before timer completes")
563
+ }
564
+ if self._isAutoUpdateEnabled() {
565
+ self.backgroundDownload()
561
566
  }
562
567
  self.checkAppReady()
563
- self.EndBackGroundTask()
564
568
  }
565
569
 
566
570
  @objc func appMovedToBackground() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.13.7",
3
+ "version": "4.13.8",
4
4
  "license": "LGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",