@capgo/capacitor-updater 7.2.21 → 7.4.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/README.md +22 -16
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +48 -26
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +165 -135
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +85 -51
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipherV2.java +13 -8
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +43 -40
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +24 -20
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +8 -4
- package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +338 -0
- package/dist/docs.json +64 -30
- package/dist/esm/definitions.d.ts +13 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Plugin/AES.swift +5 -3
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +125 -93
- package/ios/Plugin/CapgoUpdater.swift +70 -68
- package/ios/Plugin/CryptoCipherV2.swift +31 -26
- package/ios/Plugin/DelayUpdateUtils.swift +26 -24
- package/ios/Plugin/Logger.swift +289 -0
- package/ios/Plugin/UserDefaultsExtension.swift +0 -2
- package/package.json +1 -1
|
@@ -14,7 +14,6 @@ import android.content.pm.PackageInfo;
|
|
|
14
14
|
import android.content.pm.PackageManager;
|
|
15
15
|
import android.os.Build;
|
|
16
16
|
import android.os.Looper;
|
|
17
|
-
import android.util.Log;
|
|
18
17
|
import com.getcapacitor.CapConfig;
|
|
19
18
|
import com.getcapacitor.JSArray;
|
|
20
19
|
import com.getcapacitor.JSObject;
|
|
@@ -55,11 +54,13 @@ import org.json.JSONObject;
|
|
|
55
54
|
@CapacitorPlugin(name = "CapacitorUpdater")
|
|
56
55
|
public class CapacitorUpdaterPlugin extends Plugin {
|
|
57
56
|
|
|
57
|
+
private final Logger logger = new Logger("CapgoUpdater");
|
|
58
|
+
|
|
58
59
|
private static final String updateUrlDefault = "https://plugin.capgo.app/updates";
|
|
59
60
|
private static final String statsUrlDefault = "https://plugin.capgo.app/stats";
|
|
60
61
|
private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
|
|
61
62
|
|
|
62
|
-
private final String PLUGIN_VERSION = "7.
|
|
63
|
+
private final String PLUGIN_VERSION = "7.4.0";
|
|
63
64
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
64
65
|
|
|
65
66
|
private SharedPreferences.Editor editor;
|
|
@@ -125,7 +126,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
125
126
|
this.editor = this.prefs.edit();
|
|
126
127
|
|
|
127
128
|
try {
|
|
128
|
-
this.implementation = new CapgoUpdater() {
|
|
129
|
+
this.implementation = new CapgoUpdater(logger) {
|
|
129
130
|
@Override
|
|
130
131
|
public void notifyDownload(final String id, final int percent) {
|
|
131
132
|
CapacitorUpdaterPlugin.this.notifyDownload(id, percent);
|
|
@@ -159,15 +160,31 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
159
160
|
this.prefs,
|
|
160
161
|
this.editor,
|
|
161
162
|
this.currentVersionNative,
|
|
162
|
-
CapacitorUpdaterPlugin.this::installNext
|
|
163
|
+
CapacitorUpdaterPlugin.this::installNext,
|
|
164
|
+
logger
|
|
163
165
|
);
|
|
164
166
|
} catch (final PackageManager.NameNotFoundException e) {
|
|
165
|
-
|
|
167
|
+
logger.error("Error instantiating implementation " + e.getMessage());
|
|
166
168
|
return;
|
|
167
169
|
} catch (final Exception e) {
|
|
168
|
-
|
|
170
|
+
logger.error("Error getting current native app version " + e.getMessage());
|
|
169
171
|
return;
|
|
170
172
|
}
|
|
173
|
+
|
|
174
|
+
boolean disableJSLogging = this.getConfig().getBoolean("disableJSLogging", false);
|
|
175
|
+
// Set the bridge in the Logger when webView is available
|
|
176
|
+
if (this.bridge != null && this.bridge.getWebView() != null && !disableJSLogging) {
|
|
177
|
+
logger.setBridge(this.bridge);
|
|
178
|
+
logger.info("WebView set successfully for logging");
|
|
179
|
+
} else {
|
|
180
|
+
logger.info("WebView not ready yet, will be set later");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Set logger for shared classes
|
|
184
|
+
CryptoCipherV2.setLogger(logger);
|
|
185
|
+
DownloadService.setLogger(logger);
|
|
186
|
+
DownloadWorkerManager.setLogger(logger);
|
|
187
|
+
|
|
171
188
|
final CapConfig config = CapConfig.loadDefault(this.getActivity());
|
|
172
189
|
this.implementation.appId = InternalUtils.getPackageName(getContext().getPackageManager(), getContext().getPackageName());
|
|
173
190
|
this.implementation.appId = config.getString("appId", this.implementation.appId);
|
|
@@ -178,7 +195,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
178
195
|
"appId is missing in capacitor.config.json or plugin config, and cannot be retrieved from the native app, please add it globally or in the plugin config"
|
|
179
196
|
);
|
|
180
197
|
}
|
|
181
|
-
|
|
198
|
+
logger.info("appId: " + implementation.appId);
|
|
182
199
|
this.implementation.publicKey = this.getConfig().getString("publicKey", "");
|
|
183
200
|
this.implementation.statsUrl = this.getConfig().getString("statsUrl", statsUrlDefault);
|
|
184
201
|
this.implementation.channelUrl = this.getConfig().getString("channelUrl", channelUrlDefault);
|
|
@@ -198,8 +215,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
198
215
|
this.implementation.deviceID = this.prefs.getString("appUUID", UUID.randomUUID().toString()).toLowerCase();
|
|
199
216
|
this.editor.putString("appUUID", this.implementation.deviceID);
|
|
200
217
|
this.editor.commit();
|
|
201
|
-
|
|
202
|
-
|
|
218
|
+
logger.info("init for device " + this.implementation.deviceID);
|
|
219
|
+
logger.info("version native " + this.currentVersionNative.getOriginalString());
|
|
203
220
|
this.autoDeleteFailed = this.getConfig().getBoolean("autoDeleteFailed", true);
|
|
204
221
|
this.autoDeletePrevious = this.getConfig().getBoolean("autoDeletePrevious", true);
|
|
205
222
|
this.updateUrl = this.getConfig().getString("updateUrl", updateUrlDefault);
|
|
@@ -217,14 +234,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
217
234
|
}
|
|
218
235
|
|
|
219
236
|
private void semaphoreWait(Number waitTime) {
|
|
220
|
-
// Log.i(CapgoUpdater.TAG, "semaphoreWait " + waitTime);
|
|
221
237
|
try {
|
|
222
|
-
// Log.i(CapgoUpdater.TAG, "semaphoreReady count " + CapacitorUpdaterPlugin.this.semaphoreReady.getCount());
|
|
223
238
|
semaphoreReady.awaitAdvanceInterruptibly(semaphoreReady.getPhase(), waitTime.longValue(), TimeUnit.SECONDS);
|
|
224
|
-
|
|
225
|
-
Log.i(CapgoUpdater.TAG, "semaphoreReady count " + semaphoreReady.getPhase());
|
|
239
|
+
logger.info("semaphoreReady count " + semaphoreReady.getPhase());
|
|
226
240
|
} catch (InterruptedException e) {
|
|
227
|
-
|
|
241
|
+
logger.info("semaphoreWait InterruptedException");
|
|
228
242
|
e.printStackTrace();
|
|
229
243
|
} catch (TimeoutException e) {
|
|
230
244
|
throw new RuntimeException(e);
|
|
@@ -232,25 +246,25 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
232
246
|
}
|
|
233
247
|
|
|
234
248
|
private void semaphoreUp() {
|
|
235
|
-
|
|
249
|
+
logger.info("semaphoreUp");
|
|
236
250
|
semaphoreReady.register();
|
|
237
251
|
}
|
|
238
252
|
|
|
239
253
|
private void semaphoreDown() {
|
|
240
|
-
|
|
241
|
-
|
|
254
|
+
logger.info("semaphoreDown");
|
|
255
|
+
logger.info("semaphoreDown count " + semaphoreReady.getPhase());
|
|
242
256
|
semaphoreReady.arriveAndDeregister();
|
|
243
257
|
}
|
|
244
258
|
|
|
245
259
|
private void sendReadyToJs(final BundleInfo current, final String msg) {
|
|
246
|
-
|
|
260
|
+
logger.info("sendReadyToJs");
|
|
247
261
|
final JSObject ret = new JSObject();
|
|
248
262
|
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
249
263
|
ret.put("status", msg);
|
|
250
264
|
startNewThread(() -> {
|
|
251
|
-
|
|
265
|
+
logger.info("semaphoreReady sendReadyToJs");
|
|
252
266
|
semaphoreWait(CapacitorUpdaterPlugin.this.appReadyTimeout);
|
|
253
|
-
|
|
267
|
+
logger.info("semaphoreReady sendReadyToJs done");
|
|
254
268
|
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
|
|
255
269
|
});
|
|
256
270
|
}
|
|
@@ -269,23 +283,23 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
269
283
|
!"".equals(previous.getOriginalString()) &&
|
|
270
284
|
!Objects.equals(this.currentVersionNative.getOriginalString(), previous.getOriginalString())
|
|
271
285
|
) {
|
|
272
|
-
|
|
286
|
+
logger.info("New native version detected: " + this.currentVersionNative);
|
|
273
287
|
this.implementation.reset(true);
|
|
274
288
|
final List<BundleInfo> installed = this.implementation.list(false);
|
|
275
289
|
for (final BundleInfo bundle : installed) {
|
|
276
290
|
try {
|
|
277
|
-
|
|
291
|
+
logger.info("Deleting obsolete bundle: " + bundle.getId());
|
|
278
292
|
this.implementation.delete(bundle.getId());
|
|
279
293
|
} catch (final Exception e) {
|
|
280
|
-
|
|
294
|
+
logger.error("Failed to delete: " + bundle.getId() + " " + e.getMessage());
|
|
281
295
|
}
|
|
282
296
|
}
|
|
283
297
|
}
|
|
284
298
|
} catch (final Exception e) {
|
|
285
|
-
|
|
299
|
+
logger.error("Could not determine the current version " + e.getMessage());
|
|
286
300
|
}
|
|
287
301
|
} catch (final Exception e) {
|
|
288
|
-
|
|
302
|
+
logger.error("Error calculating previous native version " + e.getMessage());
|
|
289
303
|
}
|
|
290
304
|
this.editor.putString("LatestVersionNative", this.currentVersionNative.toString());
|
|
291
305
|
this.editor.commit();
|
|
@@ -312,20 +326,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
312
326
|
}
|
|
313
327
|
}
|
|
314
328
|
} catch (final Exception e) {
|
|
315
|
-
|
|
329
|
+
logger.error("Could not notify listeners " + e.getMessage());
|
|
316
330
|
}
|
|
317
331
|
}
|
|
318
332
|
|
|
319
333
|
@PluginMethod
|
|
320
334
|
public void setUpdateUrl(final PluginCall call) {
|
|
321
335
|
if (!this.getConfig().getBoolean("allowModifyUrl", false)) {
|
|
322
|
-
|
|
336
|
+
logger.error("setUpdateUrl not allowed set allowModifyUrl in your config to true to allow it");
|
|
323
337
|
call.reject("setUpdateUrl not allowed");
|
|
324
338
|
return;
|
|
325
339
|
}
|
|
326
340
|
final String url = call.getString("url");
|
|
327
341
|
if (url == null) {
|
|
328
|
-
|
|
342
|
+
logger.error("setUpdateUrl called without url");
|
|
329
343
|
call.reject("setUpdateUrl called without url");
|
|
330
344
|
return;
|
|
331
345
|
}
|
|
@@ -336,13 +350,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
336
350
|
@PluginMethod
|
|
337
351
|
public void setStatsUrl(final PluginCall call) {
|
|
338
352
|
if (!this.getConfig().getBoolean("allowModifyUrl", false)) {
|
|
339
|
-
|
|
353
|
+
logger.error("setStatsUrl not allowed set allowModifyUrl in your config to true to allow it");
|
|
340
354
|
call.reject("setStatsUrl not allowed");
|
|
341
355
|
return;
|
|
342
356
|
}
|
|
343
357
|
final String url = call.getString("url");
|
|
344
358
|
if (url == null) {
|
|
345
|
-
|
|
359
|
+
logger.error("setStatsUrl called without url");
|
|
346
360
|
call.reject("setStatsUrl called without url");
|
|
347
361
|
return;
|
|
348
362
|
}
|
|
@@ -353,13 +367,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
353
367
|
@PluginMethod
|
|
354
368
|
public void setChannelUrl(final PluginCall call) {
|
|
355
369
|
if (!this.getConfig().getBoolean("allowModifyUrl", false)) {
|
|
356
|
-
|
|
370
|
+
logger.error("setChannelUrl not allowed set allowModifyUrl in your config to true to allow it");
|
|
357
371
|
call.reject("setChannelUrl not allowed");
|
|
358
372
|
return;
|
|
359
373
|
}
|
|
360
374
|
final String url = call.getString("url");
|
|
361
375
|
if (url == null) {
|
|
362
|
-
|
|
376
|
+
logger.error("setChannelUrl called without url");
|
|
363
377
|
call.reject("setChannelUrl called without url");
|
|
364
378
|
return;
|
|
365
379
|
}
|
|
@@ -374,7 +388,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
374
388
|
ret.put("version", this.implementation.versionBuild);
|
|
375
389
|
call.resolve(ret);
|
|
376
390
|
} catch (final Exception e) {
|
|
377
|
-
|
|
391
|
+
logger.error("Could not get version " + e.getMessage());
|
|
378
392
|
call.reject("Could not get version", e);
|
|
379
393
|
}
|
|
380
394
|
}
|
|
@@ -386,7 +400,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
386
400
|
ret.put("deviceId", this.implementation.deviceID);
|
|
387
401
|
call.resolve(ret);
|
|
388
402
|
} catch (final Exception e) {
|
|
389
|
-
|
|
403
|
+
logger.error("Could not get device id " + e.getMessage());
|
|
390
404
|
call.reject("Could not get device id", e);
|
|
391
405
|
}
|
|
392
406
|
}
|
|
@@ -395,7 +409,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
395
409
|
public void setCustomId(final PluginCall call) {
|
|
396
410
|
final String customId = call.getString("customId");
|
|
397
411
|
if (customId == null) {
|
|
398
|
-
|
|
412
|
+
logger.error("setCustomId called without customId");
|
|
399
413
|
call.reject("setCustomId called without customId");
|
|
400
414
|
return;
|
|
401
415
|
}
|
|
@@ -409,7 +423,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
409
423
|
ret.put("version", this.PLUGIN_VERSION);
|
|
410
424
|
call.resolve(ret);
|
|
411
425
|
} catch (final Exception e) {
|
|
412
|
-
|
|
426
|
+
logger.error("Could not get plugin version " + e.getMessage());
|
|
413
427
|
call.reject("Could not get plugin version", e);
|
|
414
428
|
}
|
|
415
429
|
}
|
|
@@ -419,7 +433,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
419
433
|
final Boolean triggerAutoUpdate = call.getBoolean("triggerAutoUpdate", false);
|
|
420
434
|
|
|
421
435
|
try {
|
|
422
|
-
|
|
436
|
+
logger.info("unsetChannel triggerAutoUpdate: " + triggerAutoUpdate);
|
|
423
437
|
startNewThread(() ->
|
|
424
438
|
CapacitorUpdaterPlugin.this.implementation.unsetChannel(res -> {
|
|
425
439
|
JSObject jsRes = mapToJSObject(res);
|
|
@@ -427,7 +441,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
427
441
|
call.reject(jsRes.getString("error"));
|
|
428
442
|
} else {
|
|
429
443
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() && Boolean.TRUE.equals(triggerAutoUpdate)) {
|
|
430
|
-
|
|
444
|
+
logger.info("Calling autoupdater after channel change!");
|
|
431
445
|
backgroundDownload();
|
|
432
446
|
}
|
|
433
447
|
call.resolve(jsRes);
|
|
@@ -435,7 +449,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
435
449
|
})
|
|
436
450
|
);
|
|
437
451
|
} catch (final Exception e) {
|
|
438
|
-
|
|
452
|
+
logger.error("Failed to unsetChannel: " + e.getMessage());
|
|
439
453
|
call.reject("Failed to unsetChannel: ", e);
|
|
440
454
|
}
|
|
441
455
|
}
|
|
@@ -446,12 +460,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
446
460
|
final Boolean triggerAutoUpdate = call.getBoolean("triggerAutoUpdate", false);
|
|
447
461
|
|
|
448
462
|
if (channel == null) {
|
|
449
|
-
|
|
463
|
+
logger.error("setChannel called without channel");
|
|
450
464
|
call.reject("setChannel called without channel");
|
|
451
465
|
return;
|
|
452
466
|
}
|
|
453
467
|
try {
|
|
454
|
-
|
|
468
|
+
logger.info("setChannel " + channel + " triggerAutoUpdate: " + triggerAutoUpdate);
|
|
455
469
|
startNewThread(() ->
|
|
456
470
|
CapacitorUpdaterPlugin.this.implementation.setChannel(channel, res -> {
|
|
457
471
|
JSObject jsRes = mapToJSObject(res);
|
|
@@ -459,7 +473,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
459
473
|
call.reject(jsRes.getString("error"));
|
|
460
474
|
} else {
|
|
461
475
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() && Boolean.TRUE.equals(triggerAutoUpdate)) {
|
|
462
|
-
|
|
476
|
+
logger.info("Calling autoupdater after channel change!");
|
|
463
477
|
backgroundDownload();
|
|
464
478
|
}
|
|
465
479
|
call.resolve(jsRes);
|
|
@@ -467,7 +481,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
467
481
|
})
|
|
468
482
|
);
|
|
469
483
|
} catch (final Exception e) {
|
|
470
|
-
|
|
484
|
+
logger.error("Failed to setChannel: " + channel + " " + e.getMessage());
|
|
471
485
|
call.reject("Failed to setChannel: " + channel, e);
|
|
472
486
|
}
|
|
473
487
|
}
|
|
@@ -475,7 +489,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
475
489
|
@PluginMethod
|
|
476
490
|
public void getChannel(final PluginCall call) {
|
|
477
491
|
try {
|
|
478
|
-
|
|
492
|
+
logger.info("getChannel");
|
|
479
493
|
startNewThread(() ->
|
|
480
494
|
CapacitorUpdaterPlugin.this.implementation.getChannel(res -> {
|
|
481
495
|
JSObject jsRes = mapToJSObject(res);
|
|
@@ -487,7 +501,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
487
501
|
})
|
|
488
502
|
);
|
|
489
503
|
} catch (final Exception e) {
|
|
490
|
-
|
|
504
|
+
logger.error("Failed to getChannel " + e.getMessage());
|
|
491
505
|
call.reject("Failed to getChannel", e);
|
|
492
506
|
}
|
|
493
507
|
}
|
|
@@ -498,28 +512,41 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
498
512
|
final String version = call.getString("version");
|
|
499
513
|
final String sessionKey = call.getString("sessionKey", "");
|
|
500
514
|
final String checksum = call.getString("checksum", "");
|
|
515
|
+
final JSONArray manifest = call.getData().optJSONArray("manifest");
|
|
501
516
|
if (url == null) {
|
|
502
|
-
|
|
517
|
+
logger.error("Download called without url");
|
|
503
518
|
call.reject("Download called without url");
|
|
504
519
|
return;
|
|
505
520
|
}
|
|
506
521
|
if (version == null) {
|
|
507
|
-
|
|
522
|
+
logger.error("Download called without version");
|
|
508
523
|
call.reject("Download called without version");
|
|
509
524
|
return;
|
|
510
525
|
}
|
|
511
526
|
try {
|
|
512
|
-
|
|
527
|
+
logger.info("Downloading " + url);
|
|
513
528
|
startNewThread(() -> {
|
|
514
529
|
try {
|
|
515
|
-
final BundleInfo downloaded
|
|
530
|
+
final BundleInfo downloaded;
|
|
531
|
+
if (manifest != null) {
|
|
532
|
+
// For manifest downloads, we need to handle this asynchronously
|
|
533
|
+
// since there's no synchronous downloadManifest method in Java
|
|
534
|
+
CapacitorUpdaterPlugin.this.implementation.downloadBackground(url, version, sessionKey, checksum, manifest);
|
|
535
|
+
// Return immediately with a pending status - the actual result will come via listeners
|
|
536
|
+
final String id = CapacitorUpdaterPlugin.this.implementation.randomString();
|
|
537
|
+
downloaded = new BundleInfo(id, version, BundleStatus.DOWNLOADING, new Date(System.currentTimeMillis()), "");
|
|
538
|
+
call.resolve(mapToJSObject(downloaded.toJSONMap()));
|
|
539
|
+
return;
|
|
540
|
+
} else {
|
|
541
|
+
downloaded = CapacitorUpdaterPlugin.this.implementation.download(url, version, sessionKey, checksum);
|
|
542
|
+
}
|
|
516
543
|
if (downloaded.isErrorStatus()) {
|
|
517
544
|
throw new RuntimeException("Download failed: " + downloaded.getStatus());
|
|
518
545
|
} else {
|
|
519
546
|
call.resolve(mapToJSObject(downloaded.toJSONMap()));
|
|
520
547
|
}
|
|
521
548
|
} catch (final Exception e) {
|
|
522
|
-
|
|
549
|
+
logger.error("Failed to download from: " + url + " " + e.getMessage());
|
|
523
550
|
call.reject("Failed to download from: " + url, e);
|
|
524
551
|
final JSObject ret = new JSObject();
|
|
525
552
|
ret.put("version", version);
|
|
@@ -529,7 +556,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
529
556
|
}
|
|
530
557
|
});
|
|
531
558
|
} catch (final Exception e) {
|
|
532
|
-
|
|
559
|
+
logger.error("Failed to download from: " + url + " " + e.getMessage());
|
|
533
560
|
call.reject("Failed to download from: " + url, e);
|
|
534
561
|
final JSObject ret = new JSObject();
|
|
535
562
|
ret.put("version", version);
|
|
@@ -542,7 +569,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
542
569
|
protected boolean _reload() {
|
|
543
570
|
final String path = this.implementation.getCurrentBundlePath();
|
|
544
571
|
this.semaphoreUp();
|
|
545
|
-
|
|
572
|
+
logger.info("Reloading: " + path);
|
|
546
573
|
|
|
547
574
|
AtomicReference<URL> url = new AtomicReference<>();
|
|
548
575
|
if (this.keepUrlPathAfterReload) {
|
|
@@ -553,7 +580,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
553
580
|
try {
|
|
554
581
|
url.set(new URL(this.bridge.getWebView().getUrl()));
|
|
555
582
|
} catch (Exception e) {
|
|
556
|
-
|
|
583
|
+
logger.error("Error executing on main thread " + e.getMessage());
|
|
557
584
|
}
|
|
558
585
|
mainThreadSemaphore.release();
|
|
559
586
|
});
|
|
@@ -562,11 +589,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
562
589
|
try {
|
|
563
590
|
url.set(new URL(this.bridge.getWebView().getUrl()));
|
|
564
591
|
} catch (Exception e) {
|
|
565
|
-
|
|
592
|
+
logger.error("Error executing on main thread " + e.getMessage());
|
|
566
593
|
}
|
|
567
594
|
}
|
|
568
595
|
} catch (InterruptedException e) {
|
|
569
|
-
|
|
596
|
+
logger.error("Error waiting for main thread or getting the current URL from webview " + e.getMessage());
|
|
570
597
|
}
|
|
571
598
|
}
|
|
572
599
|
|
|
@@ -588,7 +615,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
588
615
|
this.bridge.getWebView().clearHistory();
|
|
589
616
|
});
|
|
590
617
|
} catch (MalformedURLException e) {
|
|
591
|
-
|
|
618
|
+
logger.error("Cannot get finalUrl from capacitor bridge " + e.getMessage());
|
|
592
619
|
|
|
593
620
|
if (this.implementation.isUsingBuiltin()) {
|
|
594
621
|
this.bridge.setServerAssetPath(path);
|
|
@@ -615,11 +642,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
615
642
|
if (this._reload()) {
|
|
616
643
|
call.resolve();
|
|
617
644
|
} else {
|
|
618
|
-
|
|
645
|
+
logger.error("Reload failed");
|
|
619
646
|
call.reject("Reload failed");
|
|
620
647
|
}
|
|
621
648
|
} catch (final Exception e) {
|
|
622
|
-
|
|
649
|
+
logger.error("Could not reload " + e.getMessage());
|
|
623
650
|
call.reject("Could not reload", e);
|
|
624
651
|
}
|
|
625
652
|
}
|
|
@@ -628,20 +655,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
628
655
|
public void next(final PluginCall call) {
|
|
629
656
|
final String id = call.getString("id");
|
|
630
657
|
if (id == null) {
|
|
631
|
-
|
|
658
|
+
logger.error("Next called without id");
|
|
632
659
|
call.reject("Next called without id");
|
|
633
660
|
return;
|
|
634
661
|
}
|
|
635
662
|
try {
|
|
636
|
-
|
|
663
|
+
logger.info("Setting next active id " + id);
|
|
637
664
|
if (!this.implementation.setNextBundle(id)) {
|
|
638
|
-
|
|
665
|
+
logger.error("Set next id failed. Bundle " + id + " does not exist.");
|
|
639
666
|
call.reject("Set next id failed. Bundle " + id + " does not exist.");
|
|
640
667
|
} else {
|
|
641
668
|
call.resolve(mapToJSObject(this.implementation.getBundleInfo(id).toJSONMap()));
|
|
642
669
|
}
|
|
643
670
|
} catch (final Exception e) {
|
|
644
|
-
|
|
671
|
+
logger.error("Could not set next id " + id + " " + e.getMessage());
|
|
645
672
|
call.reject("Could not set next id: " + id, e);
|
|
646
673
|
}
|
|
647
674
|
}
|
|
@@ -650,21 +677,21 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
650
677
|
public void set(final PluginCall call) {
|
|
651
678
|
final String id = call.getString("id");
|
|
652
679
|
if (id == null) {
|
|
653
|
-
|
|
680
|
+
logger.error("Set called without id");
|
|
654
681
|
call.reject("Set called without id");
|
|
655
682
|
return;
|
|
656
683
|
}
|
|
657
684
|
try {
|
|
658
|
-
|
|
685
|
+
logger.info("Setting active bundle " + id);
|
|
659
686
|
if (!this.implementation.set(id)) {
|
|
660
|
-
|
|
687
|
+
logger.info("No such bundle " + id);
|
|
661
688
|
call.reject("Update failed, id " + id + " does not exist.");
|
|
662
689
|
} else {
|
|
663
|
-
|
|
690
|
+
logger.info("Bundle successfully set to " + id);
|
|
664
691
|
this.reload(call);
|
|
665
692
|
}
|
|
666
693
|
} catch (final Exception e) {
|
|
667
|
-
|
|
694
|
+
logger.error("Could not set id " + id + " " + e.getMessage());
|
|
668
695
|
call.reject("Could not set id " + id, e);
|
|
669
696
|
}
|
|
670
697
|
}
|
|
@@ -673,21 +700,21 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
673
700
|
public void delete(final PluginCall call) {
|
|
674
701
|
final String id = call.getString("id");
|
|
675
702
|
if (id == null) {
|
|
676
|
-
|
|
703
|
+
logger.error("missing id");
|
|
677
704
|
call.reject("missing id");
|
|
678
705
|
return;
|
|
679
706
|
}
|
|
680
|
-
|
|
707
|
+
logger.info("Deleting id " + id);
|
|
681
708
|
try {
|
|
682
709
|
final Boolean res = this.implementation.delete(id);
|
|
683
710
|
if (res) {
|
|
684
711
|
call.resolve();
|
|
685
712
|
} else {
|
|
686
|
-
|
|
713
|
+
logger.error("Delete failed, id " + id + " does not exist");
|
|
687
714
|
call.reject("Delete failed, id " + id + " does not exist or it cannot be deleted (perhaps it is the 'next' bundle)");
|
|
688
715
|
}
|
|
689
716
|
} catch (final Exception e) {
|
|
690
|
-
|
|
717
|
+
logger.error("Could not delete id " + id + " " + e.getMessage());
|
|
691
718
|
call.reject("Could not delete id " + id, e);
|
|
692
719
|
}
|
|
693
720
|
}
|
|
@@ -704,7 +731,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
704
731
|
ret.put("bundles", values);
|
|
705
732
|
call.resolve(ret);
|
|
706
733
|
} catch (final Exception e) {
|
|
707
|
-
|
|
734
|
+
logger.error("Could not list bundles " + e.getMessage());
|
|
708
735
|
call.reject("Could not list bundles", e);
|
|
709
736
|
}
|
|
710
737
|
}
|
|
@@ -733,11 +760,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
733
760
|
this.implementation.reset();
|
|
734
761
|
|
|
735
762
|
if (toLastSuccessful && !fallback.isBuiltin()) {
|
|
736
|
-
|
|
763
|
+
logger.info("Resetting to: " + fallback);
|
|
737
764
|
return this.implementation.set(fallback) && this._reload();
|
|
738
765
|
}
|
|
739
766
|
|
|
740
|
-
|
|
767
|
+
logger.info("Resetting to native.");
|
|
741
768
|
return this._reload();
|
|
742
769
|
}
|
|
743
770
|
|
|
@@ -749,16 +776,17 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
749
776
|
call.resolve();
|
|
750
777
|
return;
|
|
751
778
|
}
|
|
752
|
-
|
|
779
|
+
logger.error("Reset failed");
|
|
753
780
|
call.reject("Reset failed");
|
|
754
781
|
} catch (final Exception e) {
|
|
755
|
-
|
|
782
|
+
logger.error("Reset failed " + e.getMessage());
|
|
756
783
|
call.reject("Reset failed", e);
|
|
757
784
|
}
|
|
758
785
|
}
|
|
759
786
|
|
|
760
787
|
@PluginMethod
|
|
761
788
|
public void current(final PluginCall call) {
|
|
789
|
+
ensureBridgeSet();
|
|
762
790
|
try {
|
|
763
791
|
final JSObject ret = new JSObject();
|
|
764
792
|
final BundleInfo bundle = this.implementation.getCurrentBundle();
|
|
@@ -766,7 +794,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
766
794
|
ret.put("native", this.currentVersionNative);
|
|
767
795
|
call.resolve(ret);
|
|
768
796
|
} catch (final Exception e) {
|
|
769
|
-
|
|
797
|
+
logger.error("Could not get current bundle " + e.getMessage());
|
|
770
798
|
call.reject("Could not get current bundle", e);
|
|
771
799
|
}
|
|
772
800
|
}
|
|
@@ -782,7 +810,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
782
810
|
|
|
783
811
|
call.resolve(mapToJSObject(bundle.toJSONMap()));
|
|
784
812
|
} catch (final Exception e) {
|
|
785
|
-
|
|
813
|
+
logger.error("Could not get next bundle " + e.getMessage());
|
|
786
814
|
call.reject("Could not get next bundle", e);
|
|
787
815
|
}
|
|
788
816
|
}
|
|
@@ -800,18 +828,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
800
828
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
801
829
|
JSObject jsRes = mapToJSObject(res);
|
|
802
830
|
if (jsRes.has("error")) {
|
|
803
|
-
|
|
831
|
+
logger.error(Objects.requireNonNull(jsRes.getString("error")));
|
|
804
832
|
} else if (jsRes.has("version")) {
|
|
805
833
|
String newVersion = jsRes.getString("version");
|
|
806
834
|
String currentVersion = String.valueOf(CapacitorUpdaterPlugin.this.implementation.getCurrentBundle());
|
|
807
835
|
if (!Objects.equals(newVersion, currentVersion)) {
|
|
808
|
-
|
|
836
|
+
logger.info("New version found: " + newVersion);
|
|
809
837
|
CapacitorUpdaterPlugin.this.backgroundDownload();
|
|
810
838
|
}
|
|
811
839
|
}
|
|
812
840
|
});
|
|
813
841
|
} catch (final Exception e) {
|
|
814
|
-
|
|
842
|
+
logger.error("Failed to check for update " + e.getMessage());
|
|
815
843
|
}
|
|
816
844
|
}
|
|
817
845
|
},
|
|
@@ -822,18 +850,19 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
822
850
|
|
|
823
851
|
@PluginMethod
|
|
824
852
|
public void notifyAppReady(final PluginCall call) {
|
|
853
|
+
ensureBridgeSet();
|
|
825
854
|
try {
|
|
826
855
|
final BundleInfo bundle = this.implementation.getCurrentBundle();
|
|
827
856
|
this.implementation.setSuccess(bundle, this.autoDeletePrevious);
|
|
828
|
-
|
|
829
|
-
|
|
857
|
+
logger.info("Current bundle loaded successfully. ['notifyAppReady()' was called] " + bundle);
|
|
858
|
+
logger.info("semaphoreReady countDown");
|
|
830
859
|
this.semaphoreDown();
|
|
831
|
-
|
|
860
|
+
logger.info("semaphoreReady countDown done");
|
|
832
861
|
final JSObject ret = new JSObject();
|
|
833
862
|
ret.put("bundle", mapToJSObject(bundle.toJSONMap()));
|
|
834
863
|
call.resolve(ret);
|
|
835
864
|
} catch (final Exception e) {
|
|
836
|
-
|
|
865
|
+
logger.error("Failed to notify app ready state. [Error calling 'notifyAppReady()'] " + e.getMessage());
|
|
837
866
|
call.reject("Failed to commit app ready state.", e);
|
|
838
867
|
}
|
|
839
868
|
}
|
|
@@ -843,7 +872,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
843
872
|
try {
|
|
844
873
|
final JSONArray delayConditions = call.getData().optJSONArray("delayConditions");
|
|
845
874
|
if (delayConditions == null) {
|
|
846
|
-
|
|
875
|
+
logger.error("setMultiDelay called without delayCondition");
|
|
847
876
|
call.reject("setMultiDelay called without delayCondition");
|
|
848
877
|
return;
|
|
849
878
|
}
|
|
@@ -861,7 +890,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
861
890
|
call.reject("Failed to delay update");
|
|
862
891
|
}
|
|
863
892
|
} catch (final Exception e) {
|
|
864
|
-
|
|
893
|
+
logger.error("Failed to delay update, [Error calling 'setMultiDelay()'] " + e.getMessage());
|
|
865
894
|
call.reject("Failed to delay update", e);
|
|
866
895
|
}
|
|
867
896
|
}
|
|
@@ -880,7 +909,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
880
909
|
String serverUrl = config.getServerUrl();
|
|
881
910
|
if (serverUrl != null && !serverUrl.isEmpty()) {
|
|
882
911
|
// log warning autoupdate disabled when serverUrl is set
|
|
883
|
-
|
|
912
|
+
logger.warn("AutoUpdate is automatic disabled when serverUrl is set.");
|
|
884
913
|
}
|
|
885
914
|
return (
|
|
886
915
|
CapacitorUpdaterPlugin.this.autoUpdate &&
|
|
@@ -896,7 +925,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
896
925
|
ret.put("enabled", this._isAutoUpdateEnabled());
|
|
897
926
|
call.resolve(ret);
|
|
898
927
|
} catch (final Exception e) {
|
|
899
|
-
|
|
928
|
+
logger.error("Could not get autoUpdate status " + e.getMessage());
|
|
900
929
|
call.reject("Could not get autoUpdate status", e);
|
|
901
930
|
}
|
|
902
931
|
}
|
|
@@ -910,7 +939,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
910
939
|
ret.put("available", serverUrl == null || serverUrl.isEmpty());
|
|
911
940
|
call.resolve(ret);
|
|
912
941
|
} catch (final Exception e) {
|
|
913
|
-
|
|
942
|
+
logger.error("Could not get autoUpdate availability " + e.getMessage());
|
|
914
943
|
call.reject("Could not get autoUpdate availability", e);
|
|
915
944
|
}
|
|
916
945
|
}
|
|
@@ -922,7 +951,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
922
951
|
}
|
|
923
952
|
this.appReadyCheck = startNewThread(new DeferredNotifyAppReadyCheck());
|
|
924
953
|
} catch (final Exception e) {
|
|
925
|
-
|
|
954
|
+
logger.error("Failed to start " + DeferredNotifyAppReadyCheck.class.getName() + " " + e.getMessage());
|
|
926
955
|
}
|
|
927
956
|
}
|
|
928
957
|
|
|
@@ -935,10 +964,15 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
935
964
|
}
|
|
936
965
|
}
|
|
937
966
|
|
|
967
|
+
private void ensureBridgeSet() {
|
|
968
|
+
if (this.bridge != null && this.bridge.getWebView() != null) {
|
|
969
|
+
logger.setBridge(this.bridge);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
938
973
|
private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
|
|
939
974
|
if (error) {
|
|
940
|
-
|
|
941
|
-
CapgoUpdater.TAG,
|
|
975
|
+
logger.info(
|
|
942
976
|
"endBackGroundTaskWithNotif error: " +
|
|
943
977
|
error +
|
|
944
978
|
" current: " +
|
|
@@ -956,7 +990,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
956
990
|
this.notifyListeners("noNeedUpdate", ret);
|
|
957
991
|
this.sendReadyToJs(current, msg);
|
|
958
992
|
this.backgroundDownloadTask = null;
|
|
959
|
-
|
|
993
|
+
logger.info("endBackGroundTaskWithNotif " + msg);
|
|
960
994
|
}
|
|
961
995
|
|
|
962
996
|
private Thread backgroundDownload() {
|
|
@@ -964,13 +998,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
964
998
|
? "Update will occur now."
|
|
965
999
|
: "Update will occur next time app moves to background.";
|
|
966
1000
|
return startNewThread(() -> {
|
|
967
|
-
|
|
1001
|
+
logger.info("Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl);
|
|
968
1002
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
969
1003
|
JSObject jsRes = mapToJSObject(res);
|
|
970
1004
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
971
1005
|
try {
|
|
972
1006
|
if (jsRes.has("message")) {
|
|
973
|
-
|
|
1007
|
+
logger.info("API message: " + jsRes.get("message"));
|
|
974
1008
|
if (jsRes.has("major") && jsRes.getBoolean("major") && jsRes.has("version")) {
|
|
975
1009
|
final JSObject majorAvailable = new JSObject();
|
|
976
1010
|
majorAvailable.put("version", jsRes.getString("version"));
|
|
@@ -988,9 +1022,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
988
1022
|
final String latestVersionName = jsRes.getString("version");
|
|
989
1023
|
|
|
990
1024
|
if ("builtin".equals(latestVersionName)) {
|
|
991
|
-
|
|
1025
|
+
logger.info("Latest version is builtin");
|
|
992
1026
|
if (CapacitorUpdaterPlugin.this.implementation.directUpdate) {
|
|
993
|
-
|
|
1027
|
+
logger.info("Direct update to builtin version");
|
|
994
1028
|
this._reset(false);
|
|
995
1029
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
996
1030
|
"Updated to builtin version",
|
|
@@ -999,7 +1033,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
999
1033
|
false
|
|
1000
1034
|
);
|
|
1001
1035
|
} else {
|
|
1002
|
-
|
|
1036
|
+
logger.info("Setting next bundle to builtin");
|
|
1003
1037
|
CapacitorUpdaterPlugin.this.implementation.setNextBundle(BundleInfo.ID_BUILTIN);
|
|
1004
1038
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1005
1039
|
"Next update will be to builtin version",
|
|
@@ -1012,7 +1046,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1012
1046
|
}
|
|
1013
1047
|
|
|
1014
1048
|
if (!jsRes.has("url") || !CapacitorUpdaterPlugin.this.isValidURL(jsRes.getString("url"))) {
|
|
1015
|
-
|
|
1049
|
+
logger.error("Error no url or wrong format");
|
|
1016
1050
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1017
1051
|
"Error no url or wrong format",
|
|
1018
1052
|
current.getVersionName(),
|
|
@@ -1030,7 +1064,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1030
1064
|
final JSObject ret = new JSObject();
|
|
1031
1065
|
ret.put("bundle", mapToJSObject(latest.toJSONMap()));
|
|
1032
1066
|
if (latest.isErrorStatus()) {
|
|
1033
|
-
|
|
1067
|
+
logger.error("Latest bundle already exists, and is in error state. Aborting update.");
|
|
1034
1068
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1035
1069
|
"Latest bundle already exists, and is in error state. Aborting update.",
|
|
1036
1070
|
latestVersionName,
|
|
@@ -1040,14 +1074,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1040
1074
|
return;
|
|
1041
1075
|
}
|
|
1042
1076
|
if (latest.isDownloaded()) {
|
|
1043
|
-
|
|
1077
|
+
logger.info("Latest bundle already exists and download is NOT required. " + messageUpdate);
|
|
1044
1078
|
if (CapacitorUpdaterPlugin.this.implementation.directUpdate) {
|
|
1045
1079
|
Gson gson = new Gson();
|
|
1046
1080
|
String delayUpdatePreferences = prefs.getString(DelayUpdateUtils.DELAY_CONDITION_PREFERENCES, "[]");
|
|
1047
1081
|
Type type = new TypeToken<ArrayList<DelayCondition>>() {}.getType();
|
|
1048
1082
|
ArrayList<DelayCondition> delayConditionList = gson.fromJson(delayUpdatePreferences, type);
|
|
1049
1083
|
if (delayConditionList != null && !delayConditionList.isEmpty()) {
|
|
1050
|
-
|
|
1084
|
+
logger.info("Update delayed until delay conditions met");
|
|
1051
1085
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1052
1086
|
"Update delayed until delay conditions met",
|
|
1053
1087
|
latestVersionName,
|
|
@@ -1077,24 +1111,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1077
1111
|
return;
|
|
1078
1112
|
}
|
|
1079
1113
|
if (latest.isDeleted()) {
|
|
1080
|
-
|
|
1081
|
-
CapgoUpdater.TAG,
|
|
1082
|
-
"Latest bundle already exists and will be deleted, download will overwrite it."
|
|
1083
|
-
);
|
|
1114
|
+
logger.info("Latest bundle already exists and will be deleted, download will overwrite it.");
|
|
1084
1115
|
try {
|
|
1085
1116
|
final Boolean deleted = CapacitorUpdaterPlugin.this.implementation.delete(latest.getId(), true);
|
|
1086
1117
|
if (deleted) {
|
|
1087
|
-
|
|
1118
|
+
logger.info("Failed bundle deleted: " + latest.getVersionName());
|
|
1088
1119
|
}
|
|
1089
1120
|
} catch (final IOException e) {
|
|
1090
|
-
|
|
1121
|
+
logger.error("Failed to delete failed bundle: " + latest.getVersionName() + " " + e.getMessage());
|
|
1091
1122
|
}
|
|
1092
1123
|
}
|
|
1093
1124
|
}
|
|
1094
1125
|
startNewThread(() -> {
|
|
1095
1126
|
try {
|
|
1096
|
-
|
|
1097
|
-
CapgoUpdater.TAG,
|
|
1127
|
+
logger.info(
|
|
1098
1128
|
"New bundle: " +
|
|
1099
1129
|
latestVersionName +
|
|
1100
1130
|
" found. Current is: " +
|
|
@@ -1128,7 +1158,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1128
1158
|
);
|
|
1129
1159
|
}
|
|
1130
1160
|
} catch (final Exception e) {
|
|
1131
|
-
|
|
1161
|
+
logger.error("error downloading file " + e.getMessage());
|
|
1132
1162
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1133
1163
|
"Error downloading file",
|
|
1134
1164
|
latestVersionName,
|
|
@@ -1138,11 +1168,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1138
1168
|
}
|
|
1139
1169
|
});
|
|
1140
1170
|
} else {
|
|
1141
|
-
|
|
1171
|
+
logger.info("No need to update, " + current.getId() + " is the latest bundle.");
|
|
1142
1172
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif("No need to update", latestVersionName, current, false);
|
|
1143
1173
|
}
|
|
1144
1174
|
} catch (final JSONException e) {
|
|
1145
|
-
|
|
1175
|
+
logger.error("error parsing JSON " + e.getMessage());
|
|
1146
1176
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1147
1177
|
"Error parsing JSON",
|
|
1148
1178
|
current.getVersionName(),
|
|
@@ -1161,7 +1191,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1161
1191
|
Type type = new TypeToken<ArrayList<DelayCondition>>() {}.getType();
|
|
1162
1192
|
ArrayList<DelayCondition> delayConditionList = gson.fromJson(delayUpdatePreferences, type);
|
|
1163
1193
|
if (delayConditionList != null && !delayConditionList.isEmpty()) {
|
|
1164
|
-
|
|
1194
|
+
logger.info("Update delayed until delay conditions met");
|
|
1165
1195
|
return;
|
|
1166
1196
|
}
|
|
1167
1197
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
@@ -1169,16 +1199,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1169
1199
|
|
|
1170
1200
|
if (next != null && !next.isErrorStatus() && !next.getId().equals(current.getId())) {
|
|
1171
1201
|
// There is a next bundle waiting for activation
|
|
1172
|
-
|
|
1202
|
+
logger.debug("Next bundle is: " + next.getVersionName());
|
|
1173
1203
|
if (this.implementation.set(next) && this._reload()) {
|
|
1174
|
-
|
|
1204
|
+
logger.info("Updated to bundle: " + next.getVersionName());
|
|
1175
1205
|
this.implementation.setNextBundle(null);
|
|
1176
1206
|
} else {
|
|
1177
|
-
|
|
1207
|
+
logger.error("Update to bundle: " + next.getVersionName() + " Failed!");
|
|
1178
1208
|
}
|
|
1179
1209
|
}
|
|
1180
1210
|
} catch (final Exception e) {
|
|
1181
|
-
|
|
1211
|
+
logger.error("Error during onActivityStopped " + e.getMessage());
|
|
1182
1212
|
}
|
|
1183
1213
|
}
|
|
1184
1214
|
|
|
@@ -1187,14 +1217,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1187
1217
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
1188
1218
|
|
|
1189
1219
|
if (current.isBuiltin()) {
|
|
1190
|
-
|
|
1220
|
+
logger.info("Built-in bundle is active. We skip the check for notifyAppReady.");
|
|
1191
1221
|
return;
|
|
1192
1222
|
}
|
|
1193
|
-
|
|
1223
|
+
logger.debug("Current bundle is: " + current);
|
|
1194
1224
|
|
|
1195
1225
|
if (BundleStatus.SUCCESS != current.getStatus()) {
|
|
1196
|
-
|
|
1197
|
-
|
|
1226
|
+
logger.error("notifyAppReady was not called, roll back current bundle: " + current.getId());
|
|
1227
|
+
logger.info("Did you forget to call 'notifyAppReady()' in your Capacitor App code?");
|
|
1198
1228
|
final JSObject ret = new JSObject();
|
|
1199
1229
|
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
1200
1230
|
this.notifyListeners("updateFailed", ret);
|
|
@@ -1202,18 +1232,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1202
1232
|
this.implementation.setError(current);
|
|
1203
1233
|
this._reset(true);
|
|
1204
1234
|
if (CapacitorUpdaterPlugin.this.autoDeleteFailed && !current.isBuiltin()) {
|
|
1205
|
-
|
|
1235
|
+
logger.info("Deleting failing bundle: " + current.getVersionName());
|
|
1206
1236
|
try {
|
|
1207
1237
|
final Boolean res = this.implementation.delete(current.getId(), false);
|
|
1208
1238
|
if (res) {
|
|
1209
|
-
|
|
1239
|
+
logger.info("Failed bundle deleted: " + current.getVersionName());
|
|
1210
1240
|
}
|
|
1211
1241
|
} catch (final IOException e) {
|
|
1212
|
-
|
|
1242
|
+
logger.error("Failed to delete failed bundle: " + current.getVersionName() + " " + e.getMessage());
|
|
1213
1243
|
}
|
|
1214
1244
|
}
|
|
1215
1245
|
} else {
|
|
1216
|
-
|
|
1246
|
+
logger.info("notifyAppReady was called. This is fine: " + current.getId());
|
|
1217
1247
|
}
|
|
1218
1248
|
}
|
|
1219
1249
|
|
|
@@ -1222,12 +1252,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1222
1252
|
@Override
|
|
1223
1253
|
public void run() {
|
|
1224
1254
|
try {
|
|
1225
|
-
|
|
1255
|
+
logger.info("Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady");
|
|
1226
1256
|
Thread.sleep(CapacitorUpdaterPlugin.this.appReadyTimeout);
|
|
1227
1257
|
CapacitorUpdaterPlugin.this.checkRevert();
|
|
1228
1258
|
CapacitorUpdaterPlugin.this.appReadyCheck = null;
|
|
1229
1259
|
} catch (final InterruptedException e) {
|
|
1230
|
-
|
|
1260
|
+
logger.info(DeferredNotifyAppReadyCheck.class.getName() + " was interrupted.");
|
|
1231
1261
|
}
|
|
1232
1262
|
}
|
|
1233
1263
|
}
|
|
@@ -1243,7 +1273,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1243
1273
|
) {
|
|
1244
1274
|
this.backgroundDownloadTask = this.backgroundDownload();
|
|
1245
1275
|
} else {
|
|
1246
|
-
|
|
1276
|
+
logger.info("Auto update is disabled");
|
|
1247
1277
|
this.sendReadyToJs(current, "disabled");
|
|
1248
1278
|
}
|
|
1249
1279
|
this.checkAppReady();
|
|
@@ -1252,14 +1282,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1252
1282
|
public void appMovedToBackground() {
|
|
1253
1283
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
1254
1284
|
CapacitorUpdaterPlugin.this.implementation.sendStats("app_moved_to_background", current.getVersionName());
|
|
1255
|
-
|
|
1285
|
+
logger.info("Checking for pending update");
|
|
1256
1286
|
try {
|
|
1257
1287
|
// We need to set "backgrounded time"
|
|
1258
1288
|
this.delayUpdateUtils.setBackgroundTimestamp(System.currentTimeMillis());
|
|
1259
1289
|
this.delayUpdateUtils.checkCancelDelay(DelayUpdateUtils.CancelDelaySource.BACKGROUND);
|
|
1260
1290
|
this.installNext();
|
|
1261
1291
|
} catch (final Exception e) {
|
|
1262
|
-
|
|
1292
|
+
logger.error("Error during onActivityStopped " + e.getMessage());
|
|
1263
1293
|
}
|
|
1264
1294
|
}
|
|
1265
1295
|
|
|
@@ -1287,7 +1317,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1287
1317
|
}
|
|
1288
1318
|
|
|
1289
1319
|
private void appKilled() {
|
|
1290
|
-
|
|
1320
|
+
logger.debug("onActivityDestroyed: all activity destroyed");
|
|
1291
1321
|
this.delayUpdateUtils.checkCancelDelay(DelayUpdateUtils.CancelDelaySource.KILLED);
|
|
1292
1322
|
}
|
|
1293
1323
|
|
|
@@ -1296,7 +1326,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1296
1326
|
if (isPreviousMainActivity) {
|
|
1297
1327
|
this.appMovedToForeground();
|
|
1298
1328
|
}
|
|
1299
|
-
|
|
1329
|
+
logger.info("onActivityStarted " + getActivity().getClass().getName());
|
|
1300
1330
|
isPreviousMainActivity = true;
|
|
1301
1331
|
}
|
|
1302
1332
|
|
|
@@ -1323,7 +1353,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1323
1353
|
|
|
1324
1354
|
@Override
|
|
1325
1355
|
public void handleOnDestroy() {
|
|
1326
|
-
|
|
1356
|
+
logger.info("onActivityDestroyed " + getActivity().getClass().getName());
|
|
1327
1357
|
this.implementation.activity = getActivity();
|
|
1328
1358
|
counterActivityCreate--;
|
|
1329
1359
|
if (counterActivityCreate == 0) {
|