@capgo/capacitor-updater 4.0.0-alpha.31 → 4.0.0-alpha.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +21 -9
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +32 -13
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +55 -79
- package/dist/docs.json +115 -13
- package/dist/esm/definitions.d.ts +27 -11
- package/dist/esm/web.js +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/BundleInfo.swift +20 -9
- package/ios/Plugin/CapacitorUpdater.swift +30 -9
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +37 -68
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -133,6 +133,7 @@ Capacitor Updator works by unzipping a compiled app bundle to the native device
|
|
|
133
133
|
* [`addListener('downloadComplete', ...)`](#addlistenerdownloadcomplete)
|
|
134
134
|
* [`addListener('majorAvailable', ...)`](#addlistenermajoravailable)
|
|
135
135
|
* [`addListener('updateFailed', ...)`](#addlistenerupdatefailed)
|
|
136
|
+
* [`addListener('downloadFailed', ...)`](#addlistenerdownloadfailed)
|
|
136
137
|
* [`getId()`](#getid)
|
|
137
138
|
* [`getPluginVersion()`](#getpluginversion)
|
|
138
139
|
* [`isAutoUpdateEnabled()`](#isautoupdateenabled)
|
|
@@ -390,7 +391,7 @@ Listen for Major update event in the App, let you know when major update is bloc
|
|
|
390
391
|
addListener(eventName: 'updateFailed', listenerFunc: UpdateFailedListener) => Promise<PluginListenerHandle> & PluginListenerHandle
|
|
391
392
|
```
|
|
392
393
|
|
|
393
|
-
Listen for update fail event in the App, let you know when update
|
|
394
|
+
Listen for update fail event in the App, let you know when update has fail to install at next app start
|
|
394
395
|
|
|
395
396
|
| Param | Type |
|
|
396
397
|
| ------------------ | --------------------------------------------------------------------- |
|
|
@@ -404,6 +405,26 @@ Listen for update fail event in the App, let you know when update hs fail to ins
|
|
|
404
405
|
--------------------
|
|
405
406
|
|
|
406
407
|
|
|
408
|
+
### addListener('downloadFailed', ...)
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
addListener(eventName: 'downloadFailed', listenerFunc: DownloadFailedListener) => Promise<PluginListenerHandle> & PluginListenerHandle
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Listen for download fail event in the App, let you know when download has fail finished
|
|
415
|
+
|
|
416
|
+
| Param | Type |
|
|
417
|
+
| ------------------ | ------------------------------------------------------------------------- |
|
|
418
|
+
| **`eventName`** | <code>'downloadFailed'</code> |
|
|
419
|
+
| **`listenerFunc`** | <code><a href="#downloadfailedlistener">DownloadFailedListener</a></code> |
|
|
420
|
+
|
|
421
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>> & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
|
|
422
|
+
|
|
423
|
+
**Since:** 4.0.0
|
|
424
|
+
|
|
425
|
+
--------------------
|
|
426
|
+
|
|
427
|
+
|
|
407
428
|
### getId()
|
|
408
429
|
|
|
409
430
|
```typescript
|
|
@@ -478,6 +499,7 @@ removeAllListeners() => Promise<void>
|
|
|
478
499
|
| **`id`** | <code>string</code> |
|
|
479
500
|
| **`version`** | <code>string</code> |
|
|
480
501
|
| **`downloaded`** | <code>string</code> |
|
|
502
|
+
| **`checksum`** | <code>string</code> |
|
|
481
503
|
| **`status`** | <code><a href="#bundlestatus">BundleStatus</a></code> |
|
|
482
504
|
|
|
483
505
|
|
|
@@ -528,6 +550,13 @@ removeAllListeners() => Promise<void>
|
|
|
528
550
|
| **`bundle`** | <code><a href="#bundleinfo">BundleInfo</a></code> | Emit when a update failed to install. | 4.0.0 |
|
|
529
551
|
|
|
530
552
|
|
|
553
|
+
#### DownloadFailedEvent
|
|
554
|
+
|
|
555
|
+
| Prop | Type | Description | Since |
|
|
556
|
+
| ------------- | ------------------- | ------------------------------------------- | ----- |
|
|
557
|
+
| **`version`** | <code>string</code> | Emit when a new major version is available. | 4.0.0 |
|
|
558
|
+
|
|
559
|
+
|
|
531
560
|
### Type Aliases
|
|
532
561
|
|
|
533
562
|
|
|
@@ -560,6 +589,11 @@ removeAllListeners() => Promise<void>
|
|
|
560
589
|
|
|
561
590
|
<code>(state: <a href="#updatefailedevent">UpdateFailedEvent</a>): void</code>
|
|
562
591
|
|
|
592
|
+
|
|
593
|
+
#### DownloadFailedListener
|
|
594
|
+
|
|
595
|
+
<code>(state: <a href="#downloadfailedevent">DownloadFailedEvent</a>): void</code>
|
|
596
|
+
|
|
563
597
|
</docgen-api>
|
|
564
598
|
|
|
565
599
|
### Listen to download events
|
|
@@ -21,6 +21,7 @@ public class BundleInfo {
|
|
|
21
21
|
private final String downloaded;
|
|
22
22
|
private final String id;
|
|
23
23
|
private final String version;
|
|
24
|
+
private final String checksum;
|
|
24
25
|
private final BundleStatus status;
|
|
25
26
|
|
|
26
27
|
static {
|
|
@@ -28,17 +29,18 @@ public class BundleInfo {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
public BundleInfo(final BundleInfo source) {
|
|
31
|
-
this(source.id, source.version, source.status, source.downloaded);
|
|
32
|
+
this(source.id, source.version, source.status, source.downloaded, source.checksum);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
public BundleInfo(final String id, final String version, final BundleStatus status, final Date downloaded) {
|
|
35
|
-
this(id, version, status, sdf.format(downloaded));
|
|
35
|
+
public BundleInfo(final String id, final String version, final BundleStatus status, final Date downloaded, final String checksum) {
|
|
36
|
+
this(id, version, status, sdf.format(downloaded), checksum);
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
public BundleInfo(final String id, final String version, final BundleStatus status, final String downloaded) {
|
|
39
|
+
public BundleInfo(final String id, final String version, final BundleStatus status, final String downloaded, final String checksum) {
|
|
39
40
|
this.downloaded = downloaded.trim();
|
|
40
41
|
this.id = id;
|
|
41
42
|
this.version = version;
|
|
43
|
+
this.checksum = checksum;
|
|
42
44
|
this.status = status;
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -60,7 +62,15 @@ public class BundleInfo {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
public BundleInfo setDownloaded(Date downloaded) {
|
|
63
|
-
return new BundleInfo(this.id, this.version, this.status, downloaded);
|
|
65
|
+
return new BundleInfo(this.id, this.version, this.status, downloaded, this.checksum);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public String getChecksum() {
|
|
69
|
+
return this.isBuiltin() ? "" : this.checksum;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public BundleInfo setChecksum(String checksum) {
|
|
73
|
+
return new BundleInfo(this.id, this.version, this.status, this.downloaded, checksum);
|
|
64
74
|
}
|
|
65
75
|
|
|
66
76
|
public String getId() {
|
|
@@ -68,7 +78,7 @@ public class BundleInfo {
|
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
public BundleInfo setId(String id) {
|
|
71
|
-
return new BundleInfo(id, this.version, this.status, this.downloaded);
|
|
81
|
+
return new BundleInfo(id, this.version, this.status, this.downloaded, this.checksum);
|
|
72
82
|
}
|
|
73
83
|
|
|
74
84
|
public String getVersionName() {
|
|
@@ -76,7 +86,7 @@ public class BundleInfo {
|
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
public BundleInfo setVersionName(String version) {
|
|
79
|
-
return new BundleInfo(this.id, version, this.status, this.downloaded);
|
|
89
|
+
return new BundleInfo(this.id, version, this.status, this.downloaded, this.checksum);
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
public BundleStatus getStatus() {
|
|
@@ -84,7 +94,7 @@ public class BundleInfo {
|
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
public BundleInfo setStatus(BundleStatus status) {
|
|
87
|
-
return new BundleInfo(this.id, this.version, status, this.downloaded);
|
|
97
|
+
return new BundleInfo(this.id, this.version, status, this.downloaded, this.checksum);
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
public static BundleInfo fromJSON(final JSObject json) throws JSONException {
|
|
@@ -97,7 +107,8 @@ public class BundleInfo {
|
|
|
97
107
|
json.has("id") ? json.getString("id") : "",
|
|
98
108
|
json.has("version") ? json.getString("version") : BundleInfo.VERSION_UNKNOWN,
|
|
99
109
|
json.has("status") ? BundleStatus.fromString(json.getString("status")) : BundleStatus.PENDING,
|
|
100
|
-
json.has("downloaded") ? json.getString("downloaded") : ""
|
|
110
|
+
json.has("downloaded") ? json.getString("downloaded") : "",
|
|
111
|
+
json.has("checksum") ? json.getString("checksum") : ""
|
|
101
112
|
);
|
|
102
113
|
}
|
|
103
114
|
|
|
@@ -106,6 +117,7 @@ public class BundleInfo {
|
|
|
106
117
|
result.put("id", this.getId());
|
|
107
118
|
result.put("version", this.getVersionName());
|
|
108
119
|
result.put("downloaded", this.getDownloaded());
|
|
120
|
+
result.put("checksum", this.getChecksum());
|
|
109
121
|
result.put("status", this.getStatus());
|
|
110
122
|
return result;
|
|
111
123
|
}
|
|
@@ -28,6 +28,7 @@ import java.security.SecureRandom;
|
|
|
28
28
|
import java.util.ArrayList;
|
|
29
29
|
import java.util.Date;
|
|
30
30
|
import java.util.List;
|
|
31
|
+
import java.util.zip.CRC32;
|
|
31
32
|
import java.util.zip.ZipEntry;
|
|
32
33
|
import java.util.zip.ZipInputStream;
|
|
33
34
|
|
|
@@ -46,7 +47,7 @@ public class CapacitorUpdater {
|
|
|
46
47
|
private static final String bundleDirectory = "versions";
|
|
47
48
|
|
|
48
49
|
public static final String TAG = "Capacitor-updater";
|
|
49
|
-
public static final String pluginVersion = "4.0.0-alpha.
|
|
50
|
+
public static final String pluginVersion = "4.0.0-alpha.35";
|
|
50
51
|
|
|
51
52
|
public SharedPreferences.Editor editor;
|
|
52
53
|
public SharedPreferences prefs;
|
|
@@ -212,13 +213,25 @@ public class CapacitorUpdater {
|
|
|
212
213
|
this.editor.commit();
|
|
213
214
|
}
|
|
214
215
|
|
|
216
|
+
private String getChecksum(File file) throws IOException {
|
|
217
|
+
byte[] bytes = new byte[(int) file.length()];
|
|
218
|
+
try(FileInputStream fis = new FileInputStream(file)){
|
|
219
|
+
fis.read(bytes);
|
|
220
|
+
}
|
|
221
|
+
CRC32 crc = new CRC32();
|
|
222
|
+
crc.update(bytes);
|
|
223
|
+
String enc = String.format("%08X", crc.getValue());
|
|
224
|
+
return enc.toLowerCase();
|
|
225
|
+
}
|
|
226
|
+
|
|
215
227
|
public BundleInfo download(final String url, final String version) throws IOException {
|
|
216
228
|
final String id = this.randomString(10);
|
|
217
|
-
this.saveBundleInfo(id, new BundleInfo(id, version, BundleStatus.DOWNLOADING, new Date(System.currentTimeMillis())));
|
|
229
|
+
this.saveBundleInfo(id, new BundleInfo(id, version, BundleStatus.DOWNLOADING, new Date(System.currentTimeMillis()), ""));
|
|
218
230
|
this.notifyDownload(id, 0);
|
|
219
231
|
final String idName = bundleDirectory + "/" + id;
|
|
220
232
|
this.notifyDownload(id, 5);
|
|
221
233
|
final File downloaded = this.downloadFile(id, url, this.randomString(10));
|
|
234
|
+
final String checksum = this.getChecksum(downloaded);
|
|
222
235
|
this.notifyDownload(id, 71);
|
|
223
236
|
final File unzipped = this.unzip(id, downloaded, this.randomString(10));
|
|
224
237
|
downloaded.delete();
|
|
@@ -226,7 +239,7 @@ public class CapacitorUpdater {
|
|
|
226
239
|
this.flattenAssets(unzipped, idName);
|
|
227
240
|
this.notifyDownload(id, 100);
|
|
228
241
|
this.saveBundleInfo(id, null);
|
|
229
|
-
BundleInfo info = new BundleInfo(id, version, BundleStatus.PENDING, new Date(System.currentTimeMillis()));
|
|
242
|
+
BundleInfo info = new BundleInfo(id, version, BundleStatus.PENDING, new Date(System.currentTimeMillis()), checksum);
|
|
230
243
|
this.saveBundleInfo(id, info);
|
|
231
244
|
return info;
|
|
232
245
|
}
|
|
@@ -246,12 +259,14 @@ public class CapacitorUpdater {
|
|
|
246
259
|
return res;
|
|
247
260
|
}
|
|
248
261
|
|
|
249
|
-
public Boolean delete(final String id) throws IOException {
|
|
262
|
+
public Boolean delete(final String id, final Boolean removeInfo) throws IOException {
|
|
250
263
|
final BundleInfo deleted = this.getBundleInfo(id);
|
|
251
264
|
final File bundle = new File(this.documentsDir, bundleDirectory + "/" + id);
|
|
252
265
|
if (bundle.exists()) {
|
|
253
266
|
this.deleteDirectory(bundle);
|
|
254
|
-
|
|
267
|
+
if (removeInfo) {
|
|
268
|
+
this.removeBundleInfo(id);
|
|
269
|
+
}
|
|
255
270
|
return true;
|
|
256
271
|
}
|
|
257
272
|
Log.e(TAG, "Directory not removed: " + bundle.getPath());
|
|
@@ -259,6 +274,10 @@ public class CapacitorUpdater {
|
|
|
259
274
|
return false;
|
|
260
275
|
}
|
|
261
276
|
|
|
277
|
+
public Boolean delete(final String id) throws IOException {
|
|
278
|
+
return this.delete(id, true);
|
|
279
|
+
}
|
|
280
|
+
|
|
262
281
|
private File getBundleDirectory(final String id) {
|
|
263
282
|
return new File(this.documentsDir, bundleDirectory + "/" + id);
|
|
264
283
|
}
|
|
@@ -293,16 +312,16 @@ public class CapacitorUpdater {
|
|
|
293
312
|
return false;
|
|
294
313
|
}
|
|
295
314
|
|
|
296
|
-
public void commit(final BundleInfo bundle) {
|
|
297
|
-
this.setBundleStatus(bundle.getId(), BundleStatus.SUCCESS);
|
|
298
|
-
this.setFallbackBundle(bundle);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
315
|
public void reset() {
|
|
302
316
|
this.reset(false);
|
|
303
317
|
}
|
|
304
318
|
|
|
305
|
-
public void
|
|
319
|
+
public void setSuccess(final BundleInfo bundle) {
|
|
320
|
+
this.setBundleStatus(bundle.getId(), BundleStatus.SUCCESS);
|
|
321
|
+
this.setFallbackBundle(bundle);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
public void setError(final BundleInfo bundle) {
|
|
306
325
|
this.setBundleStatus(bundle.getId(), BundleStatus.ERROR);
|
|
307
326
|
}
|
|
308
327
|
|
|
@@ -404,14 +423,14 @@ public class CapacitorUpdater {
|
|
|
404
423
|
Log.d(TAG, "Getting info for bundle [" + id + "]");
|
|
405
424
|
BundleInfo result;
|
|
406
425
|
if(BundleInfo.ID_BUILTIN.equals(id)) {
|
|
407
|
-
result = new BundleInfo(id, (String) null, BundleStatus.SUCCESS, "");
|
|
426
|
+
result = new BundleInfo(id, (String) null, BundleStatus.SUCCESS, "", "");
|
|
408
427
|
} else {
|
|
409
428
|
try {
|
|
410
429
|
String stored = this.prefs.getString(id + INFO_SUFFIX, "");
|
|
411
430
|
result = BundleInfo.fromJSON(stored);
|
|
412
431
|
} catch (JSONException e) {
|
|
413
432
|
Log.e(TAG, "Failed to parse info for bundle [" + id + "] ", e);
|
|
414
|
-
result = new BundleInfo(id, (String) null, BundleStatus.PENDING, "");
|
|
433
|
+
result = new BundleInfo(id, (String) null, BundleStatus.PENDING, "", "");
|
|
415
434
|
}
|
|
416
435
|
}
|
|
417
436
|
|
|
@@ -202,6 +202,9 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
202
202
|
} catch (final IOException e) {
|
|
203
203
|
Log.e(CapacitorUpdater.TAG, "download failed", e);
|
|
204
204
|
call.reject("download failed", e);
|
|
205
|
+
final JSObject ret = new JSObject();
|
|
206
|
+
ret.put("version", version);
|
|
207
|
+
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
205
208
|
}
|
|
206
209
|
}
|
|
207
210
|
}).start();
|
|
@@ -399,7 +402,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
399
402
|
try {
|
|
400
403
|
Log.i(CapacitorUpdater.TAG, "Current bundle loaded successfully. ['notifyAppReady()' was called]");
|
|
401
404
|
final BundleInfo bundle = this.implementation.getCurrentBundle();
|
|
402
|
-
this.implementation.
|
|
405
|
+
this.implementation.setSuccess(bundle);
|
|
403
406
|
call.resolve();
|
|
404
407
|
}
|
|
405
408
|
catch(final Exception e) {
|
|
@@ -566,10 +569,15 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
566
569
|
|
|
567
570
|
final String url = (String) res.get("url");
|
|
568
571
|
final BundleInfo next = CapacitorUpdaterPlugin.this.implementation.download(url, latestVersionName);
|
|
569
|
-
|
|
572
|
+
final JSObject ret = new JSObject();
|
|
573
|
+
ret.put("bundle", next.toJSON());
|
|
574
|
+
CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
|
|
570
575
|
CapacitorUpdaterPlugin.this.implementation.setNextBundle(next.getId());
|
|
571
576
|
} catch (final Exception e) {
|
|
572
577
|
Log.e(CapacitorUpdater.TAG, "error downloading file", e);
|
|
578
|
+
final JSObject ret = new JSObject();
|
|
579
|
+
ret.put("version", latestVersionName);
|
|
580
|
+
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
573
581
|
}
|
|
574
582
|
}
|
|
575
583
|
}).start();
|
|
@@ -593,19 +601,13 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
593
601
|
try {
|
|
594
602
|
final String delayUpdate = this.prefs.getString(DELAY_UPDATE, "");
|
|
595
603
|
this._checkCancelDelay(false);
|
|
596
|
-
if ("".equals(delayUpdate)) {
|
|
604
|
+
if (!"".equals(delayUpdate)) {
|
|
597
605
|
Log.i(CapacitorUpdater.TAG, "Update delayed to next backgrounding");
|
|
598
606
|
return;
|
|
599
607
|
}
|
|
600
|
-
final BundleInfo fallback = this.implementation.getFallbackBundle();
|
|
601
608
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
602
609
|
final BundleInfo next = this.implementation.getNextBundle();
|
|
603
610
|
|
|
604
|
-
final Boolean success = current.getStatus() == BundleStatus.SUCCESS;
|
|
605
|
-
|
|
606
|
-
Log.d(CapacitorUpdater.TAG, "Fallback bundle is: " + fallback);
|
|
607
|
-
Log.d(CapacitorUpdater.TAG, "Current bundle is: " + current);
|
|
608
|
-
|
|
609
611
|
if (next != null && !next.isErrorStatus() && (next.getId() != current.getId())) {
|
|
610
612
|
// There is a next bundle waiting for activation
|
|
611
613
|
Log.d(CapacitorUpdater.TAG, "Next bundle is: " + next.getVersionName());
|
|
@@ -615,70 +617,58 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
615
617
|
} else {
|
|
616
618
|
Log.e(CapacitorUpdater.TAG, "Update to bundle: " + next.getVersionName() + " Failed!");
|
|
617
619
|
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
catch(final Exception e) {
|
|
623
|
+
Log.e(CapacitorUpdater.TAG, "Error during onActivityStopped", e);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
623
626
|
|
|
624
|
-
|
|
627
|
+
private void checkRevert() {
|
|
628
|
+
// Automatically roll back to fallback version if notifyAppReady has not been called yet
|
|
629
|
+
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
630
|
+
final BundleInfo fallback = this.implementation.getFallbackBundle();
|
|
625
631
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
this.notifyListeners("updateFailed", ret);
|
|
633
|
-
this.implementation.sendStats("update_fail", current.getVersionName());
|
|
634
|
-
if (!fallback.isBuiltin() && !fallback.equals(current)) {
|
|
635
|
-
final Boolean res = this.implementation.set(fallback);
|
|
636
|
-
if (res && this._reload()) {
|
|
637
|
-
Log.i(CapacitorUpdater.TAG, "Revert to bundle: " + fallback.getVersionName());
|
|
638
|
-
} else {
|
|
639
|
-
Log.e(CapacitorUpdater.TAG, "Revert to bundle: " + fallback.getVersionName() + " Failed!");
|
|
640
|
-
}
|
|
641
|
-
} else {
|
|
642
|
-
if (this._reset(false)) {
|
|
643
|
-
Log.i(CapacitorUpdater.TAG, "Reverted to 'builtin' bundle.");
|
|
644
|
-
}
|
|
645
|
-
}
|
|
632
|
+
if(current.isBuiltin()) {
|
|
633
|
+
Log.i(CapacitorUpdater.TAG, "Built-in bundle is active. Nothing to do.");
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
Log.d(CapacitorUpdater.TAG, "Fallback bundle is: " + fallback);
|
|
637
|
+
Log.d(CapacitorUpdater.TAG, "Current bundle is: " + current);
|
|
646
638
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
639
|
+
if(BundleStatus.SUCCESS != current.getStatus()) {
|
|
640
|
+
Log.e(CapacitorUpdater.TAG, "notifyAppReady was not called, roll back current bundle: " + current.getId());
|
|
641
|
+
Log.i(CapacitorUpdater.TAG, "Did you forget to call 'notifyAppReady()' in your Capacitor App code?");
|
|
642
|
+
final JSObject ret = new JSObject();
|
|
643
|
+
ret.put("bundle", current.toJSON());
|
|
644
|
+
this.notifyListeners("updateFailed", ret);
|
|
645
|
+
this.implementation.sendStats("update_fail", current.getVersionName());
|
|
646
|
+
this.implementation.setError(current);
|
|
647
|
+
this._reset(true);
|
|
648
|
+
if (CapacitorUpdaterPlugin.this.autoDeleteFailed) {
|
|
649
|
+
Log.i(CapacitorUpdater.TAG, "Deleting failing bundle: " + current.getVersionName());
|
|
650
|
+
try {
|
|
651
|
+
final Boolean res = this.implementation.delete(current.getId(), false);
|
|
652
|
+
if (res) {
|
|
653
|
+
Log.i(CapacitorUpdater.TAG, "Failed bundle deleted: " + current.getVersionName());
|
|
657
654
|
}
|
|
658
|
-
}
|
|
659
|
-
|
|
655
|
+
} catch (final IOException e) {
|
|
656
|
+
Log.e(CapacitorUpdater.TAG, "Failed to delete failed bundle: " + current.getVersionName(), e);
|
|
660
657
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
final Boolean res = this.implementation.delete(fallback.getVersionName());
|
|
670
|
-
if (res) {
|
|
671
|
-
Log.i(CapacitorUpdater.TAG, "Deleted previous bundle: " + fallback.getVersionName());
|
|
672
|
-
}
|
|
673
|
-
} catch (final IOException e) {
|
|
674
|
-
Log.e(CapacitorUpdater.TAG, "Failed to delete previous bundle: " + fallback.getVersionName(), e);
|
|
658
|
+
}
|
|
659
|
+
} else {
|
|
660
|
+
Log.i(CapacitorUpdater.TAG, "notifyAppReady was called. This is fine: " + current.getId());
|
|
661
|
+
if(this.autoDeletePrevious && !fallback.isBuiltin()) {
|
|
662
|
+
try {
|
|
663
|
+
final Boolean res = this.implementation.delete(fallback.getId());
|
|
664
|
+
if (res) {
|
|
665
|
+
Log.i(CapacitorUpdater.TAG, "Deleted previous bundle: " + fallback.getVersionName());
|
|
675
666
|
}
|
|
667
|
+
} catch (final IOException e) {
|
|
668
|
+
Log.e(CapacitorUpdater.TAG, "Failed to delete previous bundle: " + fallback.getVersionName(), e);
|
|
676
669
|
}
|
|
677
670
|
}
|
|
678
671
|
}
|
|
679
|
-
catch(final Exception e) {
|
|
680
|
-
Log.e(CapacitorUpdater.TAG, "Error during onActivityStopped", e);
|
|
681
|
-
}
|
|
682
672
|
}
|
|
683
673
|
|
|
684
674
|
private class DeferredNotifyAppReadyCheck implements Runnable {
|
|
@@ -687,21 +677,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
687
677
|
try {
|
|
688
678
|
Log.i(CapacitorUpdater.TAG, "Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady");
|
|
689
679
|
Thread.sleep(CapacitorUpdaterPlugin.this.appReadyTimeout);
|
|
690
|
-
|
|
691
|
-
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
692
|
-
if(current.isBuiltin()) {
|
|
693
|
-
Log.i(CapacitorUpdater.TAG, "Built-in bundle is active. Nothing to do.");
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
if(BundleStatus.SUCCESS != current.getStatus()) {
|
|
698
|
-
Log.e(CapacitorUpdater.TAG, "notifyAppReady was not called, roll back current bundle: " + current.getId());
|
|
699
|
-
CapacitorUpdaterPlugin.this.implementation.rollback(current);
|
|
700
|
-
CapacitorUpdaterPlugin.this._reset(true);
|
|
701
|
-
} else {
|
|
702
|
-
Log.i(CapacitorUpdater.TAG, "notifyAppReady was called. This is fine: " + current.getId());
|
|
703
|
-
}
|
|
704
|
-
|
|
680
|
+
CapacitorUpdaterPlugin.this.checkRevert();
|
|
705
681
|
CapacitorUpdaterPlugin.this.appReadyCheck = null;
|
|
706
682
|
} catch (final InterruptedException e) {
|
|
707
683
|
Log.e(CapacitorUpdater.TAG, DeferredNotifyAppReadyCheck.class.getName() + " was interrupted.");
|