@capgo/capacitor-updater 4.2.2 → 4.2.4
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/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +13 -11
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleStatus.java +3 -2
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +71 -77
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +185 -168
- package/dist/docs.json +2 -2
- package/dist/esm/definitions.d.ts +8 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.js +9 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +10 -4
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +10 -4
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/BundleInfo.swift +5 -7
- package/ios/Plugin/BundleStatus.swift +3 -3
- package/ios/Plugin/CapacitorUpdater.swift +82 -82
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +43 -43
- package/ios/Plugin/ObjectPreferences.swift +1 -1
- package/package.json +2 -2
|
@@ -9,10 +9,8 @@ import android.os.Build;
|
|
|
9
9
|
import android.os.Bundle;
|
|
10
10
|
import android.provider.Settings;
|
|
11
11
|
import android.util.Log;
|
|
12
|
-
|
|
13
12
|
import androidx.annotation.NonNull;
|
|
14
13
|
import androidx.annotation.Nullable;
|
|
15
|
-
|
|
16
14
|
import com.android.volley.toolbox.Volley;
|
|
17
15
|
import com.getcapacitor.CapConfig;
|
|
18
16
|
import com.getcapacitor.JSArray;
|
|
@@ -22,11 +20,7 @@ import com.getcapacitor.PluginCall;
|
|
|
22
20
|
import com.getcapacitor.PluginMethod;
|
|
23
21
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
24
22
|
import com.getcapacitor.plugin.WebView;
|
|
25
|
-
|
|
26
23
|
import io.github.g00fy2.versioncompare.Version;
|
|
27
|
-
|
|
28
|
-
import org.json.JSONException;
|
|
29
|
-
|
|
30
24
|
import java.io.IOException;
|
|
31
25
|
import java.net.MalformedURLException;
|
|
32
26
|
import java.net.URL;
|
|
@@ -35,9 +29,11 @@ import java.util.Date;
|
|
|
35
29
|
import java.util.Iterator;
|
|
36
30
|
import java.util.List;
|
|
37
31
|
import java.util.UUID;
|
|
32
|
+
import org.json.JSONException;
|
|
38
33
|
|
|
39
34
|
@CapacitorPlugin(name = "CapacitorUpdater")
|
|
40
35
|
public class CapacitorUpdaterPlugin extends Plugin implements Application.ActivityLifecycleCallbacks {
|
|
36
|
+
|
|
41
37
|
private static final String updateUrlDefault = "https://api.capgo.app/updates";
|
|
42
38
|
private static final String statsUrlDefault = "https://api.capgo.app/stats";
|
|
43
39
|
private static final String DELAY_UPDATE = "delayUpdate";
|
|
@@ -64,12 +60,13 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
64
60
|
this.editor = this.prefs.edit();
|
|
65
61
|
|
|
66
62
|
try {
|
|
67
|
-
this.implementation =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
this.implementation =
|
|
64
|
+
new CapacitorUpdater() {
|
|
65
|
+
@Override
|
|
66
|
+
public void notifyDownload(final String id, final int percent) {
|
|
67
|
+
CapacitorUpdaterPlugin.this.notifyDownload(id, percent);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
73
70
|
final PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
|
|
74
71
|
this.implementation.versionBuild = pInfo.versionName;
|
|
75
72
|
this.implementation.versionCode = Integer.toString(pInfo.versionCode);
|
|
@@ -115,11 +112,10 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
115
112
|
final Version previous = new Version(this.prefs.getString("LatestVersionNative", ""));
|
|
116
113
|
try {
|
|
117
114
|
if (!"".equals(previous.getOriginalString()) && this.currentVersionNative.getMajor() > previous.getMajor()) {
|
|
118
|
-
|
|
119
115
|
Log.i(CapacitorUpdater.TAG, "New native major version detected: " + this.currentVersionNative);
|
|
120
116
|
this.implementation.reset(true);
|
|
121
117
|
final List<BundleInfo> installed = this.implementation.list();
|
|
122
|
-
for (final BundleInfo bundle: installed) {
|
|
118
|
+
for (final BundleInfo bundle : installed) {
|
|
123
119
|
try {
|
|
124
120
|
Log.i(CapacitorUpdater.TAG, "Deleting obsolete bundle: " + bundle.getId());
|
|
125
121
|
this.implementation.delete(bundle.getId());
|
|
@@ -131,7 +127,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
131
127
|
} catch (final Exception e) {
|
|
132
128
|
Log.e(CapacitorUpdater.TAG, "Could not determine the current version", e);
|
|
133
129
|
}
|
|
134
|
-
} catch(final Exception e) {
|
|
130
|
+
} catch (final Exception e) {
|
|
135
131
|
Log.e(CapacitorUpdater.TAG, "Error calculating previous native version", e);
|
|
136
132
|
}
|
|
137
133
|
this.editor.putString("LatestVersionNative", this.currentVersionNative.toString());
|
|
@@ -153,7 +149,6 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
153
149
|
}
|
|
154
150
|
}
|
|
155
151
|
|
|
156
|
-
|
|
157
152
|
@PluginMethod
|
|
158
153
|
public void getDeviceId(final PluginCall call) {
|
|
159
154
|
try {
|
|
@@ -194,22 +189,24 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
194
189
|
}
|
|
195
190
|
try {
|
|
196
191
|
Log.i(CapacitorUpdater.TAG, "Downloading " + url);
|
|
197
|
-
new Thread(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
192
|
+
new Thread(
|
|
193
|
+
new Runnable() {
|
|
194
|
+
@Override
|
|
195
|
+
public void run() {
|
|
196
|
+
try {
|
|
197
|
+
final BundleInfo downloaded = CapacitorUpdaterPlugin.this.implementation.download(url, version);
|
|
198
|
+
call.resolve(downloaded.toJSON());
|
|
199
|
+
} catch (final IOException e) {
|
|
200
|
+
Log.e(CapacitorUpdater.TAG, "download failed", e);
|
|
201
|
+
call.reject("download failed", e);
|
|
202
|
+
final JSObject ret = new JSObject();
|
|
203
|
+
ret.put("version", version);
|
|
204
|
+
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
205
|
+
}
|
|
210
206
|
}
|
|
211
207
|
}
|
|
212
|
-
|
|
208
|
+
)
|
|
209
|
+
.start();
|
|
213
210
|
} catch (final Exception e) {
|
|
214
211
|
Log.e(CapacitorUpdater.TAG, "Failed to download " + url, e);
|
|
215
212
|
call.reject("Failed to download " + url, e);
|
|
@@ -219,7 +216,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
219
216
|
private boolean _reload() {
|
|
220
217
|
final String path = this.implementation.getCurrentBundlePath();
|
|
221
218
|
Log.i(CapacitorUpdater.TAG, "Reloading: " + path);
|
|
222
|
-
if(this.implementation.isUsingBuiltin()) {
|
|
219
|
+
if (this.implementation.isUsingBuiltin()) {
|
|
223
220
|
this.bridge.setServerAssetPath(path);
|
|
224
221
|
} else {
|
|
225
222
|
this.bridge.setServerBasePath(path);
|
|
@@ -237,7 +234,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
237
234
|
Log.e(CapacitorUpdater.TAG, "Reload failed");
|
|
238
235
|
call.reject("Reload failed");
|
|
239
236
|
}
|
|
240
|
-
} catch(final Exception e) {
|
|
237
|
+
} catch (final Exception e) {
|
|
241
238
|
Log.e(CapacitorUpdater.TAG, "Could not reload", e);
|
|
242
239
|
call.reject("Could not reload", e);
|
|
243
240
|
}
|
|
@@ -282,7 +279,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
282
279
|
Log.i(CapacitorUpdater.TAG, "Bundle successfully set to" + id);
|
|
283
280
|
this.reload(call);
|
|
284
281
|
}
|
|
285
|
-
} catch(final Exception e) {
|
|
282
|
+
} catch (final Exception e) {
|
|
286
283
|
Log.e(CapacitorUpdater.TAG, "Could not set id " + id, e);
|
|
287
284
|
call.reject("Could not set id " + id, e);
|
|
288
285
|
}
|
|
@@ -305,13 +302,12 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
305
302
|
Log.e(CapacitorUpdater.TAG, "Delete failed, id " + id + " does not exist");
|
|
306
303
|
call.reject("Delete failed, id " + id + " does not exist");
|
|
307
304
|
}
|
|
308
|
-
} catch(final Exception e) {
|
|
305
|
+
} catch (final Exception e) {
|
|
309
306
|
Log.e(CapacitorUpdater.TAG, "Could not delete id " + id, e);
|
|
310
307
|
call.reject("Could not delete id " + id, e);
|
|
311
308
|
}
|
|
312
309
|
}
|
|
313
310
|
|
|
314
|
-
|
|
315
311
|
@PluginMethod
|
|
316
312
|
public void list(final PluginCall call) {
|
|
317
313
|
try {
|
|
@@ -323,8 +319,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
323
319
|
}
|
|
324
320
|
ret.put("bundles", values);
|
|
325
321
|
call.resolve(ret);
|
|
326
|
-
}
|
|
327
|
-
catch(final Exception e) {
|
|
322
|
+
} catch (final Exception e) {
|
|
328
323
|
Log.e(CapacitorUpdater.TAG, "Could not list bundles", e);
|
|
329
324
|
call.reject("Could not list bundles", e);
|
|
330
325
|
}
|
|
@@ -332,26 +327,31 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
332
327
|
|
|
333
328
|
@PluginMethod
|
|
334
329
|
public void getLatest(final PluginCall call) {
|
|
335
|
-
new Thread(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
330
|
+
new Thread(
|
|
331
|
+
new Runnable() {
|
|
332
|
+
@Override
|
|
333
|
+
public void run() {
|
|
334
|
+
CapacitorUpdaterPlugin.this.implementation.getLatest(
|
|
335
|
+
CapacitorUpdaterPlugin.this.updateUrl,
|
|
336
|
+
res -> {
|
|
337
|
+
final JSObject ret = new JSObject();
|
|
338
|
+
Iterator<String> keys = res.keys();
|
|
339
|
+
while (keys.hasNext()) {
|
|
340
|
+
String key = keys.next();
|
|
341
|
+
if (res.has(key)) {
|
|
342
|
+
try {
|
|
343
|
+
ret.put(key, res.get(key));
|
|
344
|
+
} catch (JSONException e) {
|
|
345
|
+
e.printStackTrace();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
call.resolve(ret);
|
|
348
350
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
call.resolve(ret);
|
|
352
|
-
});
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
353
|
}
|
|
354
|
-
|
|
354
|
+
);
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
private boolean _reset(final Boolean toLastSuccessful) {
|
|
@@ -377,8 +377,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
377
377
|
}
|
|
378
378
|
Log.e(CapacitorUpdater.TAG, "Reset failed");
|
|
379
379
|
call.reject("Reset failed");
|
|
380
|
-
}
|
|
381
|
-
catch(final Exception e) {
|
|
380
|
+
} catch (final Exception e) {
|
|
382
381
|
Log.e(CapacitorUpdater.TAG, "Reset failed", e);
|
|
383
382
|
call.reject("Reset failed", e);
|
|
384
383
|
}
|
|
@@ -392,8 +391,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
392
391
|
ret.put("bundle", bundle.toJSON());
|
|
393
392
|
ret.put("native", this.currentVersionNative);
|
|
394
393
|
call.resolve(ret);
|
|
395
|
-
}
|
|
396
|
-
catch(final Exception e) {
|
|
394
|
+
} catch (final Exception e) {
|
|
397
395
|
Log.e(CapacitorUpdater.TAG, "Could not get current bundle", e);
|
|
398
396
|
call.reject("Could not get current bundle", e);
|
|
399
397
|
}
|
|
@@ -406,8 +404,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
406
404
|
this.implementation.setSuccess(bundle, this.autoDeletePrevious);
|
|
407
405
|
Log.i(CapacitorUpdater.TAG, "Current bundle loaded successfully. ['notifyAppReady()' was called] " + bundle.toString());
|
|
408
406
|
call.resolve();
|
|
409
|
-
}
|
|
410
|
-
catch(final Exception e) {
|
|
407
|
+
} catch (final Exception e) {
|
|
411
408
|
Log.e(CapacitorUpdater.TAG, "Failed to notify app ready state. [Error calling 'notifyAppReady()']", e);
|
|
412
409
|
call.reject("Failed to commit app ready state.", e);
|
|
413
410
|
}
|
|
@@ -428,8 +425,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
428
425
|
this.editor.commit();
|
|
429
426
|
Log.i(CapacitorUpdater.TAG, "Delay update saved");
|
|
430
427
|
call.resolve();
|
|
431
|
-
}
|
|
432
|
-
catch(final Exception e) {
|
|
428
|
+
} catch (final Exception e) {
|
|
433
429
|
Log.e(CapacitorUpdater.TAG, "Failed to delay update", e);
|
|
434
430
|
call.reject("Failed to delay update", e);
|
|
435
431
|
}
|
|
@@ -442,8 +438,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
442
438
|
this.editor.commit();
|
|
443
439
|
Log.i(CapacitorUpdater.TAG, "delay canceled from " + source);
|
|
444
440
|
return true;
|
|
445
|
-
}
|
|
446
|
-
catch(final Exception e) {
|
|
441
|
+
} catch (final Exception e) {
|
|
447
442
|
Log.e(CapacitorUpdater.TAG, "Failed to cancel update delay", e);
|
|
448
443
|
return false;
|
|
449
444
|
}
|
|
@@ -451,7 +446,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
451
446
|
|
|
452
447
|
@PluginMethod
|
|
453
448
|
public void cancelDelay(final PluginCall call) {
|
|
454
|
-
if(this._cancelDelay("JS")) {
|
|
449
|
+
if (this._cancelDelay("JS")) {
|
|
455
450
|
call.resolve();
|
|
456
451
|
} else {
|
|
457
452
|
call.reject("Failed to cancel delay");
|
|
@@ -473,22 +468,19 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
473
468
|
try {
|
|
474
469
|
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
|
475
470
|
Date date = sdf.parse(delayVal);
|
|
476
|
-
if (date.compareTo(new Date()) > 0)
|
|
471
|
+
if (date.compareTo(new Date()) > 0) {
|
|
477
472
|
this._cancelDelay("date expired");
|
|
478
473
|
}
|
|
479
|
-
}
|
|
480
|
-
catch(final Exception e) {
|
|
474
|
+
} catch (final Exception e) {
|
|
481
475
|
this._cancelDelay("date parsing issue");
|
|
482
476
|
}
|
|
483
|
-
|
|
484
477
|
} else if ("nativeVersion".equals(delayUpdate)) {
|
|
485
478
|
try {
|
|
486
479
|
final Version versionLimit = new Version(delayVal);
|
|
487
480
|
if (this.currentVersionNative.isAtLeast(versionLimit)) {
|
|
488
481
|
this._cancelDelay("nativeVersion above limit");
|
|
489
482
|
}
|
|
490
|
-
}
|
|
491
|
-
catch(final Exception e) {
|
|
483
|
+
} catch (final Exception e) {
|
|
492
484
|
this._cancelDelay("nativeVersion parsing issue");
|
|
493
485
|
}
|
|
494
486
|
}
|
|
@@ -513,7 +505,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
513
505
|
|
|
514
506
|
private void checkAppReady() {
|
|
515
507
|
try {
|
|
516
|
-
if(this.appReadyCheck != null) {
|
|
508
|
+
if (this.appReadyCheck != null) {
|
|
517
509
|
this.appReadyCheck.interrupt();
|
|
518
510
|
}
|
|
519
511
|
this.appReadyCheck = new Thread(new DeferredNotifyAppReadyCheck());
|
|
@@ -527,8 +519,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
527
519
|
try {
|
|
528
520
|
URL url = new URL(urlStr);
|
|
529
521
|
return true;
|
|
530
|
-
}
|
|
531
|
-
catch (MalformedURLException e) {
|
|
522
|
+
} catch (MalformedURLException e) {
|
|
532
523
|
return false;
|
|
533
524
|
}
|
|
534
525
|
}
|
|
@@ -536,95 +527,120 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
536
527
|
@Override // appMovedToForeground
|
|
537
528
|
public void onActivityStarted(@NonNull final Activity activity) {
|
|
538
529
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled()) {
|
|
539
|
-
new Thread(
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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
|
-
}
|
|
566
|
-
final String latestVersionName = (String) res.get("version");
|
|
567
|
-
|
|
568
|
-
if (latestVersionName != null && !"".equals(latestVersionName) && !current.getVersionName().equals(latestVersionName)) {
|
|
569
|
-
|
|
570
|
-
final BundleInfo latest = CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(latestVersionName);
|
|
571
|
-
if(latest != null) {
|
|
572
|
-
if(latest.isErrorStatus()) {
|
|
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);
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
if(latest.isDownloaded()){
|
|
580
|
-
Log.e(CapacitorUpdater.TAG, "Latest bundle already exists and download is NOT required. Update will occur next time app moves to background.");
|
|
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());
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
530
|
+
new Thread(
|
|
531
|
+
new Runnable() {
|
|
532
|
+
@Override
|
|
533
|
+
public void run() {
|
|
534
|
+
Log.i(CapacitorUpdater.TAG, "Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl);
|
|
535
|
+
CapacitorUpdaterPlugin.this.implementation.getLatest(
|
|
536
|
+
CapacitorUpdaterPlugin.this.updateUrl,
|
|
537
|
+
res -> {
|
|
538
|
+
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
539
|
+
try {
|
|
540
|
+
if (res.has("message")) {
|
|
541
|
+
Log.i(CapacitorUpdater.TAG, "message " + res.get("message"));
|
|
542
|
+
if (res.has("major") && res.getBoolean("major") && res.has("version")) {
|
|
543
|
+
final JSObject majorAvailable = new JSObject();
|
|
544
|
+
majorAvailable.put("version", (String) res.get("version"));
|
|
545
|
+
CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", majorAvailable);
|
|
546
|
+
}
|
|
547
|
+
final JSObject retNoNeed = new JSObject();
|
|
548
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
549
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
589
552
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
public void run() {
|
|
593
|
-
try {
|
|
594
|
-
Log.i(CapacitorUpdater.TAG, "New bundle: " + latestVersionName + " found. Current is: " + current.getVersionName() + ". Update will occur next time app moves to background.");
|
|
595
|
-
|
|
596
|
-
final String url = (String) res.get("url");
|
|
597
|
-
final BundleInfo next = CapacitorUpdaterPlugin.this.implementation.download(url, latestVersionName);
|
|
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());
|
|
602
|
-
} catch (final Exception e) {
|
|
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);
|
|
553
|
+
if (!res.has("url") || !CapacitorUpdaterPlugin.this.isValidURL((String) res.get("url"))) {
|
|
554
|
+
Log.e(CapacitorUpdater.TAG, "Error no url or wrong format");
|
|
607
555
|
final JSObject retNoNeed = new JSObject();
|
|
608
556
|
retNoNeed.put("bundle", current.toJSON());
|
|
609
557
|
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
610
558
|
}
|
|
559
|
+
final String latestVersionName = (String) res.get("version");
|
|
560
|
+
|
|
561
|
+
if (
|
|
562
|
+
latestVersionName != null &&
|
|
563
|
+
!"".equals(latestVersionName) &&
|
|
564
|
+
!current.getVersionName().equals(latestVersionName)
|
|
565
|
+
) {
|
|
566
|
+
final BundleInfo latest =
|
|
567
|
+
CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(latestVersionName);
|
|
568
|
+
if (latest != null) {
|
|
569
|
+
if (latest.isErrorStatus()) {
|
|
570
|
+
Log.e(
|
|
571
|
+
CapacitorUpdater.TAG,
|
|
572
|
+
"Latest bundle already exists, and is in error state. Aborting update."
|
|
573
|
+
);
|
|
574
|
+
final JSObject retNoNeed = new JSObject();
|
|
575
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
576
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (latest.isDownloaded()) {
|
|
580
|
+
Log.e(
|
|
581
|
+
CapacitorUpdater.TAG,
|
|
582
|
+
"Latest bundle already exists and download is NOT required. Update will occur next time app moves to background."
|
|
583
|
+
);
|
|
584
|
+
final JSObject ret = new JSObject();
|
|
585
|
+
ret.put("bundle", latest.toJSON());
|
|
586
|
+
CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
|
|
587
|
+
CapacitorUpdaterPlugin.this.implementation.setNextBundle(latest.getId());
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
new Thread(
|
|
593
|
+
new Runnable() {
|
|
594
|
+
@Override
|
|
595
|
+
public void run() {
|
|
596
|
+
try {
|
|
597
|
+
Log.i(
|
|
598
|
+
CapacitorUpdater.TAG,
|
|
599
|
+
"New bundle: " +
|
|
600
|
+
latestVersionName +
|
|
601
|
+
" found. Current is: " +
|
|
602
|
+
current.getVersionName() +
|
|
603
|
+
". Update will occur next time app moves to background."
|
|
604
|
+
);
|
|
605
|
+
|
|
606
|
+
final String url = (String) res.get("url");
|
|
607
|
+
final BundleInfo next =
|
|
608
|
+
CapacitorUpdaterPlugin.this.implementation.download(url, latestVersionName);
|
|
609
|
+
final JSObject ret = new JSObject();
|
|
610
|
+
ret.put("bundle", next.toJSON());
|
|
611
|
+
CapacitorUpdaterPlugin.this.notifyListeners("updateAvailable", ret);
|
|
612
|
+
CapacitorUpdaterPlugin.this.implementation.setNextBundle(next.getId());
|
|
613
|
+
} catch (final Exception e) {
|
|
614
|
+
Log.e(CapacitorUpdater.TAG, "error downloading file", e);
|
|
615
|
+
final JSObject ret = new JSObject();
|
|
616
|
+
ret.put("version", latestVersionName);
|
|
617
|
+
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
618
|
+
final JSObject retNoNeed = new JSObject();
|
|
619
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
620
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
)
|
|
625
|
+
.start();
|
|
626
|
+
} else {
|
|
627
|
+
Log.i(CapacitorUpdater.TAG, "No need to update, " + current.getId() + " is the latest bundle.");
|
|
628
|
+
final JSObject retNoNeed = new JSObject();
|
|
629
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
630
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
631
|
+
}
|
|
632
|
+
} catch (final JSONException e) {
|
|
633
|
+
Log.e(CapacitorUpdater.TAG, "error parsing JSON", e);
|
|
634
|
+
final JSObject retNoNeed = new JSObject();
|
|
635
|
+
retNoNeed.put("bundle", current.toJSON());
|
|
636
|
+
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
611
637
|
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
final JSObject retNoNeed = new JSObject();
|
|
616
|
-
retNoNeed.put("bundle", current.toJSON());
|
|
617
|
-
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
|
|
618
|
-
}
|
|
619
|
-
} catch (final JSONException e) {
|
|
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);
|
|
624
|
-
}
|
|
625
|
-
});
|
|
638
|
+
}
|
|
639
|
+
);
|
|
640
|
+
}
|
|
626
641
|
}
|
|
627
|
-
|
|
642
|
+
)
|
|
643
|
+
.start();
|
|
628
644
|
}
|
|
629
645
|
|
|
630
646
|
this.checkAppReady();
|
|
@@ -653,8 +669,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
653
669
|
Log.e(CapacitorUpdater.TAG, "Update to bundle: " + next.getVersionName() + " Failed!");
|
|
654
670
|
}
|
|
655
671
|
}
|
|
656
|
-
}
|
|
657
|
-
catch(final Exception e) {
|
|
672
|
+
} catch (final Exception e) {
|
|
658
673
|
Log.e(CapacitorUpdater.TAG, "Error during onActivityStopped", e);
|
|
659
674
|
}
|
|
660
675
|
}
|
|
@@ -663,13 +678,13 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
663
678
|
// Automatically roll back to fallback version if notifyAppReady has not been called yet
|
|
664
679
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
665
680
|
|
|
666
|
-
if(current.isBuiltin()) {
|
|
681
|
+
if (current.isBuiltin()) {
|
|
667
682
|
Log.i(CapacitorUpdater.TAG, "Built-in bundle is active. Nothing to do.");
|
|
668
683
|
return;
|
|
669
684
|
}
|
|
670
685
|
Log.d(CapacitorUpdater.TAG, "Current bundle is: " + current);
|
|
671
686
|
|
|
672
|
-
if(BundleStatus.SUCCESS != current.getStatus()) {
|
|
687
|
+
if (BundleStatus.SUCCESS != current.getStatus()) {
|
|
673
688
|
Log.e(CapacitorUpdater.TAG, "notifyAppReady was not called, roll back current bundle: " + current.getId());
|
|
674
689
|
Log.i(CapacitorUpdater.TAG, "Did you forget to call 'notifyAppReady()' in your Capacitor App code?");
|
|
675
690
|
final JSObject ret = new JSObject();
|
|
@@ -695,10 +710,14 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
695
710
|
}
|
|
696
711
|
|
|
697
712
|
private class DeferredNotifyAppReadyCheck implements Runnable {
|
|
713
|
+
|
|
698
714
|
@Override
|
|
699
715
|
public void run() {
|
|
700
716
|
try {
|
|
701
|
-
Log.i(
|
|
717
|
+
Log.i(
|
|
718
|
+
CapacitorUpdater.TAG,
|
|
719
|
+
"Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady"
|
|
720
|
+
);
|
|
702
721
|
Thread.sleep(CapacitorUpdaterPlugin.this.appReadyTimeout);
|
|
703
722
|
CapacitorUpdaterPlugin.this.checkRevert();
|
|
704
723
|
CapacitorUpdaterPlugin.this.appReadyCheck = null;
|
|
@@ -718,15 +737,13 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
718
737
|
public void onActivityPaused(@NonNull final Activity activity) {
|
|
719
738
|
// TODO: Implement background updating based on `backgroundUpdate` and `backgroundUpdateDelay` capacitor.config.ts settings
|
|
720
739
|
}
|
|
740
|
+
|
|
721
741
|
@Override
|
|
722
|
-
public void onActivityCreated(@NonNull final Activity activity, @Nullable final Bundle savedInstanceState) {
|
|
723
|
-
}
|
|
742
|
+
public void onActivityCreated(@NonNull final Activity activity, @Nullable final Bundle savedInstanceState) {}
|
|
724
743
|
|
|
725
744
|
@Override
|
|
726
|
-
public void onActivitySaveInstanceState(@NonNull final Activity activity, @NonNull final Bundle outState) {
|
|
727
|
-
}
|
|
745
|
+
public void onActivitySaveInstanceState(@NonNull final Activity activity, @NonNull final Bundle outState) {}
|
|
728
746
|
|
|
729
747
|
@Override
|
|
730
|
-
public void onActivityDestroyed(@NonNull final Activity activity) {
|
|
731
|
-
}
|
|
748
|
+
public void onActivityDestroyed(@NonNull final Activity activity) {}
|
|
732
749
|
}
|
package/dist/docs.json
CHANGED
|
@@ -1375,7 +1375,7 @@
|
|
|
1375
1375
|
"name": "example"
|
|
1376
1376
|
}
|
|
1377
1377
|
],
|
|
1378
|
-
"docs": "Configure the URL / endpoint to which update checks are sent
|
|
1378
|
+
"docs": "Configure the URL / endpoint to which update checks are sent.\n\nOnly available for Android and iOS.",
|
|
1379
1379
|
"complexTypes": [],
|
|
1380
1380
|
"type": "string | undefined"
|
|
1381
1381
|
},
|
|
@@ -1391,7 +1391,7 @@
|
|
|
1391
1391
|
"name": "example"
|
|
1392
1392
|
}
|
|
1393
1393
|
],
|
|
1394
|
-
"docs": "Configure the URL / endpoint to which update statistics are sent
|
|
1394
|
+
"docs": "Configure the URL / endpoint to which update statistics are sent.\n\nOnly available for Android and iOS. Set to \"\" to disable stats reporting.",
|
|
1395
1395
|
"complexTypes": [],
|
|
1396
1396
|
"type": "string | undefined"
|
|
1397
1397
|
}
|
|
@@ -286,10 +286,10 @@ export interface CapacitorUpdaterPlugin {
|
|
|
286
286
|
*/
|
|
287
287
|
addListener(eventName: 'noNeedUpdate', listenerFunc: NoNeedListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
288
288
|
/**
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
289
|
+
* Listen for availbale update event, usefull when you want to force check every time the app is launched
|
|
290
|
+
*
|
|
291
|
+
* @since 4.0.0
|
|
292
|
+
*/
|
|
293
293
|
addListener(eventName: 'updateAvailable', listenerFunc: UpdateAvailabledListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
294
294
|
/**
|
|
295
295
|
* Listen for download event in the App, let you know when the download is started, loading and finished
|
|
@@ -304,10 +304,10 @@ export interface CapacitorUpdaterPlugin {
|
|
|
304
304
|
*/
|
|
305
305
|
addListener(eventName: 'majorAvailable', listenerFunc: MajorAvailableListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
306
306
|
/**
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
307
|
+
* Listen for update fail event in the App, let you know when update has fail to install at next app start
|
|
308
|
+
*
|
|
309
|
+
* @since 2.3.0
|
|
310
|
+
*/
|
|
311
311
|
addListener(eventName: 'updateFailed', listenerFunc: UpdateFailedListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
312
312
|
/**
|
|
313
313
|
* Listen for download fail event in the App, let you know when download has fail finished
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { registerPlugin } from '@capacitor/core';
|
|
2
2
|
const CapacitorUpdater = registerPlugin('CapacitorUpdater', {
|
|
3
|
-
web: () => import('./web').then(m => new m.CapacitorUpdaterWeb()),
|
|
3
|
+
web: () => import('./web').then((m) => new m.CapacitorUpdaterWeb()),
|
|
4
4
|
});
|
|
5
5
|
export * from './definitions';
|
|
6
6
|
export { CapacitorUpdater };
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,gBAAgB,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,gBAAgB,GAAG,cAAc,CAAyB,kBAAkB,EAAE;IAClF,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,mBAAmB,EAAE,CAAC;CACpE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|