@capgo/capacitor-updater 4.0.0-alpha.7 → 4.0.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.
- package/LICENCE +160 -656
- package/README.md +141 -21
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +21 -9
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +90 -51
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +214 -120
- package/dist/docs.json +390 -19
- package/dist/esm/definitions.d.ts +72 -14
- package/dist/esm/web.d.ts +4 -2
- package/dist/esm/web.js +6 -2
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +6 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +6 -2
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/BundleInfo.swift +22 -11
- package/ios/Plugin/CapacitorUpdater.swift +139 -77
- package/ios/Plugin/CapacitorUpdaterPlugin.m +2 -1
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +145 -126
- package/ios/Plugin/ObjectPreferences.swift +1 -57
- package/package.json +3 -3
|
@@ -28,13 +28,20 @@ import io.github.g00fy2.versioncompare.Version;
|
|
|
28
28
|
import org.json.JSONException;
|
|
29
29
|
|
|
30
30
|
import java.io.IOException;
|
|
31
|
+
import java.net.MalformedURLException;
|
|
32
|
+
import java.net.URL;
|
|
33
|
+
import java.text.SimpleDateFormat;
|
|
34
|
+
import java.util.Date;
|
|
35
|
+
import java.util.Iterator;
|
|
31
36
|
import java.util.List;
|
|
37
|
+
import java.util.UUID;
|
|
32
38
|
|
|
33
39
|
@CapacitorPlugin(name = "CapacitorUpdater")
|
|
34
40
|
public class CapacitorUpdaterPlugin extends Plugin implements Application.ActivityLifecycleCallbacks {
|
|
35
|
-
private static final String updateUrlDefault = "https://
|
|
36
|
-
private static final String statsUrlDefault = "https://
|
|
41
|
+
private static final String updateUrlDefault = "https://api.capgo.app/updates";
|
|
42
|
+
private static final String statsUrlDefault = "https://api.capgo.app/stats";
|
|
37
43
|
private static final String DELAY_UPDATE = "delayUpdate";
|
|
44
|
+
private static final String DELAY_UPDATE_VAL = "delayUpdateVal";
|
|
38
45
|
|
|
39
46
|
private SharedPreferences.Editor editor;
|
|
40
47
|
private SharedPreferences prefs;
|
|
@@ -80,10 +87,12 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
80
87
|
this.implementation.appId = config.getString("appId", "");
|
|
81
88
|
this.implementation.statsUrl = this.getConfig().getString("statsUrl", statsUrlDefault);
|
|
82
89
|
this.implementation.documentsDir = this.getContext().getFilesDir();
|
|
83
|
-
this.implementation.prefs = this.
|
|
84
|
-
this.implementation.editor = this.
|
|
90
|
+
this.implementation.prefs = this.prefs;
|
|
91
|
+
this.implementation.editor = this.editor;
|
|
85
92
|
this.implementation.versionOs = Build.VERSION.RELEASE;
|
|
86
|
-
this.implementation.deviceID =
|
|
93
|
+
this.implementation.deviceID = this.prefs.getString("appUUID", UUID.randomUUID().toString());
|
|
94
|
+
this.editor.putString("appUUID", this.implementation.deviceID);
|
|
95
|
+
Log.e(CapacitorUpdater.TAG, "init for device " + this.implementation.deviceID);
|
|
87
96
|
|
|
88
97
|
this.autoDeleteFailed = this.getConfig().getBoolean("autoDeleteFailed", true);
|
|
89
98
|
this.autoDeletePrevious = this.getConfig().getBoolean("autoDeletePrevious", true);
|
|
@@ -97,8 +106,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
97
106
|
}
|
|
98
107
|
final Application application = (Application) this.getContext().getApplicationContext();
|
|
99
108
|
application.registerActivityLifecycleCallbacks(this);
|
|
100
|
-
|
|
101
109
|
this.onActivityStarted(this.getActivity());
|
|
110
|
+
this._checkCancelDelay(true);
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
private void cleanupObsoleteVersions() {
|
|
@@ -133,7 +142,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
133
142
|
try {
|
|
134
143
|
final JSObject ret = new JSObject();
|
|
135
144
|
ret.put("percent", percent);
|
|
136
|
-
|
|
145
|
+
JSObject bundle = this.implementation.getBundleInfo(id).toJSON();
|
|
137
146
|
ret.put("bundle", bundle);
|
|
138
147
|
this.notifyListeners("download", ret);
|
|
139
148
|
if (percent == 100) {
|
|
@@ -146,10 +155,10 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
146
155
|
|
|
147
156
|
|
|
148
157
|
@PluginMethod
|
|
149
|
-
public void
|
|
158
|
+
public void getDeviceId(final PluginCall call) {
|
|
150
159
|
try {
|
|
151
160
|
final JSObject ret = new JSObject();
|
|
152
|
-
ret.put("
|
|
161
|
+
ret.put("deviceId", this.implementation.deviceID);
|
|
153
162
|
call.resolve(ret);
|
|
154
163
|
} catch (final Exception e) {
|
|
155
164
|
Log.e(CapacitorUpdater.TAG, "Could not get device id", e);
|
|
@@ -173,8 +182,14 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
173
182
|
public void download(final PluginCall call) {
|
|
174
183
|
final String url = call.getString("url");
|
|
175
184
|
final String version = call.getString("version");
|
|
176
|
-
if (url == null
|
|
177
|
-
|
|
185
|
+
if (url == null) {
|
|
186
|
+
Log.e(CapacitorUpdater.TAG, "Download called without url");
|
|
187
|
+
call.reject("Download called without url");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (version == null) {
|
|
191
|
+
Log.e(CapacitorUpdater.TAG, "Download called without version");
|
|
192
|
+
call.reject("Download called without version");
|
|
178
193
|
return;
|
|
179
194
|
}
|
|
180
195
|
try {
|
|
@@ -189,6 +204,9 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
189
204
|
} catch (final IOException e) {
|
|
190
205
|
Log.e(CapacitorUpdater.TAG, "download failed", e);
|
|
191
206
|
call.reject("download failed", e);
|
|
207
|
+
final JSObject ret = new JSObject();
|
|
208
|
+
ret.put("version", version);
|
|
209
|
+
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
192
210
|
}
|
|
193
211
|
}
|
|
194
212
|
}).start();
|
|
@@ -216,6 +234,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
216
234
|
if (this._reload()) {
|
|
217
235
|
call.resolve();
|
|
218
236
|
} else {
|
|
237
|
+
Log.e(CapacitorUpdater.TAG, "Reload failed");
|
|
219
238
|
call.reject("Reload failed");
|
|
220
239
|
}
|
|
221
240
|
} catch(final Exception e) {
|
|
@@ -227,10 +246,15 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
227
246
|
@PluginMethod
|
|
228
247
|
public void next(final PluginCall call) {
|
|
229
248
|
final String id = call.getString("id");
|
|
230
|
-
|
|
249
|
+
if (id == null) {
|
|
250
|
+
Log.e(CapacitorUpdater.TAG, "Next called without id");
|
|
251
|
+
call.reject("Next called without id");
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
231
254
|
try {
|
|
232
255
|
Log.i(CapacitorUpdater.TAG, "Setting next active id " + id);
|
|
233
|
-
if (!this.implementation.
|
|
256
|
+
if (!this.implementation.setNextBundle(id)) {
|
|
257
|
+
Log.e(CapacitorUpdater.TAG, "Set next id failed. Bundle " + id + " does not exist.");
|
|
234
258
|
call.reject("Set next id failed. Bundle " + id + " does not exist.");
|
|
235
259
|
} else {
|
|
236
260
|
call.resolve(this.implementation.getBundleInfo(id).toJSON());
|
|
@@ -244,7 +268,11 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
244
268
|
@PluginMethod
|
|
245
269
|
public void set(final PluginCall call) {
|
|
246
270
|
final String id = call.getString("id");
|
|
247
|
-
|
|
271
|
+
if (id == null) {
|
|
272
|
+
Log.e(CapacitorUpdater.TAG, "Set called without id");
|
|
273
|
+
call.reject("Set called without id");
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
248
276
|
try {
|
|
249
277
|
Log.i(CapacitorUpdater.TAG, "Setting active bundle " + id);
|
|
250
278
|
if (!this.implementation.set(id)) {
|
|
@@ -263,12 +291,18 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
263
291
|
@PluginMethod
|
|
264
292
|
public void delete(final PluginCall call) {
|
|
265
293
|
final String id = call.getString("id");
|
|
294
|
+
if (id == null) {
|
|
295
|
+
Log.e(CapacitorUpdater.TAG, "missing id");
|
|
296
|
+
call.reject("missing id");
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
266
299
|
Log.i(CapacitorUpdater.TAG, "Deleting id: " + id);
|
|
267
300
|
try {
|
|
268
301
|
final Boolean res = this.implementation.delete(id);
|
|
269
302
|
if (res) {
|
|
270
303
|
call.resolve();
|
|
271
304
|
} else {
|
|
305
|
+
Log.e(CapacitorUpdater.TAG, "Delete failed, id " + id + " does not exist");
|
|
272
306
|
call.reject("Delete failed, id " + id + " does not exist");
|
|
273
307
|
}
|
|
274
308
|
} catch(final Exception e) {
|
|
@@ -302,14 +336,26 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
302
336
|
@Override
|
|
303
337
|
public void run() {
|
|
304
338
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, (res) -> {
|
|
305
|
-
|
|
339
|
+
final JSObject ret = new JSObject();
|
|
340
|
+
Iterator<String> keys = res.keys();
|
|
341
|
+
while(keys.hasNext()) {
|
|
342
|
+
String key = keys.next();
|
|
343
|
+
if (res.has(key)) {
|
|
344
|
+
try {
|
|
345
|
+
ret.put(key, res.get(key));
|
|
346
|
+
} catch (JSONException e) {
|
|
347
|
+
e.printStackTrace();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
call.resolve(ret);
|
|
306
352
|
});
|
|
307
353
|
}
|
|
308
354
|
});
|
|
309
355
|
}
|
|
310
356
|
|
|
311
357
|
private boolean _reset(final Boolean toLastSuccessful) {
|
|
312
|
-
final BundleInfo fallback = this.implementation.
|
|
358
|
+
final BundleInfo fallback = this.implementation.getFallbackBundle();
|
|
313
359
|
this.implementation.reset();
|
|
314
360
|
|
|
315
361
|
if (toLastSuccessful && !fallback.isBuiltin()) {
|
|
@@ -329,6 +375,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
329
375
|
call.resolve();
|
|
330
376
|
return;
|
|
331
377
|
}
|
|
378
|
+
Log.e(CapacitorUpdater.TAG, "Reset failed");
|
|
332
379
|
call.reject("Reset failed");
|
|
333
380
|
}
|
|
334
381
|
catch(final Exception e) {
|
|
@@ -355,9 +402,9 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
355
402
|
@PluginMethod
|
|
356
403
|
public void notifyAppReady(final PluginCall call) {
|
|
357
404
|
try {
|
|
358
|
-
Log.i(CapacitorUpdater.TAG, "Current bundle loaded successfully. ['notifyAppReady()' was called]");
|
|
359
405
|
final BundleInfo bundle = this.implementation.getCurrentBundle();
|
|
360
|
-
this.implementation.
|
|
406
|
+
this.implementation.setSuccess(bundle, this.autoDeletePrevious);
|
|
407
|
+
Log.i(CapacitorUpdater.TAG, "Current bundle loaded successfully. ['notifyAppReady()' was called] " + bundle.toString());
|
|
361
408
|
call.resolve();
|
|
362
409
|
}
|
|
363
410
|
catch(final Exception e) {
|
|
@@ -367,11 +414,19 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
367
414
|
}
|
|
368
415
|
|
|
369
416
|
@PluginMethod
|
|
370
|
-
public void
|
|
417
|
+
public void setDelay(final PluginCall call) {
|
|
371
418
|
try {
|
|
372
|
-
|
|
373
|
-
|
|
419
|
+
final String kind = call.getString("kind");
|
|
420
|
+
final String value = call.getString("value");
|
|
421
|
+
if (kind == null) {
|
|
422
|
+
Log.e(CapacitorUpdater.TAG, "setDelay called without kind");
|
|
423
|
+
call.reject("setDelay called without kind");
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
this.editor.putString(DELAY_UPDATE, kind);
|
|
427
|
+
this.editor.putString(DELAY_UPDATE_VAL, value);
|
|
374
428
|
this.editor.commit();
|
|
429
|
+
Log.i(CapacitorUpdater.TAG, "Delay update saved");
|
|
375
430
|
call.resolve();
|
|
376
431
|
}
|
|
377
432
|
catch(final Exception e) {
|
|
@@ -380,17 +435,63 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
380
435
|
}
|
|
381
436
|
}
|
|
382
437
|
|
|
383
|
-
|
|
384
|
-
public void cancelDelay(final PluginCall call) {
|
|
438
|
+
private boolean _cancelDelay(String source) {
|
|
385
439
|
try {
|
|
386
|
-
|
|
387
|
-
this.editor.
|
|
440
|
+
this.editor.remove(DELAY_UPDATE);
|
|
441
|
+
this.editor.remove(DELAY_UPDATE_VAL);
|
|
388
442
|
this.editor.commit();
|
|
389
|
-
|
|
443
|
+
Log.i(CapacitorUpdater.TAG, "delay canceled from " + source);
|
|
444
|
+
return true;
|
|
390
445
|
}
|
|
391
446
|
catch(final Exception e) {
|
|
392
447
|
Log.e(CapacitorUpdater.TAG, "Failed to cancel update delay", e);
|
|
393
|
-
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
@PluginMethod
|
|
453
|
+
public void cancelDelay(final PluginCall call) {
|
|
454
|
+
if(this._cancelDelay("JS")) {
|
|
455
|
+
call.resolve();
|
|
456
|
+
} else {
|
|
457
|
+
call.reject("Failed to cancel delay");
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
private void _checkCancelDelay(Boolean killed) {
|
|
462
|
+
final String delayUpdate = this.prefs.getString(DELAY_UPDATE, "");
|
|
463
|
+
if ("".equals(delayUpdate)) {
|
|
464
|
+
if ("background".equals(delayUpdate) && !killed) {
|
|
465
|
+
this._cancelDelay("background check");
|
|
466
|
+
} else if ("kill".equals(delayUpdate) && killed) {
|
|
467
|
+
this._cancelDelay("kill check");
|
|
468
|
+
}
|
|
469
|
+
final String delayVal = this.prefs.getString(DELAY_UPDATE_VAL, "");
|
|
470
|
+
if ("".equals(delayVal)) {
|
|
471
|
+
this._cancelDelay("delayVal absent");
|
|
472
|
+
} else if ("date".equals(delayUpdate)) {
|
|
473
|
+
try {
|
|
474
|
+
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
|
475
|
+
Date date = sdf.parse(delayVal);
|
|
476
|
+
if (date.compareTo(new Date()) > 0) {
|
|
477
|
+
this._cancelDelay("date expired");
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
catch(final Exception e) {
|
|
481
|
+
this._cancelDelay("date parsing issue");
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
} else if ("nativeVersion".equals(delayUpdate)) {
|
|
485
|
+
try {
|
|
486
|
+
final Version versionLimit = new Version(delayVal);
|
|
487
|
+
if (this.currentVersionNative.isAtLeast(versionLimit)) {
|
|
488
|
+
this._cancelDelay("nativeVersion above limit");
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
catch(final Exception e) {
|
|
492
|
+
this._cancelDelay("nativeVersion parsing issue");
|
|
493
|
+
}
|
|
494
|
+
}
|
|
394
495
|
}
|
|
395
496
|
}
|
|
396
497
|
|
|
@@ -422,6 +523,16 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
422
523
|
}
|
|
423
524
|
}
|
|
424
525
|
|
|
526
|
+
private boolean isValidURL(String urlStr) {
|
|
527
|
+
try {
|
|
528
|
+
URL url = new URL(urlStr);
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
catch (MalformedURLException e) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
425
536
|
@Override // appMovedToForeground
|
|
426
537
|
public void onActivityStarted(@NonNull final Activity activity) {
|
|
427
538
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled()) {
|
|
@@ -431,17 +542,27 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
431
542
|
|
|
432
543
|
Log.i(CapacitorUpdater.TAG, "Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl);
|
|
433
544
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, (res) -> {
|
|
545
|
+
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
434
546
|
try {
|
|
435
547
|
if (res.has("message")) {
|
|
436
|
-
Log.i(CapacitorUpdater.TAG, "message
|
|
548
|
+
Log.i(CapacitorUpdater.TAG, "message " + res.get("message"));
|
|
437
549
|
if (res.has("major") && res.getBoolean("major") && res.has("version")) {
|
|
438
550
|
final JSObject majorAvailable = new JSObject();
|
|
439
551
|
majorAvailable.put("version", (String) res.get("version"));
|
|
440
552
|
CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", majorAvailable);
|
|
441
553
|
}
|
|
554
|
+
final JSObject retNoNeed = new JSObject();
|
|
555
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
556
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
442
557
|
return;
|
|
443
558
|
}
|
|
444
|
-
|
|
559
|
+
|
|
560
|
+
if (!res.has("url") || CapacitorUpdaterPlugin.this.isValidURL((String)res.get("url"))) {
|
|
561
|
+
Log.e(CapacitorUpdater.TAG, "Error no url or wrong format");
|
|
562
|
+
final JSObject retNoNeed = new JSObject();
|
|
563
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
564
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
565
|
+
}
|
|
445
566
|
final String latestVersionName = (String) res.get("version");
|
|
446
567
|
|
|
447
568
|
if (latestVersionName != null && !"".equals(latestVersionName) && !current.getVersionName().equals(latestVersionName)) {
|
|
@@ -450,11 +571,17 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
450
571
|
if(latest != null) {
|
|
451
572
|
if(latest.isErrorStatus()) {
|
|
452
573
|
Log.e(CapacitorUpdater.TAG, "Latest bundle already exists, and is in error state. Aborting update.");
|
|
574
|
+
final JSObject retNoNeed = new JSObject();
|
|
575
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
576
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
453
577
|
return;
|
|
454
578
|
}
|
|
455
579
|
if(latest.isDownloaded()){
|
|
456
580
|
Log.e(CapacitorUpdater.TAG, "Latest bundle already exists and download is NOT required. Update will occur next time app moves to background.");
|
|
457
|
-
|
|
581
|
+
final JSObject ret = new JSObject();
|
|
582
|
+
ret.put("bundle", latest.toJSON());
|
|
583
|
+
CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
|
|
584
|
+
CapacitorUpdaterPlugin.this.implementation.setNextBundle(latest.getId());
|
|
458
585
|
return;
|
|
459
586
|
}
|
|
460
587
|
}
|
|
@@ -468,18 +595,32 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
468
595
|
|
|
469
596
|
final String url = (String) res.get("url");
|
|
470
597
|
final BundleInfo next = CapacitorUpdaterPlugin.this.implementation.download(url, latestVersionName);
|
|
471
|
-
|
|
472
|
-
|
|
598
|
+
final JSObject ret = new JSObject();
|
|
599
|
+
ret.put("bundle", next.toJSON());
|
|
600
|
+
CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
|
|
601
|
+
CapacitorUpdaterPlugin.this.implementation.setNextBundle(next.getId());
|
|
473
602
|
} catch (final Exception e) {
|
|
474
603
|
Log.e(CapacitorUpdater.TAG, "error downloading file", e);
|
|
604
|
+
final JSObject ret = new JSObject();
|
|
605
|
+
ret.put("version", latestVersionName);
|
|
606
|
+
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
607
|
+
final JSObject retNoNeed = new JSObject();
|
|
608
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
609
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
475
610
|
}
|
|
476
611
|
}
|
|
477
612
|
}).start();
|
|
478
613
|
} else {
|
|
479
|
-
Log.i(CapacitorUpdater.TAG, "No need to update, " + current + " is the latest bundle.");
|
|
614
|
+
Log.i(CapacitorUpdater.TAG, "No need to update, " + current.getId() + " is the latest bundle.");
|
|
615
|
+
final JSObject retNoNeed = new JSObject();
|
|
616
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
617
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
480
618
|
}
|
|
481
619
|
} catch (final JSONException e) {
|
|
482
620
|
Log.e(CapacitorUpdater.TAG, "error parsing JSON", e);
|
|
621
|
+
final JSObject retNoNeed = new JSObject();
|
|
622
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
623
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
483
624
|
}
|
|
484
625
|
});
|
|
485
626
|
}
|
|
@@ -493,96 +634,63 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
493
634
|
public void onActivityStopped(@NonNull final Activity activity) {
|
|
494
635
|
Log.i(CapacitorUpdater.TAG, "Checking for pending update");
|
|
495
636
|
try {
|
|
496
|
-
final
|
|
497
|
-
this.
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (delayUpdate) {
|
|
637
|
+
final String delayUpdate = this.prefs.getString(DELAY_UPDATE, "");
|
|
638
|
+
this._checkCancelDelay(false);
|
|
639
|
+
if (!"".equals(delayUpdate)) {
|
|
501
640
|
Log.i(CapacitorUpdater.TAG, "Update delayed to next backgrounding");
|
|
502
641
|
return;
|
|
503
642
|
}
|
|
504
|
-
|
|
505
|
-
final BundleInfo fallback = this.implementation.getFallbackVersion();
|
|
506
643
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
507
|
-
final BundleInfo next = this.implementation.
|
|
508
|
-
|
|
509
|
-
final Boolean success = current.getStatus() == BundleStatus.SUCCESS;
|
|
510
|
-
|
|
511
|
-
Log.d(CapacitorUpdater.TAG, "Fallback bundle is: " + fallback);
|
|
512
|
-
Log.d(CapacitorUpdater.TAG, "Current bundle is: " + current);
|
|
644
|
+
final BundleInfo next = this.implementation.getNextBundle();
|
|
513
645
|
|
|
514
|
-
if (next != null && !next.isErrorStatus() &&
|
|
646
|
+
if (next != null && !next.isErrorStatus() && next.getId() != current.getId()) {
|
|
515
647
|
// There is a next bundle waiting for activation
|
|
516
648
|
Log.d(CapacitorUpdater.TAG, "Next bundle is: " + next.getVersionName());
|
|
517
649
|
if (this.implementation.set(next) && this._reload()) {
|
|
518
650
|
Log.i(CapacitorUpdater.TAG, "Updated to bundle: " + next.getVersionName());
|
|
519
|
-
this.implementation.
|
|
651
|
+
this.implementation.setNextBundle(null);
|
|
520
652
|
} else {
|
|
521
653
|
Log.e(CapacitorUpdater.TAG, "Update to bundle: " + next.getVersionName() + " Failed!");
|
|
522
654
|
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
this.implementation.rollback(current);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
catch(final Exception e) {
|
|
658
|
+
Log.e(CapacitorUpdater.TAG, "Error during onActivityStopped", e);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
530
661
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
Log.i(CapacitorUpdater.TAG, "Did you forget to call 'notifyAppReady()' in your Capacitor App code?");
|
|
535
|
-
final JSObject ret = new JSObject();
|
|
536
|
-
ret.put("bundle", current);
|
|
537
|
-
this.notifyListeners("updateFailed", ret);
|
|
538
|
-
this.implementation.sendStats("revert", current);
|
|
539
|
-
if (!fallback.isBuiltin() && !fallback.equals(current)) {
|
|
540
|
-
final Boolean res = this.implementation.set(fallback);
|
|
541
|
-
if (res && this._reload()) {
|
|
542
|
-
Log.i(CapacitorUpdater.TAG, "Revert to bundle: " + fallback.getVersionName());
|
|
543
|
-
} else {
|
|
544
|
-
Log.e(CapacitorUpdater.TAG, "Revert to bundle: " + fallback.getVersionName() + " Failed!");
|
|
545
|
-
}
|
|
546
|
-
} else {
|
|
547
|
-
if (this._reset(false)) {
|
|
548
|
-
Log.i(CapacitorUpdater.TAG, "Reverted to 'builtin' bundle.");
|
|
549
|
-
}
|
|
550
|
-
}
|
|
662
|
+
private void checkRevert() {
|
|
663
|
+
// Automatically roll back to fallback version if notifyAppReady has not been called yet
|
|
664
|
+
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
551
665
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
Log.i(CapacitorUpdater.TAG, "Failed bundle deleted: " + current.getVersionName());
|
|
558
|
-
}
|
|
559
|
-
} catch (final IOException e) {
|
|
560
|
-
Log.e(CapacitorUpdater.TAG, "Failed to delete failed bundle: " + current.getVersionName(), e);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
} else {
|
|
564
|
-
// Nothing we can/should do by default if the 'builtin' bundle fails to call 'notifyAppReady()'.
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
} else if (!fallback.isBuiltin()) {
|
|
568
|
-
// There is a no next bundle, and the current bundle has succeeded
|
|
569
|
-
this.implementation.commit(current);
|
|
666
|
+
if(current.isBuiltin()) {
|
|
667
|
+
Log.i(CapacitorUpdater.TAG, "Built-in bundle is active. Nothing to do.");
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
Log.d(CapacitorUpdater.TAG, "Current bundle is: " + current);
|
|
570
671
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
672
|
+
if(BundleStatus.SUCCESS != current.getStatus()) {
|
|
673
|
+
Log.e(CapacitorUpdater.TAG, "notifyAppReady was not called, roll back current bundle: " + current.getId());
|
|
674
|
+
Log.i(CapacitorUpdater.TAG, "Did you forget to call 'notifyAppReady()' in your Capacitor App code?");
|
|
675
|
+
final JSObject ret = new JSObject();
|
|
676
|
+
ret.put("bundle", current.toJSON());
|
|
677
|
+
this.notifyListeners("updateFailed", ret);
|
|
678
|
+
this.implementation.sendStats("update_fail", current.getVersionName());
|
|
679
|
+
this.implementation.setError(current);
|
|
680
|
+
this._reset(true);
|
|
681
|
+
if (CapacitorUpdaterPlugin.this.autoDeleteFailed && !current.isBuiltin()) {
|
|
682
|
+
Log.i(CapacitorUpdater.TAG, "Deleting failing bundle: " + current.getVersionName());
|
|
683
|
+
try {
|
|
684
|
+
final Boolean res = this.implementation.delete(current.getId(), false);
|
|
685
|
+
if (res) {
|
|
686
|
+
Log.i(CapacitorUpdater.TAG, "Failed bundle deleted: " + current.getVersionName());
|
|
580
687
|
}
|
|
688
|
+
} catch (final IOException e) {
|
|
689
|
+
Log.e(CapacitorUpdater.TAG, "Failed to delete failed bundle: " + current.getVersionName(), e);
|
|
581
690
|
}
|
|
582
691
|
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
Log.e(CapacitorUpdater.TAG, "Error during onActivityStopped", e);
|
|
692
|
+
} else {
|
|
693
|
+
Log.i(CapacitorUpdater.TAG, "notifyAppReady was called. This is fine: " + current.getId());
|
|
586
694
|
}
|
|
587
695
|
}
|
|
588
696
|
|
|
@@ -592,21 +700,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
592
700
|
try {
|
|
593
701
|
Log.i(CapacitorUpdater.TAG, "Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady");
|
|
594
702
|
Thread.sleep(CapacitorUpdaterPlugin.this.appReadyTimeout);
|
|
595
|
-
|
|
596
|
-
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
597
|
-
if(current.isBuiltin()) {
|
|
598
|
-
Log.i(CapacitorUpdater.TAG, "Built-in bundle is active. Nothing to do.");
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
if(BundleStatus.SUCCESS != current.getStatus()) {
|
|
603
|
-
Log.e(CapacitorUpdater.TAG, "notifyAppReady was not called, roll back current bundle: " + current.getId());
|
|
604
|
-
CapacitorUpdaterPlugin.this.implementation.rollback(current);
|
|
605
|
-
CapacitorUpdaterPlugin.this._reset(true);
|
|
606
|
-
} else {
|
|
607
|
-
Log.i(CapacitorUpdater.TAG, "notifyAppReady was called. This is fine: " + current.getId());
|
|
608
|
-
}
|
|
609
|
-
|
|
703
|
+
CapacitorUpdaterPlugin.this.checkRevert();
|
|
610
704
|
CapacitorUpdaterPlugin.this.appReadyCheck = null;
|
|
611
705
|
} catch (final InterruptedException e) {
|
|
612
706
|
Log.e(CapacitorUpdater.TAG, DeferredNotifyAppReadyCheck.class.getName() + " was interrupted.");
|