@capgo/capacitor-updater 5.2.8 → 5.2.10
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.
package/README.md
CHANGED
|
@@ -757,6 +757,14 @@ Remove all listeners for this plugin.
|
|
|
757
757
|
| **`version`** | <code>string</code> | Emit when a download fail. | 4.0.0 |
|
|
758
758
|
|
|
759
759
|
|
|
760
|
+
#### AppReadyEvent
|
|
761
|
+
|
|
762
|
+
| Prop | Type | Description | Since |
|
|
763
|
+
| ------------ | ------------------------------------------------- | -------------------------------- | ----- |
|
|
764
|
+
| **`bundle`** | <code><a href="#bundleinfo">BundleInfo</a></code> | Emit when a app is ready to use. | 5.2.0 |
|
|
765
|
+
| **`status`** | <code>string</code> | | |
|
|
766
|
+
|
|
767
|
+
|
|
760
768
|
### Type Aliases
|
|
761
769
|
|
|
762
770
|
|
|
@@ -812,7 +820,7 @@ Remove all listeners for this plugin.
|
|
|
812
820
|
|
|
813
821
|
#### AppReadyListener
|
|
814
822
|
|
|
815
|
-
<code>(state:
|
|
823
|
+
<code>(state: <a href="#appreadyevent">AppReadyEvent</a>): void</code>
|
|
816
824
|
|
|
817
825
|
</docgen-api>
|
|
818
826
|
|
|
@@ -56,7 +56,7 @@ public class CapacitorUpdaterPlugin
|
|
|
56
56
|
private static final String channelUrlDefault =
|
|
57
57
|
"https://api.capgo.app/channel_self";
|
|
58
58
|
|
|
59
|
-
private final String PLUGIN_VERSION = "5.2.
|
|
59
|
+
private final String PLUGIN_VERSION = "5.2.10";
|
|
60
60
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
61
61
|
|
|
62
62
|
private SharedPreferences.Editor editor;
|
|
@@ -177,6 +177,7 @@ public class CapacitorUpdaterPlugin
|
|
|
177
177
|
private void directUpdateFinish(final BundleInfo latest) {
|
|
178
178
|
final JSObject ret = new JSObject();
|
|
179
179
|
ret.put("bundle", latest.toJSON());
|
|
180
|
+
ret.put("status", "update installed");
|
|
180
181
|
CapacitorUpdaterPlugin.this.implementation.set(latest);
|
|
181
182
|
CapacitorUpdaterPlugin.this._reload();
|
|
182
183
|
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
|
|
@@ -850,6 +851,26 @@ public class CapacitorUpdaterPlugin
|
|
|
850
851
|
}
|
|
851
852
|
}
|
|
852
853
|
|
|
854
|
+
private void endBackGroundTaskWithNotif(
|
|
855
|
+
String msg,
|
|
856
|
+
String latestVersionName,
|
|
857
|
+
BundleInfo current,
|
|
858
|
+
Boolean error
|
|
859
|
+
) {
|
|
860
|
+
if (error) {
|
|
861
|
+
this.implementation.sendStats("download_fail", current.getVersionName());
|
|
862
|
+
final JSObject ret = new JSObject();
|
|
863
|
+
ret.put("version", latestVersionName);
|
|
864
|
+
this.notifyListeners("downloadFailed", ret);
|
|
865
|
+
}
|
|
866
|
+
final JSObject ret = new JSObject();
|
|
867
|
+
ret.put("bundle", current.toJSON());
|
|
868
|
+
this.notifyListeners("noNeedUpdate", ret);
|
|
869
|
+
ret.put("message", msg);
|
|
870
|
+
this.notifyListeners("appReady", ret);
|
|
871
|
+
Log.i(CapacitorUpdater.TAG, "endBackGroundTaskWithNotif " + msg);
|
|
872
|
+
}
|
|
873
|
+
|
|
853
874
|
private void backgroundDownload() {
|
|
854
875
|
String messageUpdate = this.implementation.directUpdate
|
|
855
876
|
? "Update will occur now."
|
|
@@ -885,15 +906,11 @@ public class CapacitorUpdaterPlugin
|
|
|
885
906
|
majorAvailable
|
|
886
907
|
);
|
|
887
908
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
);
|
|
894
|
-
CapacitorUpdaterPlugin.this.notifyListeners(
|
|
895
|
-
"appReady",
|
|
896
|
-
retNoNeed
|
|
909
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
910
|
+
res.getString("message"),
|
|
911
|
+
current.getVersionName(),
|
|
912
|
+
current,
|
|
913
|
+
true
|
|
897
914
|
);
|
|
898
915
|
return;
|
|
899
916
|
}
|
|
@@ -905,15 +922,11 @@ public class CapacitorUpdaterPlugin
|
|
|
905
922
|
)
|
|
906
923
|
) {
|
|
907
924
|
Log.e(CapacitorUpdater.TAG, "Error no url or wrong format");
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
);
|
|
914
|
-
CapacitorUpdaterPlugin.this.notifyListeners(
|
|
915
|
-
"appReady",
|
|
916
|
-
retNoNeed
|
|
925
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
926
|
+
"Error no url or wrong format",
|
|
927
|
+
current.getVersionName(),
|
|
928
|
+
current,
|
|
929
|
+
true
|
|
917
930
|
);
|
|
918
931
|
return;
|
|
919
932
|
}
|
|
@@ -936,15 +949,11 @@ public class CapacitorUpdaterPlugin
|
|
|
936
949
|
CapacitorUpdater.TAG,
|
|
937
950
|
"Latest bundle already exists, and is in error state. Aborting update."
|
|
938
951
|
);
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
);
|
|
945
|
-
CapacitorUpdaterPlugin.this.notifyListeners(
|
|
946
|
-
"appReady",
|
|
947
|
-
ret
|
|
952
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
953
|
+
"Latest bundle already exists, and is in error state. Aborting update.",
|
|
954
|
+
latestVersionName,
|
|
955
|
+
current,
|
|
956
|
+
true
|
|
948
957
|
);
|
|
949
958
|
return;
|
|
950
959
|
}
|
|
@@ -961,6 +970,12 @@ public class CapacitorUpdaterPlugin
|
|
|
961
970
|
latest
|
|
962
971
|
);
|
|
963
972
|
CapacitorUpdaterPlugin.this._reload();
|
|
973
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
974
|
+
"Update installed",
|
|
975
|
+
latestVersionName,
|
|
976
|
+
latest,
|
|
977
|
+
false
|
|
978
|
+
);
|
|
964
979
|
} else {
|
|
965
980
|
CapacitorUpdaterPlugin.this.notifyListeners(
|
|
966
981
|
"updateAvailable",
|
|
@@ -969,11 +984,13 @@ public class CapacitorUpdaterPlugin
|
|
|
969
984
|
CapacitorUpdaterPlugin.this.implementation.setNextBundle(
|
|
970
985
|
latest.getId()
|
|
971
986
|
);
|
|
987
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
988
|
+
"update downloaded, will install next background",
|
|
989
|
+
latestVersionName,
|
|
990
|
+
latest,
|
|
991
|
+
false
|
|
992
|
+
);
|
|
972
993
|
}
|
|
973
|
-
CapacitorUpdaterPlugin.this.notifyListeners(
|
|
974
|
-
"appReady",
|
|
975
|
-
ret
|
|
976
|
-
);
|
|
977
994
|
return;
|
|
978
995
|
}
|
|
979
996
|
if (latest.isDeleted()) {
|
|
@@ -1003,10 +1020,6 @@ public class CapacitorUpdaterPlugin
|
|
|
1003
1020
|
);
|
|
1004
1021
|
}
|
|
1005
1022
|
}
|
|
1006
|
-
CapacitorUpdaterPlugin.this.notifyListeners(
|
|
1007
|
-
"appReady",
|
|
1008
|
-
ret
|
|
1009
|
-
);
|
|
1010
1023
|
}
|
|
1011
1024
|
|
|
1012
1025
|
new Thread(
|
|
@@ -1043,27 +1056,13 @@ public class CapacitorUpdaterPlugin
|
|
|
1043
1056
|
"error downloading file",
|
|
1044
1057
|
e
|
|
1045
1058
|
);
|
|
1046
|
-
final JSObject ret = new JSObject();
|
|
1047
|
-
ret.put("version", latestVersionName);
|
|
1048
|
-
CapacitorUpdaterPlugin.this.notifyListeners(
|
|
1049
|
-
"downloadFailed",
|
|
1050
|
-
ret
|
|
1051
|
-
);
|
|
1052
1059
|
final BundleInfo current =
|
|
1053
1060
|
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
1054
|
-
CapacitorUpdaterPlugin.this.
|
|
1055
|
-
"
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
retNoNeed.put("bundle", current.toJSON());
|
|
1060
|
-
CapacitorUpdaterPlugin.this.notifyListeners(
|
|
1061
|
-
"noNeedUpdate",
|
|
1062
|
-
retNoNeed
|
|
1063
|
-
);
|
|
1064
|
-
CapacitorUpdaterPlugin.this.notifyListeners(
|
|
1065
|
-
"appReady",
|
|
1066
|
-
ret
|
|
1061
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1062
|
+
"Error downloading file",
|
|
1063
|
+
latestVersionName,
|
|
1064
|
+
current,
|
|
1065
|
+
true
|
|
1067
1066
|
);
|
|
1068
1067
|
}
|
|
1069
1068
|
}
|
|
@@ -1077,20 +1076,20 @@ public class CapacitorUpdaterPlugin
|
|
|
1077
1076
|
current.getId() +
|
|
1078
1077
|
" is the latest bundle."
|
|
1079
1078
|
);
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1079
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1080
|
+
"No need to update",
|
|
1081
|
+
latestVersionName,
|
|
1082
|
+
current,
|
|
1083
|
+
false
|
|
1085
1084
|
);
|
|
1086
1085
|
}
|
|
1087
1086
|
} catch (final JSONException e) {
|
|
1088
1087
|
Log.e(CapacitorUpdater.TAG, "error parsing JSON", e);
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1088
|
+
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1089
|
+
"Error parsing JSON",
|
|
1090
|
+
current.getVersionName(),
|
|
1091
|
+
current,
|
|
1092
|
+
true
|
|
1094
1093
|
);
|
|
1095
1094
|
}
|
|
1096
1095
|
}
|
|
@@ -1246,6 +1245,7 @@ public class CapacitorUpdaterPlugin
|
|
|
1246
1245
|
public void run() {
|
|
1247
1246
|
final JSObject ret = new JSObject();
|
|
1248
1247
|
ret.put("bundle", current.toJSON());
|
|
1248
|
+
ret.put("status", "disabled");
|
|
1249
1249
|
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
|
|
1250
1250
|
}
|
|
1251
1251
|
},
|
package/dist/docs.json
CHANGED
|
@@ -1225,6 +1225,36 @@
|
|
|
1225
1225
|
"type": "string"
|
|
1226
1226
|
}
|
|
1227
1227
|
]
|
|
1228
|
+
},
|
|
1229
|
+
{
|
|
1230
|
+
"name": "AppReadyEvent",
|
|
1231
|
+
"slug": "appreadyevent",
|
|
1232
|
+
"docs": "",
|
|
1233
|
+
"tags": [],
|
|
1234
|
+
"methods": [],
|
|
1235
|
+
"properties": [
|
|
1236
|
+
{
|
|
1237
|
+
"name": "bundle",
|
|
1238
|
+
"tags": [
|
|
1239
|
+
{
|
|
1240
|
+
"text": "5.2.0",
|
|
1241
|
+
"name": "since"
|
|
1242
|
+
}
|
|
1243
|
+
],
|
|
1244
|
+
"docs": "Emit when a app is ready to use.",
|
|
1245
|
+
"complexTypes": [
|
|
1246
|
+
"BundleInfo"
|
|
1247
|
+
],
|
|
1248
|
+
"type": "BundleInfo"
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
"name": "status",
|
|
1252
|
+
"tags": [],
|
|
1253
|
+
"docs": "",
|
|
1254
|
+
"complexTypes": [],
|
|
1255
|
+
"type": "string"
|
|
1256
|
+
}
|
|
1257
|
+
]
|
|
1228
1258
|
}
|
|
1229
1259
|
],
|
|
1230
1260
|
"enums": [],
|
|
@@ -1383,8 +1413,10 @@
|
|
|
1383
1413
|
"docs": "",
|
|
1384
1414
|
"types": [
|
|
1385
1415
|
{
|
|
1386
|
-
"text": "(state:
|
|
1387
|
-
"complexTypes": [
|
|
1416
|
+
"text": "(state: AppReadyEvent): void",
|
|
1417
|
+
"complexTypes": [
|
|
1418
|
+
"AppReadyEvent"
|
|
1419
|
+
]
|
|
1388
1420
|
}
|
|
1389
1421
|
]
|
|
1390
1422
|
}
|
|
@@ -177,6 +177,15 @@ export interface UpdateFailedEvent {
|
|
|
177
177
|
*/
|
|
178
178
|
bundle: BundleInfo;
|
|
179
179
|
}
|
|
180
|
+
export interface AppReadyEvent {
|
|
181
|
+
/**
|
|
182
|
+
* Emit when a app is ready to use.
|
|
183
|
+
*
|
|
184
|
+
* @since 5.2.0
|
|
185
|
+
*/
|
|
186
|
+
bundle: BundleInfo;
|
|
187
|
+
status: string;
|
|
188
|
+
}
|
|
180
189
|
export interface latestVersion {
|
|
181
190
|
/**
|
|
182
191
|
* Res of getLatest method
|
|
@@ -222,7 +231,7 @@ export type DownloadCompleteListener = (state: DownloadCompleteEvent) => void;
|
|
|
222
231
|
export type MajorAvailableListener = (state: MajorAvailableEvent) => void;
|
|
223
232
|
export type UpdateFailedListener = (state: UpdateFailedEvent) => void;
|
|
224
233
|
export type AppReloadedListener = (state: void) => void;
|
|
225
|
-
export type AppReadyListener = (state:
|
|
234
|
+
export type AppReadyListener = (state: AppReadyEvent) => void;
|
|
226
235
|
export interface CapacitorUpdaterPlugin {
|
|
227
236
|
/**
|
|
228
237
|
* Notify Capacitor Updater that the current bundle is working (a rollback will occur of this method is not called on every app launch)
|
|
@@ -15,7 +15,7 @@ import Version
|
|
|
15
15
|
@objc(CapacitorUpdaterPlugin)
|
|
16
16
|
public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
17
17
|
private var implementation = CapacitorUpdater()
|
|
18
|
-
private let PLUGIN_VERSION: String = "5.2.
|
|
18
|
+
private let PLUGIN_VERSION: String = "5.2.10"
|
|
19
19
|
static let updateUrlDefault = "https://api.capgo.app/updates"
|
|
20
20
|
static let statsUrlDefault = "https://api.capgo.app/stats"
|
|
21
21
|
static let channelUrlDefault = "https://api.capgo.app/channel_self"
|
|
@@ -498,6 +498,17 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
498
498
|
self.backgroundTaskID = UIBackgroundTaskIdentifier.invalid
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
+
func endBackGroundTaskWithNotif(msg: String, latestVersionName: String, current: BundleInfo, error: Bool = true) {
|
|
502
|
+
if error {
|
|
503
|
+
self.implementation.sendStats(action: "download_fail", versionName: current.getVersionName())
|
|
504
|
+
self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
|
|
505
|
+
}
|
|
506
|
+
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
507
|
+
self.notifyListeners("appReady", data: ["bundle": current.toJSON(), "message": msg])
|
|
508
|
+
print("\(self.implementation.TAG) endBackGroundTaskWithNotif \(msg)")
|
|
509
|
+
self.endBackGroundTask()
|
|
510
|
+
}
|
|
511
|
+
|
|
501
512
|
func backgroundDownload() {
|
|
502
513
|
let messageUpdate = self.directUpdate ? "Update will occur now." : "Update will occur next time app moves to background."
|
|
503
514
|
DispatchQueue.global(qos: .background).async {
|
|
@@ -515,15 +526,13 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
515
526
|
if res.major == true {
|
|
516
527
|
self.notifyListeners("majorAvailable", data: ["version": res.version])
|
|
517
528
|
}
|
|
518
|
-
self.
|
|
519
|
-
self.endBackGroundTask()
|
|
529
|
+
self.endBackGroundTaskWithNotif(msg: res.message ?? "", latestVersionName: res.version, current: current)
|
|
520
530
|
return
|
|
521
531
|
}
|
|
522
532
|
let sessionKey = res.sessionKey ?? ""
|
|
523
533
|
guard let downloadUrl = URL(string: res.url) else {
|
|
524
534
|
print("\(self.implementation.TAG) Error no url or wrong format")
|
|
525
|
-
self.
|
|
526
|
-
self.endBackGroundTask()
|
|
535
|
+
self.endBackGroundTaskWithNotif(msg: "Error no url or wrong format", latestVersionName: res.version, current: current)
|
|
527
536
|
return
|
|
528
537
|
}
|
|
529
538
|
let latestVersionName = res.version
|
|
@@ -545,15 +554,12 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
545
554
|
}
|
|
546
555
|
guard let next = nextImpl else {
|
|
547
556
|
print("\(self.implementation.TAG) Error downloading file")
|
|
548
|
-
self.
|
|
549
|
-
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
550
|
-
self.endBackGroundTask()
|
|
557
|
+
self.endBackGroundTaskWithNotif(msg: "Error downloading file", latestVersionName: latestVersionName, current: current)
|
|
551
558
|
return
|
|
552
559
|
}
|
|
553
560
|
if next.isErrorStatus() {
|
|
554
561
|
print("\(self.implementation.TAG) Latest version is in error state. Aborting update.")
|
|
555
|
-
self.
|
|
556
|
-
self.endBackGroundTask()
|
|
562
|
+
self.endBackGroundTaskWithNotif(msg: "Latest version is in error state. Aborting update.", latestVersionName: latestVersionName, current: current)
|
|
557
563
|
return
|
|
558
564
|
}
|
|
559
565
|
if res.checksum != "" && next.getChecksum() != res.checksum {
|
|
@@ -564,28 +570,30 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
564
570
|
if !resDel {
|
|
565
571
|
print("\(self.implementation.TAG) Delete failed, id \(id) doesn't exist")
|
|
566
572
|
}
|
|
567
|
-
|
|
573
|
+
self.endBackGroundTaskWithNotif(msg: "Error checksum", latestVersionName: latestVersionName, current: current)
|
|
574
|
+
return
|
|
568
575
|
}
|
|
569
576
|
if self.directUpdate {
|
|
570
577
|
_ = self.implementation.set(bundle: next)
|
|
571
578
|
_ = self._reload()
|
|
579
|
+
self.endBackGroundTaskWithNotif(msg: "update installed", latestVersionName: latestVersionName, current: current)
|
|
572
580
|
} else {
|
|
573
581
|
self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
|
|
574
582
|
_ = self.implementation.setNextBundle(next: next.getId())
|
|
583
|
+
self.endBackGroundTaskWithNotif(msg: "update downloaded, will install next background", latestVersionName: latestVersionName, current: current)
|
|
575
584
|
}
|
|
585
|
+
return
|
|
576
586
|
} catch {
|
|
577
587
|
print("\(self.implementation.TAG) Error downloading file", error.localizedDescription)
|
|
578
588
|
let current: BundleInfo = self.implementation.getCurrentBundle()
|
|
579
|
-
self.
|
|
580
|
-
|
|
581
|
-
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
589
|
+
self.endBackGroundTaskWithNotif(msg: "Error downloading file", latestVersionName: latestVersionName, current: current)
|
|
590
|
+
return
|
|
582
591
|
}
|
|
583
592
|
} else {
|
|
584
593
|
print("\(self.implementation.TAG) No need to update, \(current.getId()) is the latest bundle.")
|
|
585
|
-
self.
|
|
594
|
+
self.endBackGroundTaskWithNotif(msg: "No need to update, \(current.getId()) is the latest bundle.", latestVersionName: latestVersionName, current: current, error: false)
|
|
595
|
+
return
|
|
586
596
|
}
|
|
587
|
-
self.notifyListeners("appReady", data: ["bundle": current.toJSON()])
|
|
588
|
-
self.endBackGroundTask()
|
|
589
597
|
}
|
|
590
598
|
}
|
|
591
599
|
|
|
@@ -648,7 +656,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
648
656
|
print("\(self.implementation.TAG) Auto update is disabled")
|
|
649
657
|
// run after 1 second to make sure that the app is ready
|
|
650
658
|
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
|
|
651
|
-
self.notifyListeners("appReady", data: ["bundle": current.toJSON()])
|
|
659
|
+
self.notifyListeners("appReady", data: ["bundle": current.toJSON(), "status": "disabled"])
|
|
652
660
|
}
|
|
653
661
|
}
|
|
654
662
|
self.checkAppReady()
|