@capgo/capacitor-updater 7.2.20 → 7.3.3
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 +6 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +48 -26
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +152 -141
- package/android/src/main/java/ee/forgr/capacitor_updater/{CapacitorUpdater.java → CapgoUpdater.java} +93 -59
- 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 -43
- 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 +16 -0
- package/dist/esm/definitions.d.ts +7 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Plugin/AES.swift +5 -3
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +108 -94
- package/ios/Plugin/{CapacitorUpdater.swift → CapgoUpdater.swift} +71 -69
- 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,16 +54,18 @@ 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.3.3";
|
|
63
64
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
64
65
|
|
|
65
66
|
private SharedPreferences.Editor editor;
|
|
66
67
|
private SharedPreferences prefs;
|
|
67
|
-
protected
|
|
68
|
+
protected CapgoUpdater implementation;
|
|
68
69
|
|
|
69
70
|
private Integer appReadyTimeout = 10000;
|
|
70
71
|
private Integer counterActivityCreate = 0;
|
|
@@ -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
|
|
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(CapacitorUpdater.TAG, "semaphoreWait " + waitTime);
|
|
221
237
|
try {
|
|
222
|
-
// Log.i(CapacitorUpdater.TAG, "semaphoreReady count " + CapacitorUpdaterPlugin.this.semaphoreReady.getCount());
|
|
223
238
|
semaphoreReady.awaitAdvanceInterruptibly(semaphoreReady.getPhase(), waitTime.longValue(), TimeUnit.SECONDS);
|
|
224
|
-
|
|
225
|
-
Log.i(CapacitorUpdater.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
|
}
|
|
@@ -499,17 +513,17 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
499
513
|
final String sessionKey = call.getString("sessionKey", "");
|
|
500
514
|
final String checksum = call.getString("checksum", "");
|
|
501
515
|
if (url == null) {
|
|
502
|
-
|
|
516
|
+
logger.error("Download called without url");
|
|
503
517
|
call.reject("Download called without url");
|
|
504
518
|
return;
|
|
505
519
|
}
|
|
506
520
|
if (version == null) {
|
|
507
|
-
|
|
521
|
+
logger.error("Download called without version");
|
|
508
522
|
call.reject("Download called without version");
|
|
509
523
|
return;
|
|
510
524
|
}
|
|
511
525
|
try {
|
|
512
|
-
|
|
526
|
+
logger.info("Downloading " + url);
|
|
513
527
|
startNewThread(() -> {
|
|
514
528
|
try {
|
|
515
529
|
final BundleInfo downloaded = CapacitorUpdaterPlugin.this.implementation.download(url, version, sessionKey, checksum);
|
|
@@ -519,7 +533,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
519
533
|
call.resolve(mapToJSObject(downloaded.toJSONMap()));
|
|
520
534
|
}
|
|
521
535
|
} catch (final Exception e) {
|
|
522
|
-
|
|
536
|
+
logger.error("Failed to download from: " + url + " " + e.getMessage());
|
|
523
537
|
call.reject("Failed to download from: " + url, e);
|
|
524
538
|
final JSObject ret = new JSObject();
|
|
525
539
|
ret.put("version", version);
|
|
@@ -529,7 +543,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
529
543
|
}
|
|
530
544
|
});
|
|
531
545
|
} catch (final Exception e) {
|
|
532
|
-
|
|
546
|
+
logger.error("Failed to download from: " + url + " " + e.getMessage());
|
|
533
547
|
call.reject("Failed to download from: " + url, e);
|
|
534
548
|
final JSObject ret = new JSObject();
|
|
535
549
|
ret.put("version", version);
|
|
@@ -542,7 +556,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
542
556
|
protected boolean _reload() {
|
|
543
557
|
final String path = this.implementation.getCurrentBundlePath();
|
|
544
558
|
this.semaphoreUp();
|
|
545
|
-
|
|
559
|
+
logger.info("Reloading: " + path);
|
|
546
560
|
|
|
547
561
|
AtomicReference<URL> url = new AtomicReference<>();
|
|
548
562
|
if (this.keepUrlPathAfterReload) {
|
|
@@ -553,7 +567,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
553
567
|
try {
|
|
554
568
|
url.set(new URL(this.bridge.getWebView().getUrl()));
|
|
555
569
|
} catch (Exception e) {
|
|
556
|
-
|
|
570
|
+
logger.error("Error executing on main thread " + e.getMessage());
|
|
557
571
|
}
|
|
558
572
|
mainThreadSemaphore.release();
|
|
559
573
|
});
|
|
@@ -562,11 +576,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
562
576
|
try {
|
|
563
577
|
url.set(new URL(this.bridge.getWebView().getUrl()));
|
|
564
578
|
} catch (Exception e) {
|
|
565
|
-
|
|
579
|
+
logger.error("Error executing on main thread " + e.getMessage());
|
|
566
580
|
}
|
|
567
581
|
}
|
|
568
582
|
} catch (InterruptedException e) {
|
|
569
|
-
|
|
583
|
+
logger.error("Error waiting for main thread or getting the current URL from webview " + e.getMessage());
|
|
570
584
|
}
|
|
571
585
|
}
|
|
572
586
|
|
|
@@ -588,7 +602,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
588
602
|
this.bridge.getWebView().clearHistory();
|
|
589
603
|
});
|
|
590
604
|
} catch (MalformedURLException e) {
|
|
591
|
-
|
|
605
|
+
logger.error("Cannot get finalUrl from capacitor bridge " + e.getMessage());
|
|
592
606
|
|
|
593
607
|
if (this.implementation.isUsingBuiltin()) {
|
|
594
608
|
this.bridge.setServerAssetPath(path);
|
|
@@ -615,11 +629,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
615
629
|
if (this._reload()) {
|
|
616
630
|
call.resolve();
|
|
617
631
|
} else {
|
|
618
|
-
|
|
632
|
+
logger.error("Reload failed");
|
|
619
633
|
call.reject("Reload failed");
|
|
620
634
|
}
|
|
621
635
|
} catch (final Exception e) {
|
|
622
|
-
|
|
636
|
+
logger.error("Could not reload " + e.getMessage());
|
|
623
637
|
call.reject("Could not reload", e);
|
|
624
638
|
}
|
|
625
639
|
}
|
|
@@ -628,20 +642,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
628
642
|
public void next(final PluginCall call) {
|
|
629
643
|
final String id = call.getString("id");
|
|
630
644
|
if (id == null) {
|
|
631
|
-
|
|
645
|
+
logger.error("Next called without id");
|
|
632
646
|
call.reject("Next called without id");
|
|
633
647
|
return;
|
|
634
648
|
}
|
|
635
649
|
try {
|
|
636
|
-
|
|
650
|
+
logger.info("Setting next active id " + id);
|
|
637
651
|
if (!this.implementation.setNextBundle(id)) {
|
|
638
|
-
|
|
652
|
+
logger.error("Set next id failed. Bundle " + id + " does not exist.");
|
|
639
653
|
call.reject("Set next id failed. Bundle " + id + " does not exist.");
|
|
640
654
|
} else {
|
|
641
655
|
call.resolve(mapToJSObject(this.implementation.getBundleInfo(id).toJSONMap()));
|
|
642
656
|
}
|
|
643
657
|
} catch (final Exception e) {
|
|
644
|
-
|
|
658
|
+
logger.error("Could not set next id " + id + " " + e.getMessage());
|
|
645
659
|
call.reject("Could not set next id: " + id, e);
|
|
646
660
|
}
|
|
647
661
|
}
|
|
@@ -650,21 +664,21 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
650
664
|
public void set(final PluginCall call) {
|
|
651
665
|
final String id = call.getString("id");
|
|
652
666
|
if (id == null) {
|
|
653
|
-
|
|
667
|
+
logger.error("Set called without id");
|
|
654
668
|
call.reject("Set called without id");
|
|
655
669
|
return;
|
|
656
670
|
}
|
|
657
671
|
try {
|
|
658
|
-
|
|
672
|
+
logger.info("Setting active bundle " + id);
|
|
659
673
|
if (!this.implementation.set(id)) {
|
|
660
|
-
|
|
674
|
+
logger.info("No such bundle " + id);
|
|
661
675
|
call.reject("Update failed, id " + id + " does not exist.");
|
|
662
676
|
} else {
|
|
663
|
-
|
|
677
|
+
logger.info("Bundle successfully set to " + id);
|
|
664
678
|
this.reload(call);
|
|
665
679
|
}
|
|
666
680
|
} catch (final Exception e) {
|
|
667
|
-
|
|
681
|
+
logger.error("Could not set id " + id + " " + e.getMessage());
|
|
668
682
|
call.reject("Could not set id " + id, e);
|
|
669
683
|
}
|
|
670
684
|
}
|
|
@@ -673,21 +687,21 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
673
687
|
public void delete(final PluginCall call) {
|
|
674
688
|
final String id = call.getString("id");
|
|
675
689
|
if (id == null) {
|
|
676
|
-
|
|
690
|
+
logger.error("missing id");
|
|
677
691
|
call.reject("missing id");
|
|
678
692
|
return;
|
|
679
693
|
}
|
|
680
|
-
|
|
694
|
+
logger.info("Deleting id " + id);
|
|
681
695
|
try {
|
|
682
696
|
final Boolean res = this.implementation.delete(id);
|
|
683
697
|
if (res) {
|
|
684
698
|
call.resolve();
|
|
685
699
|
} else {
|
|
686
|
-
|
|
700
|
+
logger.error("Delete failed, id " + id + " does not exist");
|
|
687
701
|
call.reject("Delete failed, id " + id + " does not exist or it cannot be deleted (perhaps it is the 'next' bundle)");
|
|
688
702
|
}
|
|
689
703
|
} catch (final Exception e) {
|
|
690
|
-
|
|
704
|
+
logger.error("Could not delete id " + id + " " + e.getMessage());
|
|
691
705
|
call.reject("Could not delete id " + id, e);
|
|
692
706
|
}
|
|
693
707
|
}
|
|
@@ -704,7 +718,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
704
718
|
ret.put("bundles", values);
|
|
705
719
|
call.resolve(ret);
|
|
706
720
|
} catch (final Exception e) {
|
|
707
|
-
|
|
721
|
+
logger.error("Could not list bundles " + e.getMessage());
|
|
708
722
|
call.reject("Could not list bundles", e);
|
|
709
723
|
}
|
|
710
724
|
}
|
|
@@ -733,11 +747,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
733
747
|
this.implementation.reset();
|
|
734
748
|
|
|
735
749
|
if (toLastSuccessful && !fallback.isBuiltin()) {
|
|
736
|
-
|
|
750
|
+
logger.info("Resetting to: " + fallback);
|
|
737
751
|
return this.implementation.set(fallback) && this._reload();
|
|
738
752
|
}
|
|
739
753
|
|
|
740
|
-
|
|
754
|
+
logger.info("Resetting to native.");
|
|
741
755
|
return this._reload();
|
|
742
756
|
}
|
|
743
757
|
|
|
@@ -749,16 +763,17 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
749
763
|
call.resolve();
|
|
750
764
|
return;
|
|
751
765
|
}
|
|
752
|
-
|
|
766
|
+
logger.error("Reset failed");
|
|
753
767
|
call.reject("Reset failed");
|
|
754
768
|
} catch (final Exception e) {
|
|
755
|
-
|
|
769
|
+
logger.error("Reset failed " + e.getMessage());
|
|
756
770
|
call.reject("Reset failed", e);
|
|
757
771
|
}
|
|
758
772
|
}
|
|
759
773
|
|
|
760
774
|
@PluginMethod
|
|
761
775
|
public void current(final PluginCall call) {
|
|
776
|
+
ensureBridgeSet();
|
|
762
777
|
try {
|
|
763
778
|
final JSObject ret = new JSObject();
|
|
764
779
|
final BundleInfo bundle = this.implementation.getCurrentBundle();
|
|
@@ -766,7 +781,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
766
781
|
ret.put("native", this.currentVersionNative);
|
|
767
782
|
call.resolve(ret);
|
|
768
783
|
} catch (final Exception e) {
|
|
769
|
-
|
|
784
|
+
logger.error("Could not get current bundle " + e.getMessage());
|
|
770
785
|
call.reject("Could not get current bundle", e);
|
|
771
786
|
}
|
|
772
787
|
}
|
|
@@ -782,7 +797,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
782
797
|
|
|
783
798
|
call.resolve(mapToJSObject(bundle.toJSONMap()));
|
|
784
799
|
} catch (final Exception e) {
|
|
785
|
-
|
|
800
|
+
logger.error("Could not get next bundle " + e.getMessage());
|
|
786
801
|
call.reject("Could not get next bundle", e);
|
|
787
802
|
}
|
|
788
803
|
}
|
|
@@ -800,18 +815,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
800
815
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
801
816
|
JSObject jsRes = mapToJSObject(res);
|
|
802
817
|
if (jsRes.has("error")) {
|
|
803
|
-
|
|
818
|
+
logger.error(Objects.requireNonNull(jsRes.getString("error")));
|
|
804
819
|
} else if (jsRes.has("version")) {
|
|
805
820
|
String newVersion = jsRes.getString("version");
|
|
806
821
|
String currentVersion = String.valueOf(CapacitorUpdaterPlugin.this.implementation.getCurrentBundle());
|
|
807
822
|
if (!Objects.equals(newVersion, currentVersion)) {
|
|
808
|
-
|
|
823
|
+
logger.info("New version found: " + newVersion);
|
|
809
824
|
CapacitorUpdaterPlugin.this.backgroundDownload();
|
|
810
825
|
}
|
|
811
826
|
}
|
|
812
827
|
});
|
|
813
828
|
} catch (final Exception e) {
|
|
814
|
-
|
|
829
|
+
logger.error("Failed to check for update " + e.getMessage());
|
|
815
830
|
}
|
|
816
831
|
}
|
|
817
832
|
},
|
|
@@ -822,18 +837,19 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
822
837
|
|
|
823
838
|
@PluginMethod
|
|
824
839
|
public void notifyAppReady(final PluginCall call) {
|
|
840
|
+
ensureBridgeSet();
|
|
825
841
|
try {
|
|
826
842
|
final BundleInfo bundle = this.implementation.getCurrentBundle();
|
|
827
843
|
this.implementation.setSuccess(bundle, this.autoDeletePrevious);
|
|
828
|
-
|
|
829
|
-
|
|
844
|
+
logger.info("Current bundle loaded successfully. ['notifyAppReady()' was called] " + bundle);
|
|
845
|
+
logger.info("semaphoreReady countDown");
|
|
830
846
|
this.semaphoreDown();
|
|
831
|
-
|
|
847
|
+
logger.info("semaphoreReady countDown done");
|
|
832
848
|
final JSObject ret = new JSObject();
|
|
833
849
|
ret.put("bundle", mapToJSObject(bundle.toJSONMap()));
|
|
834
850
|
call.resolve(ret);
|
|
835
851
|
} catch (final Exception e) {
|
|
836
|
-
|
|
852
|
+
logger.error("Failed to notify app ready state. [Error calling 'notifyAppReady()'] " + e.getMessage());
|
|
837
853
|
call.reject("Failed to commit app ready state.", e);
|
|
838
854
|
}
|
|
839
855
|
}
|
|
@@ -843,7 +859,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
843
859
|
try {
|
|
844
860
|
final JSONArray delayConditions = call.getData().optJSONArray("delayConditions");
|
|
845
861
|
if (delayConditions == null) {
|
|
846
|
-
|
|
862
|
+
logger.error("setMultiDelay called without delayCondition");
|
|
847
863
|
call.reject("setMultiDelay called without delayCondition");
|
|
848
864
|
return;
|
|
849
865
|
}
|
|
@@ -861,7 +877,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
861
877
|
call.reject("Failed to delay update");
|
|
862
878
|
}
|
|
863
879
|
} catch (final Exception e) {
|
|
864
|
-
|
|
880
|
+
logger.error("Failed to delay update, [Error calling 'setMultiDelay()'] " + e.getMessage());
|
|
865
881
|
call.reject("Failed to delay update", e);
|
|
866
882
|
}
|
|
867
883
|
}
|
|
@@ -880,7 +896,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
880
896
|
String serverUrl = config.getServerUrl();
|
|
881
897
|
if (serverUrl != null && !serverUrl.isEmpty()) {
|
|
882
898
|
// log warning autoupdate disabled when serverUrl is set
|
|
883
|
-
|
|
899
|
+
logger.warn("AutoUpdate is automatic disabled when serverUrl is set.");
|
|
884
900
|
}
|
|
885
901
|
return (
|
|
886
902
|
CapacitorUpdaterPlugin.this.autoUpdate &&
|
|
@@ -896,7 +912,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
896
912
|
ret.put("enabled", this._isAutoUpdateEnabled());
|
|
897
913
|
call.resolve(ret);
|
|
898
914
|
} catch (final Exception e) {
|
|
899
|
-
|
|
915
|
+
logger.error("Could not get autoUpdate status " + e.getMessage());
|
|
900
916
|
call.reject("Could not get autoUpdate status", e);
|
|
901
917
|
}
|
|
902
918
|
}
|
|
@@ -910,7 +926,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
910
926
|
ret.put("available", serverUrl == null || serverUrl.isEmpty());
|
|
911
927
|
call.resolve(ret);
|
|
912
928
|
} catch (final Exception e) {
|
|
913
|
-
|
|
929
|
+
logger.error("Could not get autoUpdate availability " + e.getMessage());
|
|
914
930
|
call.reject("Could not get autoUpdate availability", e);
|
|
915
931
|
}
|
|
916
932
|
}
|
|
@@ -922,7 +938,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
922
938
|
}
|
|
923
939
|
this.appReadyCheck = startNewThread(new DeferredNotifyAppReadyCheck());
|
|
924
940
|
} catch (final Exception e) {
|
|
925
|
-
|
|
941
|
+
logger.error("Failed to start " + DeferredNotifyAppReadyCheck.class.getName() + " " + e.getMessage());
|
|
926
942
|
}
|
|
927
943
|
}
|
|
928
944
|
|
|
@@ -935,10 +951,15 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
935
951
|
}
|
|
936
952
|
}
|
|
937
953
|
|
|
954
|
+
private void ensureBridgeSet() {
|
|
955
|
+
if (this.bridge != null && this.bridge.getWebView() != null) {
|
|
956
|
+
logger.setBridge(this.bridge);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
|
|
938
960
|
private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
|
|
939
961
|
if (error) {
|
|
940
|
-
|
|
941
|
-
CapacitorUpdater.TAG,
|
|
962
|
+
logger.info(
|
|
942
963
|
"endBackGroundTaskWithNotif error: " +
|
|
943
964
|
error +
|
|
944
965
|
" current: " +
|
|
@@ -956,7 +977,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
956
977
|
this.notifyListeners("noNeedUpdate", ret);
|
|
957
978
|
this.sendReadyToJs(current, msg);
|
|
958
979
|
this.backgroundDownloadTask = null;
|
|
959
|
-
|
|
980
|
+
logger.info("endBackGroundTaskWithNotif " + msg);
|
|
960
981
|
}
|
|
961
982
|
|
|
962
983
|
private Thread backgroundDownload() {
|
|
@@ -964,13 +985,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
964
985
|
? "Update will occur now."
|
|
965
986
|
: "Update will occur next time app moves to background.";
|
|
966
987
|
return startNewThread(() -> {
|
|
967
|
-
|
|
988
|
+
logger.info("Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl);
|
|
968
989
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
969
990
|
JSObject jsRes = mapToJSObject(res);
|
|
970
991
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
971
992
|
try {
|
|
972
993
|
if (jsRes.has("message")) {
|
|
973
|
-
|
|
994
|
+
logger.info("API message: " + jsRes.get("message"));
|
|
974
995
|
if (jsRes.has("major") && jsRes.getBoolean("major") && jsRes.has("version")) {
|
|
975
996
|
final JSObject majorAvailable = new JSObject();
|
|
976
997
|
majorAvailable.put("version", jsRes.getString("version"));
|
|
@@ -988,9 +1009,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
988
1009
|
final String latestVersionName = jsRes.getString("version");
|
|
989
1010
|
|
|
990
1011
|
if ("builtin".equals(latestVersionName)) {
|
|
991
|
-
|
|
1012
|
+
logger.info("Latest version is builtin");
|
|
992
1013
|
if (CapacitorUpdaterPlugin.this.implementation.directUpdate) {
|
|
993
|
-
|
|
1014
|
+
logger.info("Direct update to builtin version");
|
|
994
1015
|
this._reset(false);
|
|
995
1016
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
996
1017
|
"Updated to builtin version",
|
|
@@ -999,7 +1020,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
999
1020
|
false
|
|
1000
1021
|
);
|
|
1001
1022
|
} else {
|
|
1002
|
-
|
|
1023
|
+
logger.info("Setting next bundle to builtin");
|
|
1003
1024
|
CapacitorUpdaterPlugin.this.implementation.setNextBundle(BundleInfo.ID_BUILTIN);
|
|
1004
1025
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1005
1026
|
"Next update will be to builtin version",
|
|
@@ -1012,7 +1033,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1012
1033
|
}
|
|
1013
1034
|
|
|
1014
1035
|
if (!jsRes.has("url") || !CapacitorUpdaterPlugin.this.isValidURL(jsRes.getString("url"))) {
|
|
1015
|
-
|
|
1036
|
+
logger.error("Error no url or wrong format");
|
|
1016
1037
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1017
1038
|
"Error no url or wrong format",
|
|
1018
1039
|
current.getVersionName(),
|
|
@@ -1030,7 +1051,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1030
1051
|
final JSObject ret = new JSObject();
|
|
1031
1052
|
ret.put("bundle", mapToJSObject(latest.toJSONMap()));
|
|
1032
1053
|
if (latest.isErrorStatus()) {
|
|
1033
|
-
|
|
1054
|
+
logger.error("Latest bundle already exists, and is in error state. Aborting update.");
|
|
1034
1055
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1035
1056
|
"Latest bundle already exists, and is in error state. Aborting update.",
|
|
1036
1057
|
latestVersionName,
|
|
@@ -1040,17 +1061,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1040
1061
|
return;
|
|
1041
1062
|
}
|
|
1042
1063
|
if (latest.isDownloaded()) {
|
|
1043
|
-
|
|
1044
|
-
CapacitorUpdater.TAG,
|
|
1045
|
-
"Latest bundle already exists and download is NOT required. " + messageUpdate
|
|
1046
|
-
);
|
|
1064
|
+
logger.info("Latest bundle already exists and download is NOT required. " + messageUpdate);
|
|
1047
1065
|
if (CapacitorUpdaterPlugin.this.implementation.directUpdate) {
|
|
1048
1066
|
Gson gson = new Gson();
|
|
1049
1067
|
String delayUpdatePreferences = prefs.getString(DelayUpdateUtils.DELAY_CONDITION_PREFERENCES, "[]");
|
|
1050
1068
|
Type type = new TypeToken<ArrayList<DelayCondition>>() {}.getType();
|
|
1051
1069
|
ArrayList<DelayCondition> delayConditionList = gson.fromJson(delayUpdatePreferences, type);
|
|
1052
1070
|
if (delayConditionList != null && !delayConditionList.isEmpty()) {
|
|
1053
|
-
|
|
1071
|
+
logger.info("Update delayed until delay conditions met");
|
|
1054
1072
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1055
1073
|
"Update delayed until delay conditions met",
|
|
1056
1074
|
latestVersionName,
|
|
@@ -1080,24 +1098,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1080
1098
|
return;
|
|
1081
1099
|
}
|
|
1082
1100
|
if (latest.isDeleted()) {
|
|
1083
|
-
|
|
1084
|
-
CapacitorUpdater.TAG,
|
|
1085
|
-
"Latest bundle already exists and will be deleted, download will overwrite it."
|
|
1086
|
-
);
|
|
1101
|
+
logger.info("Latest bundle already exists and will be deleted, download will overwrite it.");
|
|
1087
1102
|
try {
|
|
1088
1103
|
final Boolean deleted = CapacitorUpdaterPlugin.this.implementation.delete(latest.getId(), true);
|
|
1089
1104
|
if (deleted) {
|
|
1090
|
-
|
|
1105
|
+
logger.info("Failed bundle deleted: " + latest.getVersionName());
|
|
1091
1106
|
}
|
|
1092
1107
|
} catch (final IOException e) {
|
|
1093
|
-
|
|
1108
|
+
logger.error("Failed to delete failed bundle: " + latest.getVersionName() + " " + e.getMessage());
|
|
1094
1109
|
}
|
|
1095
1110
|
}
|
|
1096
1111
|
}
|
|
1097
1112
|
startNewThread(() -> {
|
|
1098
1113
|
try {
|
|
1099
|
-
|
|
1100
|
-
CapacitorUpdater.TAG,
|
|
1114
|
+
logger.info(
|
|
1101
1115
|
"New bundle: " +
|
|
1102
1116
|
latestVersionName +
|
|
1103
1117
|
" found. Current is: " +
|
|
@@ -1131,7 +1145,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1131
1145
|
);
|
|
1132
1146
|
}
|
|
1133
1147
|
} catch (final Exception e) {
|
|
1134
|
-
|
|
1148
|
+
logger.error("error downloading file " + e.getMessage());
|
|
1135
1149
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1136
1150
|
"Error downloading file",
|
|
1137
1151
|
latestVersionName,
|
|
@@ -1141,11 +1155,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1141
1155
|
}
|
|
1142
1156
|
});
|
|
1143
1157
|
} else {
|
|
1144
|
-
|
|
1158
|
+
logger.info("No need to update, " + current.getId() + " is the latest bundle.");
|
|
1145
1159
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif("No need to update", latestVersionName, current, false);
|
|
1146
1160
|
}
|
|
1147
1161
|
} catch (final JSONException e) {
|
|
1148
|
-
|
|
1162
|
+
logger.error("error parsing JSON " + e.getMessage());
|
|
1149
1163
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1150
1164
|
"Error parsing JSON",
|
|
1151
1165
|
current.getVersionName(),
|
|
@@ -1164,7 +1178,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1164
1178
|
Type type = new TypeToken<ArrayList<DelayCondition>>() {}.getType();
|
|
1165
1179
|
ArrayList<DelayCondition> delayConditionList = gson.fromJson(delayUpdatePreferences, type);
|
|
1166
1180
|
if (delayConditionList != null && !delayConditionList.isEmpty()) {
|
|
1167
|
-
|
|
1181
|
+
logger.info("Update delayed until delay conditions met");
|
|
1168
1182
|
return;
|
|
1169
1183
|
}
|
|
1170
1184
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
@@ -1172,16 +1186,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1172
1186
|
|
|
1173
1187
|
if (next != null && !next.isErrorStatus() && !next.getId().equals(current.getId())) {
|
|
1174
1188
|
// There is a next bundle waiting for activation
|
|
1175
|
-
|
|
1189
|
+
logger.debug("Next bundle is: " + next.getVersionName());
|
|
1176
1190
|
if (this.implementation.set(next) && this._reload()) {
|
|
1177
|
-
|
|
1191
|
+
logger.info("Updated to bundle: " + next.getVersionName());
|
|
1178
1192
|
this.implementation.setNextBundle(null);
|
|
1179
1193
|
} else {
|
|
1180
|
-
|
|
1194
|
+
logger.error("Update to bundle: " + next.getVersionName() + " Failed!");
|
|
1181
1195
|
}
|
|
1182
1196
|
}
|
|
1183
1197
|
} catch (final Exception e) {
|
|
1184
|
-
|
|
1198
|
+
logger.error("Error during onActivityStopped " + e.getMessage());
|
|
1185
1199
|
}
|
|
1186
1200
|
}
|
|
1187
1201
|
|
|
@@ -1190,14 +1204,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1190
1204
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
1191
1205
|
|
|
1192
1206
|
if (current.isBuiltin()) {
|
|
1193
|
-
|
|
1207
|
+
logger.info("Built-in bundle is active. We skip the check for notifyAppReady.");
|
|
1194
1208
|
return;
|
|
1195
1209
|
}
|
|
1196
|
-
|
|
1210
|
+
logger.debug("Current bundle is: " + current);
|
|
1197
1211
|
|
|
1198
1212
|
if (BundleStatus.SUCCESS != current.getStatus()) {
|
|
1199
|
-
|
|
1200
|
-
|
|
1213
|
+
logger.error("notifyAppReady was not called, roll back current bundle: " + current.getId());
|
|
1214
|
+
logger.info("Did you forget to call 'notifyAppReady()' in your Capacitor App code?");
|
|
1201
1215
|
final JSObject ret = new JSObject();
|
|
1202
1216
|
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
1203
1217
|
this.notifyListeners("updateFailed", ret);
|
|
@@ -1205,18 +1219,18 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1205
1219
|
this.implementation.setError(current);
|
|
1206
1220
|
this._reset(true);
|
|
1207
1221
|
if (CapacitorUpdaterPlugin.this.autoDeleteFailed && !current.isBuiltin()) {
|
|
1208
|
-
|
|
1222
|
+
logger.info("Deleting failing bundle: " + current.getVersionName());
|
|
1209
1223
|
try {
|
|
1210
1224
|
final Boolean res = this.implementation.delete(current.getId(), false);
|
|
1211
1225
|
if (res) {
|
|
1212
|
-
|
|
1226
|
+
logger.info("Failed bundle deleted: " + current.getVersionName());
|
|
1213
1227
|
}
|
|
1214
1228
|
} catch (final IOException e) {
|
|
1215
|
-
|
|
1229
|
+
logger.error("Failed to delete failed bundle: " + current.getVersionName() + " " + e.getMessage());
|
|
1216
1230
|
}
|
|
1217
1231
|
}
|
|
1218
1232
|
} else {
|
|
1219
|
-
|
|
1233
|
+
logger.info("notifyAppReady was called. This is fine: " + current.getId());
|
|
1220
1234
|
}
|
|
1221
1235
|
}
|
|
1222
1236
|
|
|
@@ -1225,15 +1239,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1225
1239
|
@Override
|
|
1226
1240
|
public void run() {
|
|
1227
1241
|
try {
|
|
1228
|
-
|
|
1229
|
-
CapacitorUpdater.TAG,
|
|
1230
|
-
"Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady"
|
|
1231
|
-
);
|
|
1242
|
+
logger.info("Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady");
|
|
1232
1243
|
Thread.sleep(CapacitorUpdaterPlugin.this.appReadyTimeout);
|
|
1233
1244
|
CapacitorUpdaterPlugin.this.checkRevert();
|
|
1234
1245
|
CapacitorUpdaterPlugin.this.appReadyCheck = null;
|
|
1235
1246
|
} catch (final InterruptedException e) {
|
|
1236
|
-
|
|
1247
|
+
logger.info(DeferredNotifyAppReadyCheck.class.getName() + " was interrupted.");
|
|
1237
1248
|
}
|
|
1238
1249
|
}
|
|
1239
1250
|
}
|
|
@@ -1249,7 +1260,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1249
1260
|
) {
|
|
1250
1261
|
this.backgroundDownloadTask = this.backgroundDownload();
|
|
1251
1262
|
} else {
|
|
1252
|
-
|
|
1263
|
+
logger.info("Auto update is disabled");
|
|
1253
1264
|
this.sendReadyToJs(current, "disabled");
|
|
1254
1265
|
}
|
|
1255
1266
|
this.checkAppReady();
|
|
@@ -1258,14 +1269,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1258
1269
|
public void appMovedToBackground() {
|
|
1259
1270
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
1260
1271
|
CapacitorUpdaterPlugin.this.implementation.sendStats("app_moved_to_background", current.getVersionName());
|
|
1261
|
-
|
|
1272
|
+
logger.info("Checking for pending update");
|
|
1262
1273
|
try {
|
|
1263
1274
|
// We need to set "backgrounded time"
|
|
1264
1275
|
this.delayUpdateUtils.setBackgroundTimestamp(System.currentTimeMillis());
|
|
1265
1276
|
this.delayUpdateUtils.checkCancelDelay(DelayUpdateUtils.CancelDelaySource.BACKGROUND);
|
|
1266
1277
|
this.installNext();
|
|
1267
1278
|
} catch (final Exception e) {
|
|
1268
|
-
|
|
1279
|
+
logger.error("Error during onActivityStopped " + e.getMessage());
|
|
1269
1280
|
}
|
|
1270
1281
|
}
|
|
1271
1282
|
|
|
@@ -1293,7 +1304,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1293
1304
|
}
|
|
1294
1305
|
|
|
1295
1306
|
private void appKilled() {
|
|
1296
|
-
|
|
1307
|
+
logger.debug("onActivityDestroyed: all activity destroyed");
|
|
1297
1308
|
this.delayUpdateUtils.checkCancelDelay(DelayUpdateUtils.CancelDelaySource.KILLED);
|
|
1298
1309
|
}
|
|
1299
1310
|
|
|
@@ -1302,7 +1313,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1302
1313
|
if (isPreviousMainActivity) {
|
|
1303
1314
|
this.appMovedToForeground();
|
|
1304
1315
|
}
|
|
1305
|
-
|
|
1316
|
+
logger.info("onActivityStarted " + getActivity().getClass().getName());
|
|
1306
1317
|
isPreviousMainActivity = true;
|
|
1307
1318
|
}
|
|
1308
1319
|
|
|
@@ -1329,7 +1340,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1329
1340
|
|
|
1330
1341
|
@Override
|
|
1331
1342
|
public void handleOnDestroy() {
|
|
1332
|
-
|
|
1343
|
+
logger.info("onActivityDestroyed " + getActivity().getClass().getName());
|
|
1333
1344
|
this.implementation.activity = getActivity();
|
|
1334
1345
|
counterActivityCreate--;
|
|
1335
1346
|
if (counterActivityCreate == 0) {
|