@capgo/capacitor-updater 5.2.9 → 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: void): void</code>
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.9";
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
- final JSObject retNoNeed = new JSObject();
889
- retNoNeed.put("bundle", current.toJSON());
890
- CapacitorUpdaterPlugin.this.notifyListeners(
891
- "noNeedUpdate",
892
- retNoNeed
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
- final JSObject retNoNeed = new JSObject();
909
- retNoNeed.put("bundle", current.toJSON());
910
- CapacitorUpdaterPlugin.this.notifyListeners(
911
- "noNeedUpdate",
912
- retNoNeed
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
- final JSObject retNoNeed = new JSObject();
940
- retNoNeed.put("bundle", current.toJSON());
941
- CapacitorUpdaterPlugin.this.notifyListeners(
942
- "noNeedUpdate",
943
- retNoNeed
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.implementation.sendStats(
1055
- "download_fail",
1056
- current.getVersionName()
1057
- );
1058
- final JSObject retNoNeed = new JSObject();
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
- final JSObject retNoNeed = new JSObject();
1081
- retNoNeed.put("bundle", current.toJSON());
1082
- CapacitorUpdaterPlugin.this.notifyListeners(
1083
- "noNeedUpdate",
1084
- retNoNeed
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
- final JSObject retNoNeed = new JSObject();
1090
- retNoNeed.put("bundle", current.toJSON());
1091
- CapacitorUpdaterPlugin.this.notifyListeners(
1092
- "noNeedUpdate",
1093
- retNoNeed
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: void): void",
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: void) => void;
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.9"
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,17 +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.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
519
- self.notifyListeners("appReady", data: ["bundle": current.toJSON()])
520
- self.endBackGroundTask()
529
+ self.endBackGroundTaskWithNotif(msg: res.message ?? "", latestVersionName: res.version, current: current)
521
530
  return
522
531
  }
523
532
  let sessionKey = res.sessionKey ?? ""
524
533
  guard let downloadUrl = URL(string: res.url) else {
525
534
  print("\(self.implementation.TAG) Error no url or wrong format")
526
- self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
527
- self.notifyListeners("appReady", data: ["bundle": current.toJSON()])
528
- self.endBackGroundTask()
535
+ self.endBackGroundTaskWithNotif(msg: "Error no url or wrong format", latestVersionName: res.version, current: current)
529
536
  return
530
537
  }
531
538
  let latestVersionName = res.version
@@ -547,17 +554,12 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
547
554
  }
548
555
  guard let next = nextImpl else {
549
556
  print("\(self.implementation.TAG) Error downloading file")
550
- self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
551
- self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
552
- self.notifyListeners("appReady", data: ["bundle": current.toJSON()])
553
- self.endBackGroundTask()
557
+ self.endBackGroundTaskWithNotif(msg: "Error downloading file", latestVersionName: latestVersionName, current: current)
554
558
  return
555
559
  }
556
560
  if next.isErrorStatus() {
557
561
  print("\(self.implementation.TAG) Latest version is in error state. Aborting update.")
558
- self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
559
- self.notifyListeners("appReady", data: ["bundle": current.toJSON()])
560
- self.endBackGroundTask()
562
+ self.endBackGroundTaskWithNotif(msg: "Latest version is in error state. Aborting update.", latestVersionName: latestVersionName, current: current)
561
563
  return
562
564
  }
563
565
  if res.checksum != "" && next.getChecksum() != res.checksum {
@@ -568,28 +570,30 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
568
570
  if !resDel {
569
571
  print("\(self.implementation.TAG) Delete failed, id \(id) doesn't exist")
570
572
  }
571
- throw ObjectSavableError.checksum
573
+ self.endBackGroundTaskWithNotif(msg: "Error checksum", latestVersionName: latestVersionName, current: current)
574
+ return
572
575
  }
573
576
  if self.directUpdate {
574
577
  _ = self.implementation.set(bundle: next)
575
578
  _ = self._reload()
579
+ self.endBackGroundTaskWithNotif(msg: "update installed", latestVersionName: latestVersionName, current: current)
576
580
  } else {
577
581
  self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
578
582
  _ = self.implementation.setNextBundle(next: next.getId())
583
+ self.endBackGroundTaskWithNotif(msg: "update downloaded, will install next background", latestVersionName: latestVersionName, current: current)
579
584
  }
585
+ return
580
586
  } catch {
581
587
  print("\(self.implementation.TAG) Error downloading file", error.localizedDescription)
582
588
  let current: BundleInfo = self.implementation.getCurrentBundle()
583
- self.implementation.sendStats(action: "download_fail", versionName: current.getVersionName())
584
- self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
585
- self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
589
+ self.endBackGroundTaskWithNotif(msg: "Error downloading file", latestVersionName: latestVersionName, current: current)
590
+ return
586
591
  }
587
592
  } else {
588
593
  print("\(self.implementation.TAG) No need to update, \(current.getId()) is the latest bundle.")
589
- self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
594
+ self.endBackGroundTaskWithNotif(msg: "No need to update, \(current.getId()) is the latest bundle.", latestVersionName: latestVersionName, current: current, error: false)
595
+ return
590
596
  }
591
- self.notifyListeners("appReady", data: ["bundle": current.toJSON()])
592
- self.endBackGroundTask()
593
597
  }
594
598
  }
595
599
 
@@ -652,7 +656,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
652
656
  print("\(self.implementation.TAG) Auto update is disabled")
653
657
  // run after 1 second to make sure that the app is ready
654
658
  DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
655
- self.notifyListeners("appReady", data: ["bundle": current.toJSON()])
659
+ self.notifyListeners("appReady", data: ["bundle": current.toJSON(), "status": "disabled"])
656
660
  }
657
661
  }
658
662
  self.checkAppReady()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "5.2.9",
3
+ "version": "5.2.10",
4
4
  "packageManager": "pnpm@8.6.12",
5
5
  "license": "MPL-2.0",
6
6
  "description": "Live update for capacitor apps",