@capgo/capacitor-updater 6.13.2 → 6.14.2

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.
Files changed (30) hide show
  1. package/README.md +25 -14
  2. package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +134 -194
  3. package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +23 -23
  4. package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +1 -1
  5. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +964 -1153
  6. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +1259 -1628
  7. package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +161 -197
  8. package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipherV2.java +202 -256
  9. package/android/src/main/java/ee/forgr/capacitor_updater/DataManager.java +16 -16
  10. package/android/src/main/java/ee/forgr/capacitor_updater/DelayCondition.java +44 -48
  11. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUntilNext.java +4 -4
  12. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +378 -467
  13. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +71 -83
  14. package/android/src/main/java/ee/forgr/capacitor_updater/InternalUtils.java +19 -28
  15. package/dist/docs.json +57 -21
  16. package/dist/esm/definitions.d.ts +24 -15
  17. package/dist/esm/definitions.js.map +1 -1
  18. package/dist/esm/index.d.ts +2 -2
  19. package/dist/esm/index.js +4 -4
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/web.d.ts +2 -2
  22. package/dist/esm/web.js +43 -43
  23. package/dist/esm/web.js.map +1 -1
  24. package/dist/plugin.cjs.js +43 -43
  25. package/dist/plugin.cjs.js.map +1 -1
  26. package/dist/plugin.js +43 -43
  27. package/dist/plugin.js.map +1 -1
  28. package/ios/Plugin/CapacitorUpdater.swift +51 -29
  29. package/ios/Plugin/CapacitorUpdaterPlugin.swift +3 -2
  30. package/package.json +5 -7
package/README.md CHANGED
@@ -319,7 +319,7 @@ export default config;
319
319
  * [`next(...)`](#next)
320
320
  * [`set(...)`](#set)
321
321
  * [`delete(...)`](#delete)
322
- * [`list()`](#list)
322
+ * [`list(...)`](#list)
323
323
  * [`reset(...)`](#reset)
324
324
  * [`current()`](#current)
325
325
  * [`reload()`](#reload)
@@ -484,14 +484,18 @@ Deletes the specified bundle from the native app storage. Use with {@link list}
484
484
  --------------------
485
485
 
486
486
 
487
- ### list()
487
+ ### list(...)
488
488
 
489
489
  ```typescript
490
- list() => Promise<BundleListResult>
490
+ list(options?: ListOptions | undefined) => Promise<BundleListResult>
491
491
  ```
492
492
 
493
493
  Get all locally downloaded bundles in your app
494
494
 
495
+ | Param | Type | Description |
496
+ | ------------- | --------------------------------------------------- | ---------------------------------------------------------------------- |
497
+ | **`options`** | <code><a href="#listoptions">ListOptions</a></code> | The {@link <a href="#listoptions">ListOptions</a>} for listing bundles |
498
+
495
499
  **Returns:** <code>Promise&lt;<a href="#bundlelistresult">BundleListResult</a>&gt;</code>
496
500
 
497
501
  --------------------
@@ -732,7 +736,7 @@ Remove all listeners for this plugin.
732
736
  ### addListener('download', ...)
733
737
 
734
738
  ```typescript
735
- addListener(eventName: "download", listenerFunc: (state: DownloadEvent) => void) => Promise<PluginListenerHandle>
739
+ addListener(eventName: 'download', listenerFunc: (state: DownloadEvent) => void) => Promise<PluginListenerHandle>
736
740
  ```
737
741
 
738
742
  Listen for bundle download event in the App. Fires once a download has started, during downloading and when finished.
@@ -752,7 +756,7 @@ Listen for bundle download event in the App. Fires once a download has started,
752
756
  ### addListener('noNeedUpdate', ...)
753
757
 
754
758
  ```typescript
755
- addListener(eventName: "noNeedUpdate", listenerFunc: (state: NoNeedEvent) => void) => Promise<PluginListenerHandle>
759
+ addListener(eventName: 'noNeedUpdate', listenerFunc: (state: NoNeedEvent) => void) => Promise<PluginListenerHandle>
756
760
  ```
757
761
 
758
762
  Listen for no need to update event, useful when you want force check every time the app is launched
@@ -772,7 +776,7 @@ Listen for no need to update event, useful when you want force check every time
772
776
  ### addListener('updateAvailable', ...)
773
777
 
774
778
  ```typescript
775
- addListener(eventName: "updateAvailable", listenerFunc: (state: UpdateAvailableEvent) => void) => Promise<PluginListenerHandle>
779
+ addListener(eventName: 'updateAvailable', listenerFunc: (state: UpdateAvailableEvent) => void) => Promise<PluginListenerHandle>
776
780
  ```
777
781
 
778
782
  Listen for available update event, useful when you want to force check every time the app is launched
@@ -792,7 +796,7 @@ Listen for available update event, useful when you want to force check every tim
792
796
  ### addListener('downloadComplete', ...)
793
797
 
794
798
  ```typescript
795
- addListener(eventName: "downloadComplete", listenerFunc: (state: DownloadCompleteEvent) => void) => Promise<PluginListenerHandle>
799
+ addListener(eventName: 'downloadComplete', listenerFunc: (state: DownloadCompleteEvent) => void) => Promise<PluginListenerHandle>
796
800
  ```
797
801
 
798
802
  Listen for downloadComplete events.
@@ -812,7 +816,7 @@ Listen for downloadComplete events.
812
816
  ### addListener('majorAvailable', ...)
813
817
 
814
818
  ```typescript
815
- addListener(eventName: "majorAvailable", listenerFunc: (state: MajorAvailableEvent) => void) => Promise<PluginListenerHandle>
819
+ addListener(eventName: 'majorAvailable', listenerFunc: (state: MajorAvailableEvent) => void) => Promise<PluginListenerHandle>
816
820
  ```
817
821
 
818
822
  Listen for Major update event in the App, let you know when major update is blocked by setting disableAutoUpdateBreaking
@@ -832,7 +836,7 @@ Listen for Major update event in the App, let you know when major update is bloc
832
836
  ### addListener('updateFailed', ...)
833
837
 
834
838
  ```typescript
835
- addListener(eventName: "updateFailed", listenerFunc: (state: UpdateFailedEvent) => void) => Promise<PluginListenerHandle>
839
+ addListener(eventName: 'updateFailed', listenerFunc: (state: UpdateFailedEvent) => void) => Promise<PluginListenerHandle>
836
840
  ```
837
841
 
838
842
  Listen for update fail event in the App, let you know when update has fail to install at next app start
@@ -852,7 +856,7 @@ Listen for update fail event in the App, let you know when update has fail to in
852
856
  ### addListener('downloadFailed', ...)
853
857
 
854
858
  ```typescript
855
- addListener(eventName: "downloadFailed", listenerFunc: (state: DownloadFailedEvent) => void) => Promise<PluginListenerHandle>
859
+ addListener(eventName: 'downloadFailed', listenerFunc: (state: DownloadFailedEvent) => void) => Promise<PluginListenerHandle>
856
860
  ```
857
861
 
858
862
  Listen for download fail event in the App, let you know when a bundle download has failed
@@ -872,7 +876,7 @@ Listen for download fail event in the App, let you know when a bundle download h
872
876
  ### addListener('appReloaded', ...)
873
877
 
874
878
  ```typescript
875
- addListener(eventName: "appReloaded", listenerFunc: () => void) => Promise<PluginListenerHandle>
879
+ addListener(eventName: 'appReloaded', listenerFunc: () => void) => Promise<PluginListenerHandle>
876
880
  ```
877
881
 
878
882
  Listen for reload event in the App, let you know when reload has happened
@@ -892,7 +896,7 @@ Listen for reload event in the App, let you know when reload has happened
892
896
  ### addListener('appReady', ...)
893
897
 
894
898
  ```typescript
895
- addListener(eventName: "appReady", listenerFunc: (state: AppReadyEvent) => void) => Promise<PluginListenerHandle>
899
+ addListener(eventName: 'appReady', listenerFunc: (state: AppReadyEvent) => void) => Promise<PluginListenerHandle>
896
900
  ```
897
901
 
898
902
  Listen for app ready event in the App, let you know when app is ready to use
@@ -1004,6 +1008,13 @@ Returns null if no next bundle is set.
1004
1008
  | **`bundles`** | <code>BundleInfo[]</code> |
1005
1009
 
1006
1010
 
1011
+ #### ListOptions
1012
+
1013
+ | Prop | Type | Description | Default | Since |
1014
+ | --------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ------ |
1015
+ | **`raw`** | <code>boolean</code> | Whether to return the raw bundle list or the manifest. If true, the list will attempt to read the internal database instead of files on disk. | <code>false</code> | 6.14.0 |
1016
+
1017
+
1007
1018
  #### ResetOptions
1008
1019
 
1009
1020
  | Prop | Type |
@@ -1212,12 +1223,12 @@ Returns null if no next bundle is set.
1212
1223
 
1213
1224
  #### BundleStatus
1214
1225
 
1215
- <code>"success" | "error" | "pending" | "downloading"</code>
1226
+ <code>'success' | 'error' | 'pending' | 'downloading'</code>
1216
1227
 
1217
1228
 
1218
1229
  #### DelayUntilNext
1219
1230
 
1220
- <code>"background" | "kill" | "nativeVersion" | "date"</code>
1231
+ <code>'background' | 'kill' | 'nativeVersion' | 'date'</code>
1221
1232
 
1222
1233
  </docgen-api>
1223
1234
 
@@ -17,198 +17,138 @@ import org.json.JSONTokener;
17
17
 
18
18
  public class BundleInfo {
19
19
 
20
- private static final SimpleDateFormat sdf = new SimpleDateFormat(
21
- "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
22
- );
23
-
24
- public static final String ID_BUILTIN = "builtin";
25
- public static final String VERSION_UNKNOWN = "unknown";
26
- public static final String DOWNLOADED_BUILTIN = "1970-01-01T00:00:00.000Z";
27
-
28
- private final String downloaded;
29
- private final String id;
30
- private final String version;
31
- private final String checksum;
32
- private final BundleStatus status;
33
-
34
- static {
35
- sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
36
- }
37
-
38
- public BundleInfo(final BundleInfo source) {
39
- this(
40
- source.id,
41
- source.version,
42
- source.status,
43
- source.downloaded,
44
- source.checksum
45
- );
46
- }
47
-
48
- public BundleInfo(
49
- final String id,
50
- final String version,
51
- final BundleStatus status,
52
- final Date downloaded,
53
- final String checksum
54
- ) {
55
- this(id, version, status, sdf.format(downloaded), checksum);
56
- }
57
-
58
- public BundleInfo(
59
- final String id,
60
- final String version,
61
- final BundleStatus status,
62
- final String downloaded,
63
- final String checksum
64
- ) {
65
- this.downloaded = downloaded.trim();
66
- this.id = id;
67
- this.version = version;
68
- this.checksum = checksum;
69
- this.status = status;
70
- }
71
-
72
- public Boolean isBuiltin() {
73
- return ID_BUILTIN.equals(this.id);
74
- }
75
-
76
- public Boolean isUnknown() {
77
- return VERSION_UNKNOWN.equals(this.id);
78
- }
79
-
80
- public Boolean isErrorStatus() {
81
- return BundleStatus.ERROR == this.status;
82
- }
83
-
84
- public Boolean isDeleted() {
85
- return BundleStatus.DELETED == this.status;
86
- }
87
-
88
- public boolean isDownloaded() {
89
- return (
90
- !this.isBuiltin() &&
91
- this.downloaded != null &&
92
- !this.downloaded.isEmpty() &&
93
- !this.isDeleted()
94
- );
95
- }
96
-
97
- public String getDownloaded() {
98
- return this.isBuiltin() ? DOWNLOADED_BUILTIN : this.downloaded;
99
- }
100
-
101
- public BundleInfo setDownloaded(Date downloaded) {
102
- return new BundleInfo(
103
- this.id,
104
- this.version,
105
- this.status,
106
- downloaded,
107
- this.checksum
108
- );
109
- }
110
-
111
- public String getChecksum() {
112
- return this.isBuiltin() ? "" : this.checksum;
113
- }
114
-
115
- public BundleInfo setChecksum(String checksum) {
116
- return new BundleInfo(
117
- this.id,
118
- this.version,
119
- this.status,
120
- this.downloaded,
121
- checksum
122
- );
123
- }
124
-
125
- public String getId() {
126
- return this.isBuiltin() ? ID_BUILTIN : this.id;
127
- }
128
-
129
- public BundleInfo setId(String id) {
130
- return new BundleInfo(
131
- id,
132
- this.version,
133
- this.status,
134
- this.downloaded,
135
- this.checksum
136
- );
137
- }
138
-
139
- public String getVersionName() {
140
- return this.version == null ? ID_BUILTIN : this.version;
141
- }
142
-
143
- public BundleInfo setVersionName(String version) {
144
- return new BundleInfo(
145
- this.id,
146
- version,
147
- this.status,
148
- this.downloaded,
149
- this.checksum
150
- );
151
- }
152
-
153
- public BundleStatus getStatus() {
154
- return this.isBuiltin() ? BundleStatus.SUCCESS : this.status;
155
- }
156
-
157
- public BundleInfo setStatus(BundleStatus status) {
158
- return new BundleInfo(
159
- this.id,
160
- this.version,
161
- status,
162
- this.downloaded,
163
- this.checksum
164
- );
165
- }
166
-
167
- public static BundleInfo fromJSON(final JSObject json) throws JSONException {
168
- return BundleInfo.fromJSON(json.toString());
169
- }
170
-
171
- public static BundleInfo fromJSON(final String jsonString)
172
- throws JSONException {
173
- JSONObject json = new JSONObject(new JSONTokener(jsonString));
174
- return new BundleInfo(
175
- json.has("id") ? json.getString("id") : "",
176
- json.has("version")
177
- ? json.getString("version")
178
- : BundleInfo.VERSION_UNKNOWN,
179
- json.has("status")
180
- ? BundleStatus.fromString(json.getString("status"))
181
- : BundleStatus.PENDING,
182
- json.has("downloaded") ? json.getString("downloaded") : "",
183
- json.has("checksum") ? json.getString("checksum") : ""
184
- );
185
- }
186
-
187
- public JSObject toJSON() {
188
- final JSObject result = new JSObject();
189
- result.put("id", this.getId());
190
- result.put("version", this.getVersionName());
191
- result.put("downloaded", this.getDownloaded());
192
- result.put("checksum", this.getChecksum());
193
- result.put("status", this.getStatus());
194
- return result;
195
- }
196
-
197
- @Override
198
- public boolean equals(final Object o) {
199
- if (this == o) return true;
200
- if (!(o instanceof BundleInfo)) return false;
201
- final BundleInfo that = (BundleInfo) o;
202
- return this.getId().equals(that.getId());
203
- }
204
-
205
- @Override
206
- public int hashCode() {
207
- return Objects.hash(this.version);
208
- }
209
-
210
- @Override
211
- public String toString() {
212
- return this.toJSON().toString();
213
- }
20
+ private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
21
+
22
+ public static final String ID_BUILTIN = "builtin";
23
+ public static final String VERSION_UNKNOWN = "unknown";
24
+ public static final String DOWNLOADED_BUILTIN = "1970-01-01T00:00:00.000Z";
25
+
26
+ private final String downloaded;
27
+ private final String id;
28
+ private final String version;
29
+ private final String checksum;
30
+ private final BundleStatus status;
31
+
32
+ static {
33
+ sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
34
+ }
35
+
36
+ public BundleInfo(final BundleInfo source) {
37
+ this(source.id, source.version, source.status, source.downloaded, source.checksum);
38
+ }
39
+
40
+ public BundleInfo(final String id, final String version, final BundleStatus status, final Date downloaded, final String checksum) {
41
+ this(id, version, status, sdf.format(downloaded), checksum);
42
+ }
43
+
44
+ public BundleInfo(final String id, final String version, final BundleStatus status, final String downloaded, final String checksum) {
45
+ this.downloaded = downloaded.trim();
46
+ this.id = id;
47
+ this.version = version;
48
+ this.checksum = checksum;
49
+ this.status = status;
50
+ }
51
+
52
+ public Boolean isBuiltin() {
53
+ return ID_BUILTIN.equals(this.id);
54
+ }
55
+
56
+ public Boolean isUnknown() {
57
+ return VERSION_UNKNOWN.equals(this.id);
58
+ }
59
+
60
+ public Boolean isErrorStatus() {
61
+ return BundleStatus.ERROR == this.status;
62
+ }
63
+
64
+ public Boolean isDeleted() {
65
+ return BundleStatus.DELETED == this.status;
66
+ }
67
+
68
+ public boolean isDownloaded() {
69
+ return (!this.isBuiltin() && this.downloaded != null && !this.downloaded.isEmpty() && !this.isDeleted());
70
+ }
71
+
72
+ public String getDownloaded() {
73
+ return this.isBuiltin() ? DOWNLOADED_BUILTIN : this.downloaded;
74
+ }
75
+
76
+ public BundleInfo setDownloaded(Date downloaded) {
77
+ return new BundleInfo(this.id, this.version, this.status, downloaded, this.checksum);
78
+ }
79
+
80
+ public String getChecksum() {
81
+ return this.isBuiltin() ? "" : this.checksum;
82
+ }
83
+
84
+ public BundleInfo setChecksum(String checksum) {
85
+ return new BundleInfo(this.id, this.version, this.status, this.downloaded, checksum);
86
+ }
87
+
88
+ public String getId() {
89
+ return this.isBuiltin() ? ID_BUILTIN : this.id;
90
+ }
91
+
92
+ public BundleInfo setId(String id) {
93
+ return new BundleInfo(id, this.version, this.status, this.downloaded, this.checksum);
94
+ }
95
+
96
+ public String getVersionName() {
97
+ return this.version == null ? ID_BUILTIN : this.version;
98
+ }
99
+
100
+ public BundleInfo setVersionName(String version) {
101
+ return new BundleInfo(this.id, version, this.status, this.downloaded, this.checksum);
102
+ }
103
+
104
+ public BundleStatus getStatus() {
105
+ return this.isBuiltin() ? BundleStatus.SUCCESS : this.status;
106
+ }
107
+
108
+ public BundleInfo setStatus(BundleStatus status) {
109
+ return new BundleInfo(this.id, this.version, status, this.downloaded, this.checksum);
110
+ }
111
+
112
+ public static BundleInfo fromJSON(final JSObject json) throws JSONException {
113
+ return BundleInfo.fromJSON(json.toString());
114
+ }
115
+
116
+ public static BundleInfo fromJSON(final String jsonString) throws JSONException {
117
+ JSONObject json = new JSONObject(new JSONTokener(jsonString));
118
+ return new BundleInfo(
119
+ json.has("id") ? json.getString("id") : "",
120
+ json.has("version") ? json.getString("version") : BundleInfo.VERSION_UNKNOWN,
121
+ json.has("status") ? BundleStatus.fromString(json.getString("status")) : BundleStatus.PENDING,
122
+ json.has("downloaded") ? json.getString("downloaded") : "",
123
+ json.has("checksum") ? json.getString("checksum") : ""
124
+ );
125
+ }
126
+
127
+ public JSObject toJSON() {
128
+ final JSObject result = new JSObject();
129
+ result.put("id", this.getId());
130
+ result.put("version", this.getVersionName());
131
+ result.put("downloaded", this.getDownloaded());
132
+ result.put("checksum", this.getChecksum());
133
+ result.put("status", this.getStatus());
134
+ return result;
135
+ }
136
+
137
+ @Override
138
+ public boolean equals(final Object o) {
139
+ if (this == o) return true;
140
+ if (!(o instanceof BundleInfo)) return false;
141
+ final BundleInfo that = (BundleInfo) o;
142
+ return this.getId().equals(that.getId());
143
+ }
144
+
145
+ @Override
146
+ public int hashCode() {
147
+ return Objects.hash(this.version);
148
+ }
149
+
150
+ @Override
151
+ public String toString() {
152
+ return this.toJSON().toString();
153
+ }
214
154
  }
@@ -10,35 +10,35 @@ import java.util.HashMap;
10
10
  import java.util.Map;
11
11
 
12
12
  public enum BundleStatus {
13
- SUCCESS("success"),
14
- ERROR("error"),
15
- PENDING("pending"),
16
- DELETED("deleted"),
17
- DOWNLOADING("downloading");
13
+ SUCCESS("success"),
14
+ ERROR("error"),
15
+ PENDING("pending"),
16
+ DELETED("deleted"),
17
+ DOWNLOADING("downloading");
18
18
 
19
- public final String label;
19
+ public final String label;
20
20
 
21
- private static final Map<String, BundleStatus> BY_LABEL = new HashMap<>();
21
+ private static final Map<String, BundleStatus> BY_LABEL = new HashMap<>();
22
22
 
23
- static {
24
- for (final BundleStatus e : values()) {
25
- BY_LABEL.put(e.label, e);
23
+ static {
24
+ for (final BundleStatus e : values()) {
25
+ BY_LABEL.put(e.label, e);
26
+ }
26
27
  }
27
- }
28
28
 
29
- BundleStatus(final String label) {
30
- this.label = label;
31
- }
29
+ BundleStatus(final String label) {
30
+ this.label = label;
31
+ }
32
32
 
33
- @Override
34
- public String toString() {
35
- return this.label;
36
- }
33
+ @Override
34
+ public String toString() {
35
+ return this.label;
36
+ }
37
37
 
38
- public static BundleStatus fromString(final String status) {
39
- if (status == null || status.isEmpty()) {
40
- return BundleStatus.PENDING;
38
+ public static BundleStatus fromString(final String status) {
39
+ if (status == null || status.isEmpty()) {
40
+ return BundleStatus.PENDING;
41
+ }
42
+ return BundleStatus.BY_LABEL.get(status);
41
43
  }
42
- return BundleStatus.BY_LABEL.get(status);
43
- }
44
44
  }
@@ -9,5 +9,5 @@ package ee.forgr.capacitor_updater;
9
9
  import com.getcapacitor.JSObject;
10
10
 
11
11
  public interface Callback {
12
- void callback(JSObject jsoObject);
12
+ void callback(JSObject jsoObject);
13
13
  }