@capawesome/capacitor-live-update 6.7.2 → 7.1.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 (43) hide show
  1. package/CapawesomeCapacitorLiveUpdate.podspec +2 -2
  2. package/Package.swift +32 -0
  3. package/README.md +102 -88
  4. package/android/build.gradle +9 -9
  5. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java +192 -133
  6. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateConfig.java +6 -27
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdateHttpClient.java +7 -2
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePlugin.java +51 -77
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePreferences.java +12 -5
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/api/GetLatestBundleResponse.java +27 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/events/DownloadBundleProgressEvent.java +32 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/DownloadBundleOptions.java +16 -1
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/FetchLatestBundleResult.java +29 -1
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/ReadyResult.java +32 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/interfaces/DownloadProgressCallback.java +5 -0
  16. package/dist/docs.json +228 -147
  17. package/dist/esm/definitions.d.ts +140 -49
  18. package/dist/esm/definitions.js.map +1 -1
  19. package/dist/esm/index.js +1 -1
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/web.d.ts +2 -2
  22. package/dist/esm/web.js.map +1 -1
  23. package/dist/plugin.cjs.js +1 -3
  24. package/dist/plugin.cjs.js.map +1 -1
  25. package/dist/plugin.js +1 -3
  26. package/dist/plugin.js.map +1 -1
  27. package/ios/Plugin/Classes/Events/DownloadBundleProgressEvent.swift +25 -0
  28. package/ios/Plugin/Classes/Options/DownloadBundleOptions.swift +7 -1
  29. package/ios/Plugin/Classes/Results/{FetchLatestBundle.swift → FetchLatestBundleResult.swift} +16 -1
  30. package/ios/Plugin/Classes/Results/ReadyResult.swift +22 -0
  31. package/ios/Plugin/LiveUpdate.swift +171 -154
  32. package/ios/Plugin/LiveUpdateConfig.swift +2 -4
  33. package/ios/Plugin/LiveUpdateHttpClient.swift +6 -2
  34. package/ios/Plugin/LiveUpdatePlugin.swift +45 -37
  35. package/ios/Plugin/LiveUpdatePreferences.swift +6 -20
  36. package/ios/Plugin/Protocols/Api/GetLatestBundleResponse.swift +3 -0
  37. package/package.json +17 -18
  38. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/SetBundleOptions.java +0 -18
  39. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetBundleResult.java +0 -24
  40. package/ios/Plugin/Classes/Options/SetBundleOptions.swift +0 -14
  41. package/ios/Plugin/Classes/Results/GetBundleResult.swift +0 -16
  42. package/ios/Plugin/LiveUpdatePlugin.h +0 -10
  43. package/ios/Plugin/LiveUpdatePlugin.m +0 -27
@@ -13,17 +13,13 @@ public class LiveUpdateConfig {
13
13
  @Nullable
14
14
  private String defaultChannel = null;
15
15
 
16
- private boolean enabled = true;
17
16
  private int httpTimeout = 60000;
18
17
 
19
- @Nullable
20
- private String location = null;
21
-
22
18
  @Nullable
23
19
  private String publicKey = null;
24
20
 
25
- private int readyTimeout = 10000;
26
- private boolean resetOnUpdate = true;
21
+ private int readyTimeout = 0;
22
+ private String serverDomain = "api.cloud.capawesome.io";
27
23
 
28
24
  @Nullable
29
25
  public String getAppId() {
@@ -39,19 +35,10 @@ public class LiveUpdateConfig {
39
35
  return defaultChannel;
40
36
  }
41
37
 
42
- public boolean getEnabled() {
43
- return enabled;
44
- }
45
-
46
38
  public int getHttpTimeout() {
47
39
  return httpTimeout;
48
40
  }
49
41
 
50
- @Nullable
51
- public String getLocation() {
52
- return location;
53
- }
54
-
55
42
  @Nullable
56
43
  public String getPublicKey() {
57
44
  return publicKey;
@@ -61,8 +48,8 @@ public class LiveUpdateConfig {
61
48
  return readyTimeout;
62
49
  }
63
50
 
64
- public boolean getResetOnUpdate() {
65
- return resetOnUpdate;
51
+ public String getServerDomain() {
52
+ return serverDomain;
66
53
  }
67
54
 
68
55
  public void setAppId(@Nullable String appId) {
@@ -77,18 +64,10 @@ public class LiveUpdateConfig {
77
64
  this.defaultChannel = defaultChannel;
78
65
  }
79
66
 
80
- public void setEnabled(boolean enabled) {
81
- this.enabled = enabled;
82
- }
83
-
84
67
  public void setHttpTimeout(int httpTimeout) {
85
68
  this.httpTimeout = httpTimeout;
86
69
  }
87
70
 
88
- public void setLocation(@Nullable String location) {
89
- this.location = location;
90
- }
91
-
92
71
  public void setPublicKey(@Nullable String publicKey) {
93
72
  this.publicKey = publicKey;
94
73
  }
@@ -97,7 +76,7 @@ public class LiveUpdateConfig {
97
76
  this.readyTimeout = readyTimeout;
98
77
  }
99
78
 
100
- public void setResetOnUpdate(boolean resetOnUpdate) {
101
- this.resetOnUpdate = resetOnUpdate;
79
+ public void setServerDomain(String serverDomain) {
80
+ this.serverDomain = serverDomain;
102
81
  }
103
82
  }
@@ -2,6 +2,8 @@ package io.capawesome.capacitorjs.plugins.liveupdate;
2
2
 
3
3
  import androidx.annotation.NonNull;
4
4
  import androidx.annotation.Nullable;
5
+ import com.getcapacitor.Logger;
6
+ import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.DownloadProgressCallback;
5
7
  import java.io.File;
6
8
  import java.io.IOException;
7
9
  import java.util.concurrent.TimeUnit;
@@ -52,7 +54,8 @@ public class LiveUpdateHttpClient {
52
54
  return okHttpClient.newCall(request).execute();
53
55
  }
54
56
 
55
- public static void writeResponseBodyToFile(ResponseBody body, File file) throws IOException {
57
+ public static void writeResponseBodyToFile(ResponseBody body, File file, @Nullable DownloadProgressCallback callback)
58
+ throws IOException {
56
59
  long contentLength = body.contentLength();
57
60
  BufferedSource source = body.source();
58
61
  BufferedSink sink = Okio.buffer(Okio.sink(file));
@@ -62,7 +65,9 @@ public class LiveUpdateHttpClient {
62
65
  for (long bytesRead; (bytesRead = source.read(sinkBuffer, bufferSize)) != -1;) {
63
66
  sink.emit();
64
67
  totalBytesRead += bytesRead;
65
- int progress = (int) ((totalBytesRead * 100) / contentLength);
68
+ if (callback != null) {
69
+ callback.onProgress(totalBytesRead, contentLength);
70
+ }
66
71
  }
67
72
  sink.flush();
68
73
  sink.close();
@@ -1,15 +1,17 @@
1
1
  package io.capawesome.capacitorjs.plugins.liveupdate;
2
2
 
3
+ import androidx.annotation.NonNull;
3
4
  import androidx.annotation.Nullable;
5
+ import com.getcapacitor.JSObject;
4
6
  import com.getcapacitor.Logger;
5
7
  import com.getcapacitor.Plugin;
6
8
  import com.getcapacitor.PluginCall;
7
9
  import com.getcapacitor.PluginMethod;
8
10
  import com.getcapacitor.annotation.CapacitorPlugin;
11
+ import io.capawesome.capacitorjs.plugins.liveupdate.classes.events.DownloadBundleProgressEvent;
9
12
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.DeleteBundleOptions;
10
13
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.DownloadBundleOptions;
11
14
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.FetchLatestBundleOptions;
12
- import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetBundleOptions;
13
15
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetChannelOptions;
14
16
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetCustomIdOptions;
15
17
  import io.capawesome.capacitorjs.plugins.liveupdate.classes.options.SetNextBundleOptions;
@@ -24,7 +26,7 @@ import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
24
26
  public class LiveUpdatePlugin extends Plugin {
25
27
 
26
28
  public static final String TAG = "LiveUpdate";
27
- public static final String VERSION = "6.7.2";
29
+ public static final String VERSION = "7.1.0";
28
30
  public static final String SHARED_PREFERENCES_NAME = "CapawesomeLiveUpdate"; // DO NOT CHANGE
29
31
  public static final String ERROR_APP_ID_MISSING = "appId must be configured.";
30
32
  public static final String ERROR_BUNDLE_EXISTS = "bundle already exists.";
@@ -42,6 +44,7 @@ public class LiveUpdatePlugin extends Plugin {
42
44
  public static final String ERROR_SIGNATURE_MISSING = "Bundle does not contain a signature.";
43
45
  public static final String ERROR_SYNC_IN_PROGRESS = "Sync is already in progress.";
44
46
  public static final String ERROR_UNKNOWN_ERROR = "An unknown error has occurred.";
47
+ public static final String EVENT_DOWNLOAD_BUNDLE_PROGRESS = "downloadBundleProgress";
45
48
 
46
49
  private boolean syncInProgress = false;
47
50
 
@@ -73,7 +76,7 @@ public class LiveUpdatePlugin extends Plugin {
73
76
  EmptyCallback callback = new EmptyCallback() {
74
77
  @Override
75
78
  public void success() {
76
- call.resolve();
79
+ resolveCall(call);
77
80
  }
78
81
 
79
82
  @Override
@@ -98,17 +101,18 @@ public class LiveUpdatePlugin extends Plugin {
98
101
  return;
99
102
  }
100
103
  String checksum = call.getString("checksum");
104
+ String signature = call.getString("signature");
101
105
  String url = call.getString("url");
102
106
  if (url == null) {
103
107
  call.reject(ERROR_URL_MISSING);
104
108
  return;
105
109
  }
106
110
 
107
- DownloadBundleOptions options = new DownloadBundleOptions(artifactType, bundleId, checksum, url);
111
+ DownloadBundleOptions options = new DownloadBundleOptions(artifactType, bundleId, checksum, signature, url);
108
112
  EmptyCallback callback = new EmptyCallback() {
109
113
  @Override
110
114
  public void success() {
111
- call.resolve();
115
+ resolveCall(call);
112
116
  }
113
117
 
114
118
  @Override
@@ -130,7 +134,7 @@ public class LiveUpdatePlugin extends Plugin {
130
134
  NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
131
135
  @Override
132
136
  public void success(Result result) {
133
- call.resolve(result.toJSObject());
137
+ resolveCall(call, result.toJSObject());
134
138
  }
135
139
 
136
140
  @Override
@@ -145,34 +149,13 @@ public class LiveUpdatePlugin extends Plugin {
145
149
  }
146
150
  }
147
151
 
148
- @PluginMethod
149
- public void getBundle(PluginCall call) {
150
- try {
151
- NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
152
- @Override
153
- public void success(Result result) {
154
- call.resolve(result.toJSObject());
155
- }
156
-
157
- @Override
158
- public void error(Exception exception) {
159
- rejectCall(call, exception);
160
- }
161
- };
162
-
163
- implementation.getBundle(callback);
164
- } catch (Exception exception) {
165
- rejectCall(call, exception);
166
- }
167
- }
168
-
169
152
  @PluginMethod
170
153
  public void getBundles(PluginCall call) {
171
154
  try {
172
155
  NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
173
156
  @Override
174
157
  public void success(Result result) {
175
- call.resolve(result.toJSObject());
158
+ resolveCall(call, result.toJSObject());
176
159
  }
177
160
 
178
161
  @Override
@@ -193,7 +176,7 @@ public class LiveUpdatePlugin extends Plugin {
193
176
  NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
194
177
  @Override
195
178
  public void success(Result result) {
196
- call.resolve(result.toJSObject());
179
+ resolveCall(call, result.toJSObject());
197
180
  }
198
181
 
199
182
  @Override
@@ -214,7 +197,7 @@ public class LiveUpdatePlugin extends Plugin {
214
197
  NonEmptyCallback<GetCurrentBundleResult> callback = new NonEmptyCallback<>() {
215
198
  @Override
216
199
  public void success(GetCurrentBundleResult result) {
217
- call.resolve(result.toJSObject());
200
+ resolveCall(call, result.toJSObject());
218
201
  }
219
202
 
220
203
  @Override
@@ -236,7 +219,7 @@ public class LiveUpdatePlugin extends Plugin {
236
219
  NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
237
220
  @Override
238
221
  public void success(Result result) {
239
- call.resolve(result.toJSObject());
222
+ resolveCall(call, result.toJSObject());
240
223
  }
241
224
 
242
225
  @Override
@@ -257,7 +240,7 @@ public class LiveUpdatePlugin extends Plugin {
257
240
  NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
258
241
  @Override
259
242
  public void success(Result result) {
260
- call.resolve(result.toJSObject());
243
+ resolveCall(call, result.toJSObject());
261
244
  }
262
245
 
263
246
  @Override
@@ -278,7 +261,7 @@ public class LiveUpdatePlugin extends Plugin {
278
261
  NonEmptyCallback<GetNextBundleResult> callback = new NonEmptyCallback<>() {
279
262
  @Override
280
263
  public void success(GetNextBundleResult result) {
281
- call.resolve(result.toJSObject());
264
+ resolveCall(call, result.toJSObject());
282
265
  }
283
266
 
284
267
  @Override
@@ -300,7 +283,7 @@ public class LiveUpdatePlugin extends Plugin {
300
283
  NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
301
284
  @Override
302
285
  public void success(Result result) {
303
- call.resolve(result.toJSObject());
286
+ resolveCall(call, result.toJSObject());
304
287
  }
305
288
 
306
289
  @Override
@@ -321,7 +304,7 @@ public class LiveUpdatePlugin extends Plugin {
321
304
  NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
322
305
  @Override
323
306
  public void success(Result result) {
324
- call.resolve(result.toJSObject());
307
+ resolveCall(call, result.toJSObject());
325
308
  }
326
309
 
327
310
  @Override
@@ -339,8 +322,19 @@ public class LiveUpdatePlugin extends Plugin {
339
322
  @PluginMethod
340
323
  public void ready(PluginCall call) {
341
324
  try {
342
- implementation.ready();
343
- call.resolve();
325
+ NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
326
+ @Override
327
+ public void success(Result result) {
328
+ resolveCall(call, result.toJSObject());
329
+ }
330
+
331
+ @Override
332
+ public void error(Exception exception) {
333
+ rejectCall(call, exception);
334
+ }
335
+ };
336
+
337
+ implementation.ready(callback);
344
338
  } catch (Exception exception) {
345
339
  rejectCall(call, exception);
346
340
  }
@@ -350,7 +344,7 @@ public class LiveUpdatePlugin extends Plugin {
350
344
  public void reload(PluginCall call) {
351
345
  try {
352
346
  implementation.reload();
353
- call.resolve();
347
+ resolveCall(call);
354
348
  } catch (Exception exception) {
355
349
  rejectCall(call, exception);
356
350
  }
@@ -360,35 +354,7 @@ public class LiveUpdatePlugin extends Plugin {
360
354
  public void reset(PluginCall call) {
361
355
  try {
362
356
  implementation.reset();
363
- call.resolve();
364
- } catch (Exception exception) {
365
- rejectCall(call, exception);
366
- }
367
- }
368
-
369
- @PluginMethod
370
- public void setBundle(PluginCall call) {
371
- try {
372
- String bundleId = call.getString("bundleId");
373
- if (bundleId == null) {
374
- call.reject(ERROR_BUNDLE_ID_MISSING);
375
- return;
376
- }
377
-
378
- SetBundleOptions options = new SetBundleOptions(bundleId);
379
- EmptyCallback callback = new EmptyCallback() {
380
- @Override
381
- public void success() {
382
- call.resolve();
383
- }
384
-
385
- @Override
386
- public void error(Exception exception) {
387
- rejectCall(call, exception);
388
- }
389
- };
390
-
391
- implementation.setBundle(options, callback);
357
+ resolveCall(call);
392
358
  } catch (Exception exception) {
393
359
  rejectCall(call, exception);
394
360
  }
@@ -403,7 +369,7 @@ public class LiveUpdatePlugin extends Plugin {
403
369
  EmptyCallback callback = new EmptyCallback() {
404
370
  @Override
405
371
  public void success() {
406
- call.resolve();
372
+ resolveCall(call);
407
373
  }
408
374
 
409
375
  @Override
@@ -431,7 +397,7 @@ public class LiveUpdatePlugin extends Plugin {
431
397
  EmptyCallback callback = new EmptyCallback() {
432
398
  @Override
433
399
  public void success() {
434
- call.resolve();
400
+ resolveCall(call);
435
401
  }
436
402
 
437
403
  @Override
@@ -453,7 +419,7 @@ public class LiveUpdatePlugin extends Plugin {
453
419
  EmptyCallback callback = new EmptyCallback() {
454
420
  @Override
455
421
  public void success() {
456
- call.resolve();
422
+ resolveCall(call);
457
423
  }
458
424
 
459
425
  @Override
@@ -488,7 +454,7 @@ public class LiveUpdatePlugin extends Plugin {
488
454
  @Override
489
455
  public void success(Result result) {
490
456
  syncInProgress = false;
491
- call.resolve(result.toJSObject());
457
+ resolveCall(call, result.toJSObject());
492
458
  }
493
459
 
494
460
  @Override
@@ -505,6 +471,10 @@ public class LiveUpdatePlugin extends Plugin {
505
471
  }
506
472
  }
507
473
 
474
+ public void notifyDownloadBundleProgressListeners(@NonNull DownloadBundleProgressEvent event) {
475
+ notifyListeners(EVENT_DOWNLOAD_BUNDLE_PROGRESS, event.toJSObject(), false);
476
+ }
477
+
508
478
  private LiveUpdateConfig getLiveUpdateConfig() {
509
479
  LiveUpdateConfig config = new LiveUpdateConfig();
510
480
 
@@ -514,22 +484,26 @@ public class LiveUpdatePlugin extends Plugin {
514
484
  config.setAutoDeleteBundles(autoDeleteBundles);
515
485
  String defaultChannel = getConfig().getString("defaultChannel", config.getDefaultChannel());
516
486
  config.setDefaultChannel(defaultChannel);
517
- boolean enabled = getConfig().getBoolean("enabled", config.getEnabled());
518
- config.setEnabled(enabled);
519
487
  int httpTimeout = getConfig().getInt("httpTimeout", config.getHttpTimeout());
520
488
  config.setHttpTimeout(httpTimeout);
521
- String location = getConfig().getString("location", config.getLocation());
522
- config.setLocation(location);
523
489
  String publicKey = getConfig().getString("publicKey", config.getPublicKey());
524
490
  config.setPublicKey(publicKey);
525
491
  int readyTimeout = getConfig().getInt("readyTimeout", config.getReadyTimeout());
526
492
  config.setReadyTimeout(readyTimeout);
527
- boolean resetOnUpdate = getConfig().getBoolean("resetOnUpdate", config.getResetOnUpdate());
528
- config.setResetOnUpdate(resetOnUpdate);
493
+ String serverDomain = getConfig().getString("serverDomain", config.getServerDomain());
494
+ config.setServerDomain(serverDomain);
529
495
 
530
496
  return config;
531
497
  }
532
498
 
499
+ private void resolveCall(@NonNull PluginCall call) {
500
+ call.resolve();
501
+ }
502
+
503
+ private void resolveCall(@NonNull PluginCall call, @NonNull JSObject result) {
504
+ call.resolve(result);
505
+ }
506
+
533
507
  private void rejectCall(PluginCall call, Exception exception) {
534
508
  String message = exception.getMessage();
535
509
  if (exception instanceof java.net.SocketTimeoutException) {
@@ -18,7 +18,7 @@ public class LiveUpdatePreferences {
18
18
  private final String channelKey = "channel"; // DO NOT CHANGE
19
19
  private final String deviceIdKey = "deviceId"; // DO NOT CHANGE
20
20
  private final String customIdKey = "customId"; // DO NOT CHANGE
21
- private final String lastVersionCodeKey = "lastVersionCode"; // DO NOT CHANGE
21
+ private final String previousBundleIdKey = "previousBundleId"; // DO NOT CHANGE
22
22
 
23
23
  public LiveUpdatePreferences(@NonNull Context context) {
24
24
  this.context = context;
@@ -48,8 +48,11 @@ public class LiveUpdatePreferences {
48
48
  }
49
49
  }
50
50
 
51
- public int getLastVersionCode() {
52
- return context.getSharedPreferences(LiveUpdatePlugin.SHARED_PREFERENCES_NAME, Activity.MODE_PRIVATE).getInt(lastVersionCodeKey, 0);
51
+ @Nullable
52
+ public String getPreviousBundleId() {
53
+ return context
54
+ .getSharedPreferences(LiveUpdatePlugin.SHARED_PREFERENCES_NAME, Activity.MODE_PRIVATE)
55
+ .getString(previousBundleIdKey, null);
53
56
  }
54
57
 
55
58
  public void setChannel(@Nullable String channel) {
@@ -79,8 +82,12 @@ public class LiveUpdatePreferences {
79
82
  settingsEditor.apply();
80
83
  }
81
84
 
82
- public void setLastVersionCode(int lastVersionCode) {
83
- settingsEditor.putInt(lastVersionCodeKey, lastVersionCode);
85
+ public void setPreviousBundleId(@Nullable String bundleId) {
86
+ if (bundleId == null) {
87
+ settingsEditor.remove(previousBundleIdKey);
88
+ } else {
89
+ settingsEditor.putString(previousBundleIdKey, bundleId);
90
+ }
84
91
  settingsEditor.apply();
85
92
  }
86
93
  }
@@ -16,6 +16,15 @@ public class GetLatestBundleResponse {
16
16
  @NonNull
17
17
  private String bundleId;
18
18
 
19
+ @Nullable
20
+ private String checksum;
21
+
22
+ @Nullable
23
+ private JSONObject customProperties;
24
+
25
+ @Nullable
26
+ private String signature;
27
+
19
28
  @NonNull
20
29
  private String url;
21
30
 
@@ -27,6 +36,9 @@ public class GetLatestBundleResponse {
27
36
  this.artifactType = ArtifactType.ZIP;
28
37
  }
29
38
  this.bundleId = responseJson.optString("bundleId");
39
+ this.checksum = responseJson.optString("checksum");
40
+ this.customProperties = responseJson.optJSONObject("customProperties");
41
+ this.signature = responseJson.optString("signature");
30
42
  this.url = responseJson.optString("url");
31
43
  }
32
44
 
@@ -40,6 +52,21 @@ public class GetLatestBundleResponse {
40
52
  return bundleId;
41
53
  }
42
54
 
55
+ @Nullable
56
+ public JSONObject getCustomProperties() {
57
+ return customProperties;
58
+ }
59
+
60
+ @Nullable
61
+ public String getChecksum() {
62
+ return checksum;
63
+ }
64
+
65
+ @Nullable
66
+ public String getSignature() {
67
+ return signature;
68
+ }
69
+
43
70
  @NonNull
44
71
  public String getUrl() {
45
72
  return url;
@@ -0,0 +1,32 @@
1
+ package io.capawesome.capacitorjs.plugins.liveupdate.classes.events;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
6
+
7
+ public class DownloadBundleProgressEvent implements Result {
8
+
9
+ @NonNull
10
+ private final String bundleId;
11
+
12
+ private final long downloadedBytes;
13
+ private final long totalBytes;
14
+ private final double progress;
15
+
16
+ public DownloadBundleProgressEvent(@NonNull String bundleId, long downloadedBytes, long totalBytes) {
17
+ this.bundleId = bundleId;
18
+ this.downloadedBytes = downloadedBytes;
19
+ this.totalBytes = totalBytes;
20
+ this.progress = (double) downloadedBytes / (double) totalBytes;
21
+ }
22
+
23
+ @NonNull
24
+ public JSObject toJSObject() {
25
+ JSObject result = new JSObject();
26
+ result.put("bundleId", bundleId);
27
+ result.put("downloadedBytes", downloadedBytes);
28
+ result.put("progress", progress);
29
+ result.put("totalBytes", totalBytes);
30
+ return result;
31
+ }
32
+ }
@@ -15,10 +15,19 @@ public class DownloadBundleOptions {
15
15
  @Nullable
16
16
  private String checksum;
17
17
 
18
+ @Nullable
19
+ private String signature;
20
+
18
21
  @NonNull
19
22
  private String url;
20
23
 
21
- public DownloadBundleOptions(@NonNull String artifactType, @NonNull String bundleId, @Nullable String checksum, @NonNull String url) {
24
+ public DownloadBundleOptions(
25
+ @NonNull String artifactType,
26
+ @NonNull String bundleId,
27
+ @Nullable String checksum,
28
+ @Nullable String signature,
29
+ @NonNull String url
30
+ ) {
22
31
  if (artifactType.equals("manifest")) {
23
32
  this.artifactType = ArtifactType.MANIFEST;
24
33
  } else {
@@ -26,6 +35,7 @@ public class DownloadBundleOptions {
26
35
  }
27
36
  this.bundleId = bundleId;
28
37
  this.checksum = checksum;
38
+ this.signature = signature;
29
39
  this.url = url;
30
40
  }
31
41
 
@@ -44,6 +54,11 @@ public class DownloadBundleOptions {
44
54
  return checksum;
45
55
  }
46
56
 
57
+ @Nullable
58
+ public String getSignature() {
59
+ return signature;
60
+ }
61
+
47
62
  @NonNull
48
63
  public String getUrl() {
49
64
  return url;
@@ -15,13 +15,32 @@ public class FetchLatestBundleResult implements Result {
15
15
  @Nullable
16
16
  private final String bundleId;
17
17
 
18
+ @Nullable
19
+ private final String checksum;
20
+
21
+ @Nullable
22
+ private final JSONObject customProperties;
23
+
18
24
  @Nullable
19
25
  private final String downloadUrl;
20
26
 
21
- public FetchLatestBundleResult(@Nullable ArtifactType artifactType, @Nullable String bundleId, @Nullable String downloadUrl) {
27
+ @Nullable
28
+ private final String signature;
29
+
30
+ public FetchLatestBundleResult(
31
+ @Nullable ArtifactType artifactType,
32
+ @Nullable String bundleId,
33
+ @Nullable String checksum,
34
+ @Nullable JSONObject customProperties,
35
+ @Nullable String downloadUrl,
36
+ @Nullable String signature
37
+ ) {
22
38
  this.artifactType = artifactType;
23
39
  this.bundleId = bundleId;
40
+ this.checksum = checksum;
41
+ this.customProperties = customProperties;
24
42
  this.downloadUrl = downloadUrl;
43
+ this.signature = signature;
25
44
  }
26
45
 
27
46
  @NonNull
@@ -33,9 +52,18 @@ public class FetchLatestBundleResult implements Result {
33
52
  result.put("artifactType", "zip");
34
53
  }
35
54
  result.put("bundleId", bundleId == null ? JSONObject.NULL : bundleId);
55
+ if (checksum != null) {
56
+ result.put("checksum", checksum);
57
+ }
58
+ if (customProperties != null) {
59
+ result.put("customProperties", customProperties);
60
+ }
36
61
  if (downloadUrl != null) {
37
62
  result.put("downloadUrl", downloadUrl);
38
63
  }
64
+ if (signature != null) {
65
+ result.put("signature", signature);
66
+ }
39
67
  return result;
40
68
  }
41
69
  }
@@ -0,0 +1,32 @@
1
+ package io.capawesome.capacitorjs.plugins.liveupdate.classes.results;
2
+
3
+ import androidx.annotation.Nullable;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.liveupdate.LiveUpdate;
6
+ import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
7
+ import org.json.JSONObject;
8
+
9
+ public class ReadyResult implements Result {
10
+
11
+ @Nullable
12
+ private String currentBundleId;
13
+
14
+ @Nullable
15
+ private String previousBundleId;
16
+
17
+ private boolean rollback;
18
+
19
+ public ReadyResult(@Nullable String currentBundleId, @Nullable String previousBundleId, boolean rollback) {
20
+ this.currentBundleId = currentBundleId;
21
+ this.previousBundleId = previousBundleId;
22
+ this.rollback = rollback;
23
+ }
24
+
25
+ public JSObject toJSObject() {
26
+ JSObject result = new JSObject();
27
+ result.put("currentBundleId", currentBundleId == null ? JSONObject.NULL : currentBundleId);
28
+ result.put("previousBundleId", previousBundleId == null ? JSONObject.NULL : previousBundleId);
29
+ result.put("rollback", rollback);
30
+ return result;
31
+ }
32
+ }
@@ -0,0 +1,5 @@
1
+ package io.capawesome.capacitorjs.plugins.liveupdate.interfaces;
2
+
3
+ public interface DownloadProgressCallback {
4
+ void onProgress(long downloadedBytes, long totalBytes);
5
+ }