@capgo/capacitor-updater 4.0.0-alpha.2 → 4.0.0-alpha.20
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 +53 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +17 -19
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +115 -29
- package/dist/docs.json +172 -4
- package/dist/esm/definitions.d.ts +39 -4
- package/dist/esm/web.d.ts +5 -2
- package/dist/esm/web.js +12 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +12 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +12 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorUpdater.swift +65 -38
- package/ios/Plugin/CapacitorUpdaterPlugin.m +3 -1
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +105 -45
- package/ios/Plugin/ObjectPreferences.swift +1 -57
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -127,6 +127,8 @@ Capacitor Updator works by unzipping a compiled app bundle to the native device
|
|
|
127
127
|
* [`current()`](#current)
|
|
128
128
|
* [`reload()`](#reload)
|
|
129
129
|
* [`setDelay(...)`](#setdelay)
|
|
130
|
+
* [`cancelDelay()`](#canceldelay)
|
|
131
|
+
* [`getLatest(...)`](#getlatest)
|
|
130
132
|
* [`addListener('download', ...)`](#addlistenerdownload)
|
|
131
133
|
* [`addListener('downloadComplete', ...)`](#addlistenerdownloadcomplete)
|
|
132
134
|
* [`addListener('majorAvailable', ...)`](#addlistenermajoravailable)
|
|
@@ -276,15 +278,49 @@ Reload the view
|
|
|
276
278
|
### setDelay(...)
|
|
277
279
|
|
|
278
280
|
```typescript
|
|
279
|
-
setDelay(options: {
|
|
281
|
+
setDelay(options: { kind: DelayUntilNext; value?: string; }) => Promise<void>
|
|
280
282
|
```
|
|
281
283
|
|
|
282
284
|
Set delay to skip updates in the next time the app goes into the background
|
|
283
285
|
|
|
286
|
+
| Param | Type |
|
|
287
|
+
| ------------- | ------------------------------------------------------------------------------------ |
|
|
288
|
+
| **`options`** | <code>{ kind: <a href="#delayuntilnext">DelayUntilNext</a>; value?: string; }</code> |
|
|
289
|
+
|
|
290
|
+
**Since:** 4.0.0
|
|
291
|
+
|
|
292
|
+
--------------------
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
### cancelDelay()
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
cancelDelay() => Promise<void>
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Cancel delay to updates as usual
|
|
302
|
+
|
|
303
|
+
**Since:** 4.0.0
|
|
304
|
+
|
|
305
|
+
--------------------
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
### getLatest(...)
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
getLatest(options: { delay: boolean; }) => Promise<latestVersion>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Get Latest version available from update Url
|
|
315
|
+
|
|
284
316
|
| Param | Type |
|
|
285
317
|
| ------------- | -------------------------------- |
|
|
286
318
|
| **`options`** | <code>{ delay: boolean; }</code> |
|
|
287
319
|
|
|
320
|
+
**Returns:** <code>Promise<<a href="#latestversion">latestVersion</a>></code>
|
|
321
|
+
|
|
322
|
+
**Since:** 4.0.0
|
|
323
|
+
|
|
288
324
|
--------------------
|
|
289
325
|
|
|
290
326
|
|
|
@@ -445,6 +481,17 @@ removeAllListeners() => Promise<void>
|
|
|
445
481
|
| **`status`** | <code><a href="#bundlestatus">BundleStatus</a></code> |
|
|
446
482
|
|
|
447
483
|
|
|
484
|
+
#### latestVersion
|
|
485
|
+
|
|
486
|
+
| Prop | Type | Description | Since |
|
|
487
|
+
| ------------- | -------------------- | ----------------------- | ----- |
|
|
488
|
+
| **`version`** | <code>string</code> | Res of getLatest method | 4.0.0 |
|
|
489
|
+
| **`major`** | <code>boolean</code> | | |
|
|
490
|
+
| **`message`** | <code>string</code> | | |
|
|
491
|
+
| **`old`** | <code>string</code> | | |
|
|
492
|
+
| **`url`** | <code>string</code> | | |
|
|
493
|
+
|
|
494
|
+
|
|
448
495
|
#### PluginListenerHandle
|
|
449
496
|
|
|
450
497
|
| Prop | Type |
|
|
@@ -489,6 +536,11 @@ removeAllListeners() => Promise<void>
|
|
|
489
536
|
<code>'success' | 'error' | 'pending' | 'downloading'</code>
|
|
490
537
|
|
|
491
538
|
|
|
539
|
+
#### DelayUntilNext
|
|
540
|
+
|
|
541
|
+
<code>'background' | 'kill' | 'nativeVersion' | 'date'</code>
|
|
542
|
+
|
|
543
|
+
|
|
492
544
|
#### DownloadChangeListener
|
|
493
545
|
|
|
494
546
|
<code>(state: <a href="#downloadevent">DownloadEvent</a>): void</code>
|
|
@@ -46,7 +46,7 @@ public class CapacitorUpdater {
|
|
|
46
46
|
private static final String bundleDirectory = "versions";
|
|
47
47
|
|
|
48
48
|
public static final String TAG = "Capacitor-updater";
|
|
49
|
-
public static final String pluginVersion = "4.0.0-alpha.
|
|
49
|
+
public static final String pluginVersion = "4.0.0-alpha.20";
|
|
50
50
|
|
|
51
51
|
public SharedPreferences.Editor editor;
|
|
52
52
|
public SharedPreferences prefs;
|
|
@@ -255,7 +255,7 @@ public class CapacitorUpdater {
|
|
|
255
255
|
return true;
|
|
256
256
|
}
|
|
257
257
|
Log.e(TAG, "Directory not removed: " + bundle.getPath());
|
|
258
|
-
this.sendStats("delete", deleted);
|
|
258
|
+
this.sendStats("delete", deleted.getVersionName());
|
|
259
259
|
return false;
|
|
260
260
|
}
|
|
261
261
|
|
|
@@ -263,11 +263,11 @@ public class CapacitorUpdater {
|
|
|
263
263
|
return new File(this.documentsDir, bundleDirectory + "/" + id);
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
private boolean bundleExists(final
|
|
266
|
+
private boolean bundleExists(final String id) {
|
|
267
|
+
final File bundle = this.getBundleDirectory(id);
|
|
267
268
|
if(bundle == null || !bundle.exists()) {
|
|
268
269
|
return false;
|
|
269
270
|
}
|
|
270
|
-
|
|
271
271
|
return new File(bundle.getPath(), "/index.html").exists();
|
|
272
272
|
}
|
|
273
273
|
|
|
@@ -277,17 +277,17 @@ public class CapacitorUpdater {
|
|
|
277
277
|
|
|
278
278
|
public Boolean set(final String id) {
|
|
279
279
|
|
|
280
|
-
final BundleInfo
|
|
280
|
+
final BundleInfo newBundle = this.getBundleInfo(id);
|
|
281
281
|
final File bundle = this.getBundleDirectory(id);
|
|
282
282
|
|
|
283
|
-
Log.i(TAG, "Setting next active bundle: " +
|
|
284
|
-
if (this.bundleExists(
|
|
283
|
+
Log.i(TAG, "Setting next active bundle: " + id);
|
|
284
|
+
if (this.bundleExists(id)) {
|
|
285
285
|
this.setCurrentBundle(bundle);
|
|
286
286
|
this.setBundleStatus(id, BundleStatus.PENDING);
|
|
287
|
-
this.sendStats("set",
|
|
287
|
+
this.sendStats("set", newBundle.getVersionName());
|
|
288
288
|
return true;
|
|
289
289
|
}
|
|
290
|
-
this.sendStats("set_fail",
|
|
290
|
+
this.sendStats("set_fail", newBundle.getVersionName());
|
|
291
291
|
return false;
|
|
292
292
|
}
|
|
293
293
|
|
|
@@ -307,9 +307,9 @@ public class CapacitorUpdater {
|
|
|
307
307
|
public void reset(final boolean internal) {
|
|
308
308
|
this.setCurrentBundle(new File("public"));
|
|
309
309
|
this.setFallbackVersion(null);
|
|
310
|
-
this.
|
|
310
|
+
this.setNext(null);
|
|
311
311
|
if(!internal) {
|
|
312
|
-
this.sendStats("reset", this.getCurrentBundle());
|
|
312
|
+
this.sendStats("reset", this.getCurrentBundle().getVersionName());
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
|
|
@@ -356,7 +356,7 @@ public class CapacitorUpdater {
|
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
-
public void sendStats(final String action, final
|
|
359
|
+
public void sendStats(final String action, final String versionName) {
|
|
360
360
|
String statsUrl = this.statsUrl;
|
|
361
361
|
if (statsUrl == null || "".equals(statsUrl) || statsUrl.length() == 0) { return; }
|
|
362
362
|
try {
|
|
@@ -367,7 +367,7 @@ public class CapacitorUpdater {
|
|
|
367
367
|
json.put("version_build", this.versionBuild);
|
|
368
368
|
json.put("version_code", this.versionCode);
|
|
369
369
|
json.put("version_os", this.versionOs);
|
|
370
|
-
json.put("version_name",
|
|
370
|
+
json.put("version_name", versionName);
|
|
371
371
|
json.put("plugin_version", pluginVersion);
|
|
372
372
|
json.put("action", action);
|
|
373
373
|
|
|
@@ -379,13 +379,13 @@ public class CapacitorUpdater {
|
|
|
379
379
|
new Response.Listener<JSONObject>() {
|
|
380
380
|
@Override
|
|
381
381
|
public void onResponse(JSONObject response) {
|
|
382
|
-
Log.i(TAG, "Stats send for \"" + action + "\", version " +
|
|
382
|
+
Log.i(TAG, "Stats send for \"" + action + "\", version " + versionName);
|
|
383
383
|
}
|
|
384
384
|
},
|
|
385
385
|
new Response.ErrorListener(){
|
|
386
386
|
@Override
|
|
387
387
|
public void onErrorResponse(VolleyError error) {
|
|
388
|
-
Log.i(TAG, "Stats send for \"" + action + "\", version " +
|
|
388
|
+
Log.i(TAG, "Stats send for \"" + action + "\", version " + versionName);
|
|
389
389
|
}
|
|
390
390
|
});
|
|
391
391
|
this.requestQueue.add(request);
|
|
@@ -511,15 +511,13 @@ public class CapacitorUpdater {
|
|
|
511
511
|
}
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
-
public boolean
|
|
514
|
+
public boolean setNext(final String next) {
|
|
515
515
|
if (next == null) {
|
|
516
516
|
this.editor.remove(NEXT_VERSION);
|
|
517
517
|
} else {
|
|
518
|
-
|
|
519
|
-
if (!this.bundleExists(bundle)) {
|
|
518
|
+
if (!this.bundleExists(next)) {
|
|
520
519
|
return false;
|
|
521
520
|
}
|
|
522
|
-
|
|
523
521
|
this.editor.putString(NEXT_VERSION, next);
|
|
524
522
|
this.setBundleStatus(next, BundleStatus.PENDING);
|
|
525
523
|
}
|
|
@@ -28,13 +28,17 @@ import io.github.g00fy2.versioncompare.Version;
|
|
|
28
28
|
import org.json.JSONException;
|
|
29
29
|
|
|
30
30
|
import java.io.IOException;
|
|
31
|
+
import java.text.SimpleDateFormat;
|
|
32
|
+
import java.util.Date;
|
|
33
|
+
import java.util.Iterator;
|
|
31
34
|
import java.util.List;
|
|
32
35
|
|
|
33
36
|
@CapacitorPlugin(name = "CapacitorUpdater")
|
|
34
37
|
public class CapacitorUpdaterPlugin extends Plugin implements Application.ActivityLifecycleCallbacks {
|
|
35
|
-
private static final String
|
|
38
|
+
private static final String updateUrlDefault = "https://xvwzpoazmxkqosrdewyv.functions.supabase.co/updates";
|
|
36
39
|
private static final String statsUrlDefault = "https://xvwzpoazmxkqosrdewyv.functions.supabase.co/stats";
|
|
37
40
|
private static final String DELAY_UPDATE = "delayUpdate";
|
|
41
|
+
private static final String DELAY_UPDATE_VAL = "delayUpdateVal";
|
|
38
42
|
|
|
39
43
|
private SharedPreferences.Editor editor;
|
|
40
44
|
private SharedPreferences prefs;
|
|
@@ -44,7 +48,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
44
48
|
private Boolean autoDeleteFailed = true;
|
|
45
49
|
private Boolean autoDeletePrevious = true;
|
|
46
50
|
private Boolean autoUpdate = false;
|
|
47
|
-
private String
|
|
51
|
+
private String updateUrl = "";
|
|
48
52
|
private Version currentVersionNative;
|
|
49
53
|
private Boolean resetWhenUpdate = true;
|
|
50
54
|
|
|
@@ -87,7 +91,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
87
91
|
|
|
88
92
|
this.autoDeleteFailed = this.getConfig().getBoolean("autoDeleteFailed", true);
|
|
89
93
|
this.autoDeletePrevious = this.getConfig().getBoolean("autoDeletePrevious", true);
|
|
90
|
-
this.
|
|
94
|
+
this.updateUrl = this.getConfig().getString("updateUrl", updateUrlDefault);
|
|
91
95
|
this.autoUpdate = this.getConfig().getBoolean("autoUpdate", false);
|
|
92
96
|
this.appReadyTimeout = this.getConfig().getInt("appReadyTimeout", 10000);
|
|
93
97
|
this.resetWhenUpdate = this.getConfig().getBoolean("resetWhenUpdate", true);
|
|
@@ -97,8 +101,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
97
101
|
}
|
|
98
102
|
final Application application = (Application) this.getContext().getApplicationContext();
|
|
99
103
|
application.registerActivityLifecycleCallbacks(this);
|
|
100
|
-
|
|
101
104
|
this.onActivityStarted(this.getActivity());
|
|
105
|
+
this._checkCancelDelay(true);
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
private void cleanupObsoleteVersions() {
|
|
@@ -133,7 +137,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
133
137
|
try {
|
|
134
138
|
final JSObject ret = new JSObject();
|
|
135
139
|
ret.put("percent", percent);
|
|
136
|
-
|
|
140
|
+
JSObject bundle = this.implementation.getBundleInfo(id).toJSON();
|
|
137
141
|
ret.put("bundle", bundle);
|
|
138
142
|
this.notifyListeners("download", ret);
|
|
139
143
|
if (percent == 100) {
|
|
@@ -146,10 +150,10 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
146
150
|
|
|
147
151
|
|
|
148
152
|
@PluginMethod
|
|
149
|
-
public void
|
|
153
|
+
public void getDeviceId(final PluginCall call) {
|
|
150
154
|
try {
|
|
151
155
|
final JSObject ret = new JSObject();
|
|
152
|
-
ret.put("
|
|
156
|
+
ret.put("deviceId", this.implementation.deviceID);
|
|
153
157
|
call.resolve(ret);
|
|
154
158
|
} catch (final Exception e) {
|
|
155
159
|
Log.e(CapacitorUpdater.TAG, "Could not get device id", e);
|
|
@@ -174,6 +178,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
174
178
|
final String url = call.getString("url");
|
|
175
179
|
final String version = call.getString("version");
|
|
176
180
|
if (url == null || version == null) {
|
|
181
|
+
Log.e(CapacitorUpdater.TAG, "missing url or version");
|
|
177
182
|
call.reject("missing url or version");
|
|
178
183
|
return;
|
|
179
184
|
}
|
|
@@ -216,6 +221,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
216
221
|
if (this._reload()) {
|
|
217
222
|
call.resolve();
|
|
218
223
|
} else {
|
|
224
|
+
Log.e(CapacitorUpdater.TAG, "Reload failed");
|
|
219
225
|
call.reject("Reload failed");
|
|
220
226
|
}
|
|
221
227
|
} catch(final Exception e) {
|
|
@@ -230,7 +236,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
230
236
|
|
|
231
237
|
try {
|
|
232
238
|
Log.i(CapacitorUpdater.TAG, "Setting next active id " + id);
|
|
233
|
-
if (!this.implementation.
|
|
239
|
+
if (!this.implementation.setNext(id)) {
|
|
240
|
+
Log.e(CapacitorUpdater.TAG, "Set next id failed. Bundle " + id + " does not exist.");
|
|
234
241
|
call.reject("Set next id failed. Bundle " + id + " does not exist.");
|
|
235
242
|
} else {
|
|
236
243
|
call.resolve(this.implementation.getBundleInfo(id).toJSON());
|
|
@@ -269,6 +276,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
269
276
|
if (res) {
|
|
270
277
|
call.resolve();
|
|
271
278
|
} else {
|
|
279
|
+
Log.e(CapacitorUpdater.TAG, "Delete failed, id " + id + " does not exist");
|
|
272
280
|
call.reject("Delete failed, id " + id + " does not exist");
|
|
273
281
|
}
|
|
274
282
|
} catch(final Exception e) {
|
|
@@ -296,6 +304,30 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
296
304
|
}
|
|
297
305
|
}
|
|
298
306
|
|
|
307
|
+
@PluginMethod
|
|
308
|
+
public void getLatest(final PluginCall call) {
|
|
309
|
+
new Thread(new Runnable(){
|
|
310
|
+
@Override
|
|
311
|
+
public void run() {
|
|
312
|
+
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, (res) -> {
|
|
313
|
+
final JSObject ret = new JSObject();
|
|
314
|
+
Iterator<String> keys = res.keys();
|
|
315
|
+
while(keys.hasNext()) {
|
|
316
|
+
String key = keys.next();
|
|
317
|
+
if (res.has(key)) {
|
|
318
|
+
try {
|
|
319
|
+
ret.put(key, res.get(key));
|
|
320
|
+
} catch (JSONException e) {
|
|
321
|
+
e.printStackTrace();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
call.resolve(ret);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
299
331
|
private boolean _reset(final Boolean toLastSuccessful) {
|
|
300
332
|
final BundleInfo fallback = this.implementation.getFallbackVersion();
|
|
301
333
|
this.implementation.reset();
|
|
@@ -317,6 +349,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
317
349
|
call.resolve();
|
|
318
350
|
return;
|
|
319
351
|
}
|
|
352
|
+
Log.e(CapacitorUpdater.TAG, "Reset failed");
|
|
320
353
|
call.reject("Reset failed");
|
|
321
354
|
}
|
|
322
355
|
catch(final Exception e) {
|
|
@@ -357,9 +390,17 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
357
390
|
@PluginMethod
|
|
358
391
|
public void delayUpdate(final PluginCall call) {
|
|
359
392
|
try {
|
|
360
|
-
|
|
361
|
-
|
|
393
|
+
final String kind = call.getString("kind");
|
|
394
|
+
final String value = call.getString("value");
|
|
395
|
+
if (kind == null) {
|
|
396
|
+
Log.e(CapacitorUpdater.TAG, "setDelay called without kind");
|
|
397
|
+
call.reject("setDelay called without kind");
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
this.editor.putString(DELAY_UPDATE, kind);
|
|
401
|
+
this.editor.putString(DELAY_UPDATE_VAL, value);
|
|
362
402
|
this.editor.commit();
|
|
403
|
+
Log.i(CapacitorUpdater.TAG, "Delay update saved");
|
|
363
404
|
call.resolve();
|
|
364
405
|
}
|
|
365
406
|
catch(final Exception e) {
|
|
@@ -368,22 +409,68 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
368
409
|
}
|
|
369
410
|
}
|
|
370
411
|
|
|
371
|
-
|
|
372
|
-
public void cancelDelay(final PluginCall call) {
|
|
412
|
+
private boolean _cancelDelay(String source) {
|
|
373
413
|
try {
|
|
374
|
-
|
|
375
|
-
this.editor.
|
|
414
|
+
this.editor.remove(DELAY_UPDATE);
|
|
415
|
+
this.editor.remove(DELAY_UPDATE_VAL);
|
|
376
416
|
this.editor.commit();
|
|
377
|
-
|
|
417
|
+
Log.i(CapacitorUpdater.TAG, "delay canceled from " + source);
|
|
418
|
+
return true;
|
|
378
419
|
}
|
|
379
420
|
catch(final Exception e) {
|
|
380
421
|
Log.e(CapacitorUpdater.TAG, "Failed to cancel update delay", e);
|
|
381
|
-
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
@PluginMethod
|
|
427
|
+
public void cancelDelay(final PluginCall call) {
|
|
428
|
+
if(this._cancelDelay("JS")) {
|
|
429
|
+
call.resolve();
|
|
430
|
+
} else {
|
|
431
|
+
call.reject("Failed to cancel delay");
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
private void _checkCancelDelay(Boolean killed) {
|
|
436
|
+
final String delayUpdate = this.prefs.getString(DELAY_UPDATE, "");
|
|
437
|
+
if ("".equals(delayUpdate)) {
|
|
438
|
+
if ("background".equals(delayUpdate) && !killed) {
|
|
439
|
+
this._cancelDelay("background check");
|
|
440
|
+
} else if ("kill".equals(delayUpdate) && killed) {
|
|
441
|
+
this._cancelDelay("kill check");
|
|
442
|
+
}
|
|
443
|
+
final String delayVal = this.prefs.getString(DELAY_UPDATE_VAL, "");
|
|
444
|
+
if ("".equals(delayVal)) {
|
|
445
|
+
this._cancelDelay("delayVal absent");
|
|
446
|
+
} else if ("date".equals(delayUpdate)) {
|
|
447
|
+
try {
|
|
448
|
+
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
|
449
|
+
Date date = sdf.parse(delayVal);
|
|
450
|
+
if (date.compareTo(new Date()) > 0) {
|
|
451
|
+
this._cancelDelay("date expired");
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
catch(final Exception e) {
|
|
455
|
+
this._cancelDelay("date parsing issue");
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
} else if ("nativeVersion".equals(delayUpdate)) {
|
|
459
|
+
try {
|
|
460
|
+
final Version versionLimit = new Version(delayVal);
|
|
461
|
+
if (this.currentVersionNative.isAtLeast(versionLimit)) {
|
|
462
|
+
this._cancelDelay("nativeVersion above limit");
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
catch(final Exception e) {
|
|
466
|
+
this._cancelDelay("nativeVersion parsing issue");
|
|
467
|
+
}
|
|
468
|
+
}
|
|
382
469
|
}
|
|
383
470
|
}
|
|
384
471
|
|
|
385
472
|
private Boolean _isAutoUpdateEnabled() {
|
|
386
|
-
return CapacitorUpdaterPlugin.this.autoUpdate && !"".equals(CapacitorUpdaterPlugin.this.
|
|
473
|
+
return CapacitorUpdaterPlugin.this.autoUpdate && !"".equals(CapacitorUpdaterPlugin.this.updateUrl);
|
|
387
474
|
}
|
|
388
475
|
|
|
389
476
|
@PluginMethod
|
|
@@ -410,6 +497,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
410
497
|
}
|
|
411
498
|
}
|
|
412
499
|
|
|
500
|
+
|
|
501
|
+
|
|
413
502
|
@Override // appMovedToForeground
|
|
414
503
|
public void onActivityStarted(@NonNull final Activity activity) {
|
|
415
504
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled()) {
|
|
@@ -417,8 +506,8 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
417
506
|
@Override
|
|
418
507
|
public void run() {
|
|
419
508
|
|
|
420
|
-
Log.i(CapacitorUpdater.TAG, "Check for update via: " + CapacitorUpdaterPlugin.this.
|
|
421
|
-
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.
|
|
509
|
+
Log.i(CapacitorUpdater.TAG, "Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl);
|
|
510
|
+
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, (res) -> {
|
|
422
511
|
try {
|
|
423
512
|
if (res.has("message")) {
|
|
424
513
|
Log.i(CapacitorUpdater.TAG, "message: " + res.get("message"));
|
|
@@ -442,7 +531,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
442
531
|
}
|
|
443
532
|
if(latest.isDownloaded()){
|
|
444
533
|
Log.e(CapacitorUpdater.TAG, "Latest bundle already exists and download is NOT required. Update will occur next time app moves to background.");
|
|
445
|
-
CapacitorUpdaterPlugin.this.implementation.
|
|
534
|
+
CapacitorUpdaterPlugin.this.implementation.setNext(latest.getId());
|
|
446
535
|
return;
|
|
447
536
|
}
|
|
448
537
|
}
|
|
@@ -457,7 +546,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
457
546
|
final String url = (String) res.get("url");
|
|
458
547
|
final BundleInfo next = CapacitorUpdaterPlugin.this.implementation.download(url, latestVersionName);
|
|
459
548
|
|
|
460
|
-
CapacitorUpdaterPlugin.this.implementation.
|
|
549
|
+
CapacitorUpdaterPlugin.this.implementation.setNext(next.getId());
|
|
461
550
|
} catch (final Exception e) {
|
|
462
551
|
Log.e(CapacitorUpdater.TAG, "error downloading file", e);
|
|
463
552
|
}
|
|
@@ -481,15 +570,12 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
481
570
|
public void onActivityStopped(@NonNull final Activity activity) {
|
|
482
571
|
Log.i(CapacitorUpdater.TAG, "Checking for pending update");
|
|
483
572
|
try {
|
|
484
|
-
final
|
|
485
|
-
this.
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (delayUpdate) {
|
|
573
|
+
final String delayUpdate = this.prefs.getString(DELAY_UPDATE, "");
|
|
574
|
+
this._checkCancelDelay(false);
|
|
575
|
+
if ("".equals(delayUpdate)) {
|
|
489
576
|
Log.i(CapacitorUpdater.TAG, "Update delayed to next backgrounding");
|
|
490
577
|
return;
|
|
491
578
|
}
|
|
492
|
-
|
|
493
579
|
final BundleInfo fallback = this.implementation.getFallbackVersion();
|
|
494
580
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
495
581
|
final BundleInfo next = this.implementation.getNextVersion();
|
|
@@ -504,7 +590,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
504
590
|
Log.d(CapacitorUpdater.TAG, "Next bundle is: " + next.getVersionName());
|
|
505
591
|
if (this.implementation.set(next) && this._reload()) {
|
|
506
592
|
Log.i(CapacitorUpdater.TAG, "Updated to bundle: " + next.getVersionName());
|
|
507
|
-
this.implementation.
|
|
593
|
+
this.implementation.setNext(null);
|
|
508
594
|
} else {
|
|
509
595
|
Log.e(CapacitorUpdater.TAG, "Update to bundle: " + next.getVersionName() + " Failed!");
|
|
510
596
|
}
|
|
@@ -523,7 +609,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
|
|
|
523
609
|
final JSObject ret = new JSObject();
|
|
524
610
|
ret.put("bundle", current);
|
|
525
611
|
this.notifyListeners("updateFailed", ret);
|
|
526
|
-
this.implementation.sendStats("
|
|
612
|
+
this.implementation.sendStats("update_fail", current.getVersionName());
|
|
527
613
|
if (!fallback.isBuiltin() && !fallback.equals(current)) {
|
|
528
614
|
final Boolean res = this.implementation.set(fallback);
|
|
529
615
|
if (res && this._reload()) {
|