@capawesome/capacitor-live-update 6.6.0 → 6.7.0

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 +147 -40
  2. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java +53 -7
  3. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePlugin.java +75 -2
  4. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/api/GetLatestBundleResponse.java +3 -0
  5. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/FetchLatestBundleOptions.java +24 -0
  6. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/SetNextBundleOptions.java +20 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/SyncOptions.java +20 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/FetchLatestBundleResult.java +21 -2
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetCurrentBundleResult.java +22 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetNextBundleResult.java +22 -0
  11. package/dist/docs.json +254 -17
  12. package/dist/esm/definitions.d.ts +118 -12
  13. package/dist/esm/definitions.js.map +1 -1
  14. package/dist/esm/web.d.ts +4 -1
  15. package/dist/esm/web.js +9 -0
  16. package/dist/esm/web.js.map +1 -1
  17. package/dist/plugin.cjs.js +9 -0
  18. package/dist/plugin.cjs.js.map +1 -1
  19. package/dist/plugin.js +9 -0
  20. package/dist/plugin.js.map +1 -1
  21. package/ios/Plugin/Classes/Options/FetchLatestBundleOptions.swift +18 -0
  22. package/ios/Plugin/Classes/Options/SetNextBundleOptions.swift +14 -0
  23. package/ios/Plugin/Classes/Options/SyncOptions.swift +14 -0
  24. package/ios/Plugin/Classes/Results/FetchLatestBundle.swift +14 -2
  25. package/ios/Plugin/Classes/Results/GetCurrentBundleResult.swift +16 -0
  26. package/ios/Plugin/Classes/Results/GetNextBundleResult.swift +16 -0
  27. package/ios/Plugin/LiveUpdate.swift +46 -7
  28. package/ios/Plugin/LiveUpdatePlugin.m +4 -1
  29. package/ios/Plugin/LiveUpdatePlugin.swift +65 -20
  30. package/package.json +2 -2
package/README.md CHANGED
@@ -103,7 +103,7 @@ In `capacitor.config.json`:
103
103
  In `capacitor.config.ts`:
104
104
 
105
105
  ```ts
106
- /// <reference types="@capacitor/live-update" />
106
+ /// <reference types="@capawesome/capacitor-live-update" />
107
107
 
108
108
  import { CapacitorConfig } from '@capacitor/cli';
109
109
 
@@ -128,10 +128,6 @@ export default config;
128
128
 
129
129
  </docgen-config>
130
130
 
131
- ## Demo
132
-
133
- A working example can be found here: [robingenz/capacitor-plugin-demo](https://github.com/robingenz/capacitor-plugin-demo)
134
-
135
131
  ## Starter templates
136
132
 
137
133
  The following starter templates are available:
@@ -160,11 +156,6 @@ const fetchLatestBundle = async () => {
160
156
  await LiveUpdate.fetchLatestBundle();
161
157
  };
162
158
 
163
- const getBundle = async () => {
164
- const result = await LiveUpdate.getBundle();
165
- return result.bundleId;
166
- };
167
-
168
159
  const getBundles = async () => {
169
160
  const result = await LiveUpdate.getBundles();
170
161
  return result.bundleIds;
@@ -175,6 +166,11 @@ const getChannel = async () => {
175
166
  return result.channel;
176
167
  };
177
168
 
169
+ const getCurrentBundle = async () => {
170
+ const result = await LiveUpdate.getCurrentBundle();
171
+ return result.bundleId;
172
+ };
173
+
178
174
  const getCustomId = async () => {
179
175
  const result = await LiveUpdate.getCustomId();
180
176
  return result.customId;
@@ -185,6 +181,11 @@ const getDeviceId = async () => {
185
181
  return result.deviceId;
186
182
  };
187
183
 
184
+ const getNextBundle = async () => {
185
+ const result = await LiveUpdate.getNextBundle();
186
+ return result.bundleId;
187
+ };
188
+
188
189
  const getVersionCode = async () => {
189
190
  const result = await LiveUpdate.getVersionCode();
190
191
  return result.versionCode;
@@ -207,10 +208,6 @@ const reset = async () => {
207
208
  await LiveUpdate.reset();
208
209
  };
209
210
 
210
- const setBundle = async () => {
211
- await LiveUpdate.setBundle({ bundleId: '1.0.0' });
212
- };
213
-
214
211
  const setChannel = async () => {
215
212
  await LiveUpdate.setChannel({ channel: 'beta' });
216
213
  };
@@ -219,6 +216,10 @@ const setCustomId = async () => {
219
216
  await LiveUpdate.setCustomId({ customId: 'my-custom-id' });
220
217
  };
221
218
 
219
+ const setNextBundle = async () => {
220
+ await LiveUpdate.setNextBundle({ bundleId: '1.0.0' });
221
+ };
222
+
222
223
  const sync = async () => {
223
224
  const result = await LiveUpdate.sync();
224
225
  return result.nextBundleId;
@@ -241,12 +242,14 @@ const isNewBundleAvailable = async () => {
241
242
 
242
243
  * [`deleteBundle(...)`](#deletebundle)
243
244
  * [`downloadBundle(...)`](#downloadbundle)
244
- * [`fetchLatestBundle()`](#fetchlatestbundle)
245
+ * [`fetchLatestBundle(...)`](#fetchlatestbundle)
245
246
  * [`getBundle()`](#getbundle)
246
247
  * [`getBundles()`](#getbundles)
247
248
  * [`getChannel()`](#getchannel)
249
+ * [`getCurrentBundle()`](#getcurrentbundle)
248
250
  * [`getCustomId()`](#getcustomid)
249
251
  * [`getDeviceId()`](#getdeviceid)
252
+ * [`getNextBundle()`](#getnextbundle)
250
253
  * [`getVersionCode()`](#getversioncode)
251
254
  * [`getVersionName()`](#getversionname)
252
255
  * [`ready()`](#ready)
@@ -255,7 +258,8 @@ const isNewBundleAvailable = async () => {
255
258
  * [`setBundle(...)`](#setbundle)
256
259
  * [`setChannel(...)`](#setchannel)
257
260
  * [`setCustomId(...)`](#setcustomid)
258
- * [`sync()`](#sync)
261
+ * [`setNextBundle(...)`](#setnextbundle)
262
+ * [`sync(...)`](#sync)
259
263
  * [Interfaces](#interfaces)
260
264
 
261
265
  </docgen-index>
@@ -301,16 +305,20 @@ Only available on Android and iOS.
301
305
  --------------------
302
306
 
303
307
 
304
- ### fetchLatestBundle()
308
+ ### fetchLatestBundle(...)
305
309
 
306
310
  ```typescript
307
- fetchLatestBundle() => Promise<FetchLatestBundleResult>
311
+ fetchLatestBundle(options?: FetchLatestBundleOptions | undefined) => Promise<FetchLatestBundleResult>
308
312
  ```
309
313
 
310
314
  Fetch the latest bundle using the [Capawesome Cloud](https://capawesome.io/cloud/).
311
315
 
312
316
  Only available on Android and iOS.
313
317
 
318
+ | Param | Type |
319
+ | ------------- | ----------------------------------------------------------------------------- |
320
+ | **`options`** | <code><a href="#fetchlatestbundleoptions">FetchLatestBundleOptions</a></code> |
321
+
314
322
  **Returns:** <code>Promise&lt;<a href="#fetchlatestbundleresult">FetchLatestBundleResult</a>&gt;</code>
315
323
 
316
324
  **Since:** 6.6.0
@@ -358,7 +366,7 @@ Only available on Android and iOS.
358
366
  getChannel() => Promise<GetChannelResult>
359
367
  ```
360
368
 
361
- Get the channel of the app.
369
+ Get the channel that is used for the update.
362
370
 
363
371
  Only available on Android and iOS.
364
372
 
@@ -369,13 +377,31 @@ Only available on Android and iOS.
369
377
  --------------------
370
378
 
371
379
 
380
+ ### getCurrentBundle()
381
+
382
+ ```typescript
383
+ getCurrentBundle() => Promise<GetCurrentBundleResult>
384
+ ```
385
+
386
+ Get the bundle identifier of the current bundle.
387
+ The current bundle is the bundle that is currently used by the app.
388
+
389
+ Only available on Android and iOS.
390
+
391
+ **Returns:** <code>Promise&lt;<a href="#getcurrentbundleresult">GetCurrentBundleResult</a>&gt;</code>
392
+
393
+ **Since:** 6.7.0
394
+
395
+ --------------------
396
+
397
+
372
398
  ### getCustomId()
373
399
 
374
400
  ```typescript
375
401
  getCustomId() => Promise<GetCustomIdResult>
376
402
  ```
377
403
 
378
- Get the custom identifier of the app.
404
+ Get the custom identifier of the device.
379
405
 
380
406
  Only available on Android and iOS.
381
407
 
@@ -392,7 +418,7 @@ Only available on Android and iOS.
392
418
  getDeviceId() => Promise<GetDeviceIdResult>
393
419
  ```
394
420
 
395
- Get the device identifier of the app.
421
+ Get the unique device identifier.
396
422
 
397
423
  Only available on Android and iOS.
398
424
 
@@ -403,6 +429,25 @@ Only available on Android and iOS.
403
429
  --------------------
404
430
 
405
431
 
432
+ ### getNextBundle()
433
+
434
+ ```typescript
435
+ getNextBundle() => Promise<GetNextBundleResult>
436
+ ```
437
+
438
+ Get the bundle identifier of the next bundle.
439
+ The next bundle is the bundle that will be used after calling `reload()`
440
+ or restarting the app.
441
+
442
+ Only available on Android and iOS.
443
+
444
+ **Returns:** <code>Promise&lt;<a href="#getnextbundleresult">GetNextBundleResult</a>&gt;</code>
445
+
446
+ **Since:** 6.7.0
447
+
448
+ --------------------
449
+
450
+
406
451
  ### getVersionCode()
407
452
 
408
453
  ```typescript
@@ -514,7 +559,7 @@ Only available on Android and iOS.
514
559
  setChannel(options: SetChannelOptions) => Promise<void>
515
560
  ```
516
561
 
517
- Set the channel of the app.
562
+ Set the channel to use for the update.
518
563
 
519
564
  Only available on Android and iOS.
520
565
 
@@ -533,7 +578,7 @@ Only available on Android and iOS.
533
578
  setCustomId(options: SetCustomIdOptions) => Promise<void>
534
579
  ```
535
580
 
536
- Set the custom identifier of the app.
581
+ Set the custom identifier of the device.
537
582
 
538
583
  Only available on Android and iOS.
539
584
 
@@ -546,10 +591,31 @@ Only available on Android and iOS.
546
591
  --------------------
547
592
 
548
593
 
549
- ### sync()
594
+ ### setNextBundle(...)
550
595
 
551
596
  ```typescript
552
- sync() => Promise<SyncResult>
597
+ setNextBundle(options: SetNextBundleOptions) => Promise<void>
598
+ ```
599
+
600
+ Set the next bundle to use for the app.
601
+
602
+ Call `reload()` or restart the app to apply the changes.
603
+
604
+ Only available on Android and iOS.
605
+
606
+ | Param | Type |
607
+ | ------------- | --------------------------------------------------------------------- |
608
+ | **`options`** | <code><a href="#setnextbundleoptions">SetNextBundleOptions</a></code> |
609
+
610
+ **Since:** 6.7.0
611
+
612
+ --------------------
613
+
614
+
615
+ ### sync(...)
616
+
617
+ ```typescript
618
+ sync(options?: SyncOptions | undefined) => Promise<SyncResult>
553
619
  ```
554
620
 
555
621
  Automatically download and set the latest bundle for the app using the [Capawesome Cloud](https://capawesome.io/cloud/).
@@ -558,6 +624,10 @@ Call `reload()` or restart the app to apply the changes.
558
624
 
559
625
  Only available on Android and iOS.
560
626
 
627
+ | Param | Type |
628
+ | ------------- | --------------------------------------------------- |
629
+ | **`options`** | <code><a href="#syncoptions">SyncOptions</a></code> |
630
+
561
631
  **Returns:** <code>Promise&lt;<a href="#syncresult">SyncResult</a>&gt;</code>
562
632
 
563
633
  **Since:** 5.0.0
@@ -587,9 +657,18 @@ Only available on Android and iOS.
587
657
 
588
658
  #### FetchLatestBundleResult
589
659
 
590
- | Prop | Type | Description | Since |
591
- | -------------- | --------------------------- | ------------------------------------------------------------------------------ | ----- |
592
- | **`bundleId`** | <code>string \| null</code> | The unique identifier of the latest bundle. If `null`, no bundle is available. | 6.6.0 |
660
+ | Prop | Type | Description | Since |
661
+ | ------------------ | -------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ----- |
662
+ | **`artifactType`** | <code>'manifest' \| 'zip'</code> | The artifact type of the bundle. | 6.7.0 |
663
+ | **`bundleId`** | <code>string \| null</code> | The unique identifier of the latest bundle. If `null`, no bundle is available. | 6.6.0 |
664
+ | **`downloadUrl`** | <code>string</code> | The URL of the latest bundle to download. Pass this URL to the `downloadBundle(...)` method to download the bundle. | 6.7.0 |
665
+
666
+
667
+ #### FetchLatestBundleOptions
668
+
669
+ | Prop | Type | Description | Since |
670
+ | ------------- | ------------------- | ---------------------------------------------------------------- | ----- |
671
+ | **`channel`** | <code>string</code> | The name of the channel where the latest bundle is fetched from. | 6.7.0 |
593
672
 
594
673
 
595
674
  #### GetBundleResult
@@ -608,16 +687,23 @@ Only available on Android and iOS.
608
687
 
609
688
  #### GetChannelResult
610
689
 
611
- | Prop | Type | Description | Since |
612
- | ------------- | --------------------------- | ------------------------------------------------------------------------ | ----- |
613
- | **`channel`** | <code>string \| null</code> | The channel of the app. If `null`, the app is using the default channel. | 5.0.0 |
690
+ | Prop | Type | Description | Since |
691
+ | ------------- | --------------------------- | ------------------------------------------------------------------ | ----- |
692
+ | **`channel`** | <code>string \| null</code> | The channel name. If `null`, the app is using the default channel. | 5.0.0 |
693
+
694
+
695
+ #### GetCurrentBundleResult
696
+
697
+ | Prop | Type | Description | Since |
698
+ | -------------- | --------------------------- | ----------------------------------------------------------------------------------------- | ----- |
699
+ | **`bundleId`** | <code>string \| null</code> | The unique identifier of the current bundle. If `null`, the default bundle is being used. | 6.7.0 |
614
700
 
615
701
 
616
702
  #### GetCustomIdResult
617
703
 
618
- | Prop | Type | Description | Since |
619
- | -------------- | --------------------------- | ------------------------------------------------------------------------- | ----- |
620
- | **`customId`** | <code>string \| null</code> | The custom identifier of the app. If `null`, no custom identifier is set. | 5.0.0 |
704
+ | Prop | Type | Description | Since |
705
+ | -------------- | --------------------------- | ---------------------------------------------------------------------------- | ----- |
706
+ | **`customId`** | <code>string \| null</code> | The custom identifier of the device. If `null`, no custom identifier is set. | 5.0.0 |
621
707
 
622
708
 
623
709
  #### GetDeviceIdResult
@@ -627,6 +713,13 @@ Only available on Android and iOS.
627
713
  | **`deviceId`** | <code>string</code> | The unique identifier of the device. On iOS, [`identifierForVendor`](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor) is used. The value of this property is the same for apps that come from the same vendor running on the same device. | 5.0.0 |
628
714
 
629
715
 
716
+ #### GetNextBundleResult
717
+
718
+ | Prop | Type | Description | Since |
719
+ | -------------- | --------------------------- | -------------------------------------------------------------------------------------- | ----- |
720
+ | **`bundleId`** | <code>string \| null</code> | The unique identifier of the next bundle. If `null`, the default bundle is being used. | 6.7.0 |
721
+
722
+
630
723
  #### GetVersionCodeResult
631
724
 
632
725
  | Prop | Type | Description | Since |
@@ -650,16 +743,23 @@ Only available on Android and iOS.
650
743
 
651
744
  #### SetChannelOptions
652
745
 
653
- | Prop | Type | Description | Since |
654
- | ------------- | --------------------------- | --------------------------------------------------------- | ----- |
655
- | **`channel`** | <code>string \| null</code> | The channel of the app. Set `null` to remove the channel. | 5.0.0 |
746
+ | Prop | Type | Description | Since |
747
+ | ------------- | --------------------------- | --------------------------------------------------- | ----- |
748
+ | **`channel`** | <code>string \| null</code> | The channel name. Set `null` to remove the channel. | 5.0.0 |
656
749
 
657
750
 
658
751
  #### SetCustomIdOptions
659
752
 
660
- | Prop | Type | Description | Since |
661
- | -------------- | --------------------------- | ----------------------------------------------------------------------------- | ----- |
662
- | **`customId`** | <code>string \| null</code> | The custom identifier of the app. Set `null` to remove the custom identifier. | 5.0.0 |
753
+ | Prop | Type | Description | Since |
754
+ | -------------- | --------------------------- | -------------------------------------------------------------------------------- | ----- |
755
+ | **`customId`** | <code>string \| null</code> | The custom identifier of the device. Set `null` to remove the custom identifier. | 5.0.0 |
756
+
757
+
758
+ #### SetNextBundleOptions
759
+
760
+ | Prop | Type | Description | Since |
761
+ | -------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------- | ----- |
762
+ | **`bundleId`** | <code>string \| null</code> | The unique identifier of the bundle to use. Set `null` to use the default bundle (same as calling `reset()`). | 6.7.0 |
663
763
 
664
764
 
665
765
  #### SyncResult
@@ -668,6 +768,13 @@ Only available on Android and iOS.
668
768
  | ------------------ | --------------------------- | ---------------------------------------------------------------------------------------------------------- | ----- |
669
769
  | **`nextBundleId`** | <code>string \| null</code> | The identifier of the next bundle to use. If `null`, the app is up-to-date and no new bundle is available. | 5.0.0 |
670
770
 
771
+
772
+ #### SyncOptions
773
+
774
+ | Prop | Type | Description | Since |
775
+ | ------------- | ------------------- | ---------------------------------------------------------------- | ----- |
776
+ | **`channel`** | <code>string</code> | The name of the channel where the latest bundle is fetched from. | 6.7.0 |
777
+
671
778
  </docgen-api>
672
779
 
673
780
  ## Testing
@@ -17,15 +17,20 @@ import io.capawesome.capacitorjs.plugins.liveupdate.classes.ManifestItem;
17
17
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.api.GetLatestBundleResponse;
18
18
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.DeleteBundleOptions;
19
19
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.DownloadBundleOptions;
20
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.FetchLatestBundleOptions;
20
21
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetBundleOptions;
21
22
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetChannelOptions;
22
23
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetCustomIdOptions;
24
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetNextBundleOptions;
25
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SyncOptions;
23
26
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.FetchLatestBundleResult;
24
27
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetBundleResult;
25
28
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetBundlesResult;
26
29
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetChannelResult;
30
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetCurrentBundleResult;
27
31
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetCustomIdResult;
28
32
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetDeviceIdResult;
33
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetNextBundleResult;
29
34
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetVersionCodeResult;
30
35
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetVersionNameResult;
31
36
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.SyncResult;
@@ -142,9 +147,12 @@ public class LiveUpdate {
142
147
  callback.success();
143
148
  }
144
149
 
145
- public void fetchLatestBundle(@NonNull NonEmptyCallback callback) throws Exception {
146
- GetLatestBundleResponse response = fetchLatestBundle();
147
- FetchLatestBundleResult result = new FetchLatestBundleResult(response == null ? null : response.getBundleId());
150
+ public void fetchLatestBundle(@NonNull FetchLatestBundleOptions options, @NonNull NonEmptyCallback callback) throws Exception {
151
+ GetLatestBundleResponse response = fetchLatestBundle(options);
152
+ ArtifactType artifactType = response == null ? null : response.getArtifactType();
153
+ String bundleId = response == null ? null : response.getBundleId();
154
+ String downloadUrl = response == null ? null : response.getUrl();
155
+ FetchLatestBundleResult result = new FetchLatestBundleResult(artifactType, bundleId, downloadUrl);
148
156
  callback.success(result);
149
157
  }
150
158
 
@@ -169,6 +177,15 @@ public class LiveUpdate {
169
177
  callback.success(result);
170
178
  }
171
179
 
180
+ public void getCurrentBundle(@NonNull NonEmptyCallback<GetCurrentBundleResult> callback) {
181
+ String bundleId = getCurrentBundleId();
182
+ if (bundleId.equals(defaultWebAssetDir)) {
183
+ bundleId = null;
184
+ }
185
+ GetCurrentBundleResult result = new GetCurrentBundleResult(bundleId);
186
+ callback.success(result);
187
+ }
188
+
172
189
  public void getCustomId(@NonNull NonEmptyCallback callback) {
173
190
  String customId = preferences.getCustomId();
174
191
  GetCustomIdResult result = new GetCustomIdResult(customId);
@@ -181,6 +198,15 @@ public class LiveUpdate {
181
198
  callback.success(result);
182
199
  }
183
200
 
201
+ public void getNextBundle(@NonNull NonEmptyCallback<GetNextBundleResult> callback) {
202
+ String bundleId = getNextBundleId();
203
+ if (bundleId.equals(defaultWebAssetDir)) {
204
+ bundleId = null;
205
+ }
206
+ GetNextBundleResult result = new GetNextBundleResult(bundleId);
207
+ callback.success(result);
208
+ }
209
+
184
210
  public void getVersionCode(@NonNull NonEmptyCallback callback) throws PackageManager.NameNotFoundException {
185
211
  String versionCode = getVersionCode();
186
212
  GetVersionCodeResult result = new GetVersionCodeResult(versionCode);
@@ -240,9 +266,28 @@ public class LiveUpdate {
240
266
  callback.success();
241
267
  }
242
268
 
243
- public void sync(@NonNull NonEmptyCallback<Result> callback) throws Exception {
269
+ public void setNextBundle(@NonNull SetNextBundleOptions options, @NonNull EmptyCallback callback) {
270
+ String bundleId = options.getBundleId();
271
+
272
+ if (bundleId == null) {
273
+ reset();
274
+ } else {
275
+ if (hasBundle(bundleId)) {
276
+ setNextBundle(bundleId);
277
+ } else {
278
+ Exception exception = new Exception(LiveUpdatePlugin.ERROR_BUNDLE_NOT_FOUND);
279
+ callback.error(exception);
280
+ return;
281
+ }
282
+ }
283
+ callback.success();
284
+ }
285
+
286
+ public void sync(@NonNull SyncOptions options, @NonNull NonEmptyCallback<Result> callback) throws Exception {
287
+ String channel = options.getChannel();
244
288
  // Fetch the latest bundle
245
- GetLatestBundleResponse response = fetchLatestBundle();
289
+ FetchLatestBundleOptions fetchLatestBundleOptions = new FetchLatestBundleOptions(channel);
290
+ GetLatestBundleResponse response = fetchLatestBundle(fetchLatestBundleOptions);
246
291
  if (response == null) {
247
292
  Logger.debug(LiveUpdatePlugin.TAG, "No update available.");
248
293
  SyncResult syncResult = new SyncResult(null);
@@ -546,7 +591,8 @@ public class LiveUpdate {
546
591
  }
547
592
 
548
593
  @Nullable
549
- private GetLatestBundleResponse fetchLatestBundle() throws Exception {
594
+ private GetLatestBundleResponse fetchLatestBundle(@NonNull FetchLatestBundleOptions options) throws Exception {
595
+ String channel = options.getChannel() == null ? getChannel() : options.getChannel();
550
596
  String url = new HttpUrl.Builder()
551
597
  .scheme("https")
552
598
  .host(host)
@@ -558,7 +604,7 @@ public class LiveUpdate {
558
604
  .addQueryParameter("appVersionCode", getVersionCode())
559
605
  .addQueryParameter("appVersionName", getVersionName())
560
606
  .addQueryParameter("bundleId", getCurrentBundleId())
561
- .addQueryParameter("channelName", getChannel())
607
+ .addQueryParameter("channelName", channel)
562
608
  .addQueryParameter("customId", preferences.getCustomId())
563
609
  .addQueryParameter("deviceId", getDeviceId())
564
610
  .addQueryParameter("osVersion", String.valueOf(Build.VERSION.SDK_INT))
@@ -8,9 +8,14 @@ import com.getcapacitor.PluginMethod;
8
8
  import com.getcapacitor.annotation.CapacitorPlugin;
9
9
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.DeleteBundleOptions;
10
10
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.DownloadBundleOptions;
11
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.FetchLatestBundleOptions;
11
12
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetBundleOptions;
12
13
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetChannelOptions;
13
14
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetCustomIdOptions;
15
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetNextBundleOptions;
16
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SyncOptions;
17
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetCurrentBundleResult;
18
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.results.GetNextBundleResult;
14
19
  import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.EmptyCallback;
15
20
  import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.NonEmptyCallback;
16
21
  import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
@@ -121,6 +126,7 @@ public class LiveUpdatePlugin extends Plugin {
121
126
  @PluginMethod
122
127
  public void fetchLatestBundle(PluginCall call) {
123
128
  try {
129
+ FetchLatestBundleOptions options = new FetchLatestBundleOptions(call);
124
130
  NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
125
131
  @Override
126
132
  public void success(Result result) {
@@ -133,7 +139,7 @@ public class LiveUpdatePlugin extends Plugin {
133
139
  }
134
140
  };
135
141
 
136
- implementation.fetchLatestBundle(callback);
142
+ implementation.fetchLatestBundle(options, callback);
137
143
  } catch (Exception exception) {
138
144
  rejectCall(call, exception);
139
145
  }
@@ -202,6 +208,28 @@ public class LiveUpdatePlugin extends Plugin {
202
208
  }
203
209
  }
204
210
 
211
+ @PluginMethod
212
+ public void getCurrentBundle(PluginCall call) {
213
+ try {
214
+ NonEmptyCallback<GetCurrentBundleResult> callback = new NonEmptyCallback<>() {
215
+ @Override
216
+ public void success(GetCurrentBundleResult result) {
217
+ call.resolve(result.toJSObject());
218
+ }
219
+
220
+ @Override
221
+ public void error(Exception exception) {
222
+ rejectCall(call, exception);
223
+ }
224
+ };
225
+
226
+ assert implementation != null;
227
+ implementation.getCurrentBundle(callback);
228
+ } catch (Exception exception) {
229
+ rejectCall(call, exception);
230
+ }
231
+ }
232
+
205
233
  @PluginMethod
206
234
  public void getCustomId(PluginCall call) {
207
235
  try {
@@ -244,6 +272,28 @@ public class LiveUpdatePlugin extends Plugin {
244
272
  }
245
273
  }
246
274
 
275
+ @PluginMethod
276
+ public void getNextBundle(PluginCall call) {
277
+ try {
278
+ NonEmptyCallback<GetNextBundleResult> callback = new NonEmptyCallback<>() {
279
+ @Override
280
+ public void success(GetNextBundleResult result) {
281
+ call.resolve(result.toJSObject());
282
+ }
283
+
284
+ @Override
285
+ public void error(Exception exception) {
286
+ rejectCall(call, exception);
287
+ }
288
+ };
289
+
290
+ assert implementation != null;
291
+ implementation.getNextBundle(callback);
292
+ } catch (Exception exception) {
293
+ rejectCall(call, exception);
294
+ }
295
+ }
296
+
247
297
  @PluginMethod
248
298
  public void getVersionCode(PluginCall call) {
249
299
  try {
@@ -396,6 +446,28 @@ public class LiveUpdatePlugin extends Plugin {
396
446
  }
397
447
  }
398
448
 
449
+ @PluginMethod
450
+ public void setNextBundle(PluginCall call) {
451
+ try {
452
+ SetNextBundleOptions options = new SetNextBundleOptions(call);
453
+ EmptyCallback callback = new EmptyCallback() {
454
+ @Override
455
+ public void success() {
456
+ call.resolve();
457
+ }
458
+
459
+ @Override
460
+ public void error(Exception exception) {
461
+ rejectCall(call, exception);
462
+ }
463
+ };
464
+
465
+ implementation.setNextBundle(options, callback);
466
+ } catch (Exception exception) {
467
+ rejectCall(call, exception);
468
+ }
469
+ }
470
+
399
471
  @PluginMethod
400
472
  public void sync(PluginCall call) {
401
473
  try {
@@ -411,6 +483,7 @@ public class LiveUpdatePlugin extends Plugin {
411
483
  }
412
484
  syncInProgress = true;
413
485
 
486
+ SyncOptions options = new SyncOptions(call);
414
487
  NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
415
488
  @Override
416
489
  public void success(Result result) {
@@ -425,7 +498,7 @@ public class LiveUpdatePlugin extends Plugin {
425
498
  }
426
499
  };
427
500
 
428
- implementation.sync(callback);
501
+ implementation.sync(options, callback);
429
502
  } catch (Exception exception) {
430
503
  syncInProgress = false;
431
504
  rejectCall(call, exception);
@@ -30,14 +30,17 @@ public class GetLatestBundleResponse {
30
30
  this.url = responseJson.optString("url");
31
31
  }
32
32
 
33
+ @NonNull
33
34
  public ArtifactType getArtifactType() {
34
35
  return artifactType;
35
36
  }
36
37
 
38
+ @NonNull
37
39
  public String getBundleId() {
38
40
  return bundleId;
39
41
  }
40
42
 
43
+ @NonNull
41
44
  public String getUrl() {
42
45
  return url;
43
46
  }
@@ -0,0 +1,24 @@
1
+ package io.capawesome.capacitorjs.plugins.liveupdate.classes.options;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+ import com.getcapacitor.PluginCall;
6
+
7
+ public class FetchLatestBundleOptions {
8
+
9
+ @Nullable
10
+ private final String channel;
11
+
12
+ public FetchLatestBundleOptions(@NonNull PluginCall call) {
13
+ this.channel = call.getString("channel", null);
14
+ }
15
+
16
+ public FetchLatestBundleOptions(@Nullable String channel) {
17
+ this.channel = channel;
18
+ }
19
+
20
+ @Nullable
21
+ public String getChannel() {
22
+ return channel;
23
+ }
24
+ }
@@ -0,0 +1,20 @@
1
+ package io.capawesome.capacitorjs.plugins.liveupdate.classes.options;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+ import com.getcapacitor.PluginCall;
6
+
7
+ public class SetNextBundleOptions {
8
+
9
+ @Nullable
10
+ private final String bundleId;
11
+
12
+ public SetNextBundleOptions(@NonNull PluginCall call) {
13
+ this.bundleId = call.getString("bundleId");
14
+ }
15
+
16
+ @Nullable
17
+ public String getBundleId() {
18
+ return bundleId;
19
+ }
20
+ }