@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.
|
|
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
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
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
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
)
|
|
827
|
+
res.has("major") &&
|
|
828
|
+
res.getBoolean("major") &&
|
|
829
|
+
res.has("version")
|
|
854
830
|
) {
|
|
855
|
-
|
|
856
|
-
|
|
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
|
-
"
|
|
863
|
-
|
|
834
|
+
"majorAvailable",
|
|
835
|
+
majorAvailable
|
|
864
836
|
);
|
|
865
837
|
}
|
|
866
|
-
final
|
|
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
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
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
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
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
|
-
|
|
897
|
-
|
|
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
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
latest.
|
|
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
|
-
|
|
926
|
-
Log.e(
|
|
913
|
+
if (deleted) {
|
|
914
|
+
Log.i(
|
|
927
915
|
CapacitorUpdater.TAG,
|
|
928
|
-
"Failed
|
|
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
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
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
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
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
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
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
|
-
"
|
|
1004
|
-
|
|
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
|
-
"
|
|
970
|
+
"checksum_fail",
|
|
1016
971
|
current.getVersionName()
|
|
1017
972
|
);
|
|
1018
|
-
final
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
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
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
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
|
-
|
|
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
|
|
469
|
+
func endBackGroundTask() {
|
|
470
470
|
UIApplication.shared.endBackgroundTask(self.backgroundTaskID)
|
|
471
471
|
self.backgroundTaskID = UIBackgroundTaskIdentifier.invalid
|
|
472
472
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
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.
|
|
548
|
-
|
|
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
|
-
|
|
557
|
-
|
|
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() {
|