@capgo/capacitor-updater 7.2.19 → 7.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/ee/forgr/capacitor_updater/BundleInfo.java +22 -8
- package/android/src/main/java/ee/forgr/capacitor_updater/Callback.java +2 -2
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +185 -188
- package/android/src/main/java/ee/forgr/capacitor_updater/{CapacitorUpdater.java → CapgoUpdater.java} +50 -49
- package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipherV2.java +7 -7
- package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +21 -24
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +1 -1
- package/ios/Plugin/AES.swift +2 -2
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +93 -93
- package/ios/Plugin/{CapacitorUpdater.swift → CapgoUpdater.swift} +67 -67
- package/ios/Plugin/CryptoCipherV2.swift +25 -25
- package/ios/Plugin/DelayUpdateUtils.swift +23 -23
- package/package.json +1 -1
|
@@ -36,6 +36,7 @@ import java.util.Arrays;
|
|
|
36
36
|
import java.util.Date;
|
|
37
37
|
import java.util.Iterator;
|
|
38
38
|
import java.util.List;
|
|
39
|
+
import java.util.Map;
|
|
39
40
|
import java.util.Objects;
|
|
40
41
|
import java.util.Timer;
|
|
41
42
|
import java.util.TimerTask;
|
|
@@ -58,12 +59,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
58
59
|
private static final String statsUrlDefault = "https://plugin.capgo.app/stats";
|
|
59
60
|
private static final String channelUrlDefault = "https://plugin.capgo.app/channel_self";
|
|
60
61
|
|
|
61
|
-
private final String PLUGIN_VERSION = "7.2.
|
|
62
|
+
private final String PLUGIN_VERSION = "7.2.21";
|
|
62
63
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
63
64
|
|
|
64
65
|
private SharedPreferences.Editor editor;
|
|
65
66
|
private SharedPreferences prefs;
|
|
66
|
-
protected
|
|
67
|
+
protected CapgoUpdater implementation;
|
|
67
68
|
|
|
68
69
|
private Integer appReadyTimeout = 10000;
|
|
69
70
|
private Integer counterActivityCreate = 0;
|
|
@@ -89,6 +90,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
89
90
|
|
|
90
91
|
private DelayUpdateUtils delayUpdateUtils;
|
|
91
92
|
|
|
93
|
+
private JSObject mapToJSObject(Map<String, Object> map) {
|
|
94
|
+
JSObject jsObject = new JSObject();
|
|
95
|
+
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
96
|
+
jsObject.put(entry.getKey(), entry.getValue());
|
|
97
|
+
}
|
|
98
|
+
return jsObject;
|
|
99
|
+
}
|
|
100
|
+
|
|
92
101
|
public Thread startNewThread(final Runnable function, Number waitTime) {
|
|
93
102
|
Thread bgTask = new Thread(() -> {
|
|
94
103
|
try {
|
|
@@ -116,7 +125,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
116
125
|
this.editor = this.prefs.edit();
|
|
117
126
|
|
|
118
127
|
try {
|
|
119
|
-
this.implementation = new
|
|
128
|
+
this.implementation = new CapgoUpdater() {
|
|
120
129
|
@Override
|
|
121
130
|
public void notifyDownload(final String id, final int percent) {
|
|
122
131
|
CapacitorUpdaterPlugin.this.notifyDownload(id, percent);
|
|
@@ -128,13 +137,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
@Override
|
|
131
|
-
public void notifyListeners(final String id, final
|
|
132
|
-
CapacitorUpdaterPlugin.this.notifyListeners(id, res);
|
|
140
|
+
public void notifyListeners(final String id, final Map<String, Object> res) {
|
|
141
|
+
CapacitorUpdaterPlugin.this.notifyListeners(id, CapacitorUpdaterPlugin.this.mapToJSObject(res));
|
|
133
142
|
}
|
|
134
143
|
};
|
|
135
144
|
final PackageInfo pInfo = this.getContext().getPackageManager().getPackageInfo(this.getContext().getPackageName(), 0);
|
|
136
145
|
this.implementation.activity = this.getActivity();
|
|
137
146
|
this.implementation.versionBuild = this.getConfig().getString("version", pInfo.versionName);
|
|
147
|
+
this.implementation.CAP_SERVER_PATH = WebView.CAP_SERVER_PATH;
|
|
138
148
|
this.implementation.PLUGIN_VERSION = this.PLUGIN_VERSION;
|
|
139
149
|
this.implementation.versionCode = Integer.toString(pInfo.versionCode);
|
|
140
150
|
this.implementation.client = new OkHttpClient.Builder()
|
|
@@ -152,10 +162,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
152
162
|
CapacitorUpdaterPlugin.this::installNext
|
|
153
163
|
);
|
|
154
164
|
} catch (final PackageManager.NameNotFoundException e) {
|
|
155
|
-
Log.e(
|
|
165
|
+
Log.e(CapgoUpdater.TAG, "Error instantiating implementation", e);
|
|
156
166
|
return;
|
|
157
167
|
} catch (final Exception e) {
|
|
158
|
-
Log.e(
|
|
168
|
+
Log.e(CapgoUpdater.TAG, "Error getting current native app version", e);
|
|
159
169
|
return;
|
|
160
170
|
}
|
|
161
171
|
final CapConfig config = CapConfig.loadDefault(this.getActivity());
|
|
@@ -168,7 +178,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
168
178
|
"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"
|
|
169
179
|
);
|
|
170
180
|
}
|
|
171
|
-
Log.i(
|
|
181
|
+
Log.i(CapgoUpdater.TAG, "appId: " + implementation.appId);
|
|
172
182
|
this.implementation.publicKey = this.getConfig().getString("publicKey", "");
|
|
173
183
|
this.implementation.statsUrl = this.getConfig().getString("statsUrl", statsUrlDefault);
|
|
174
184
|
this.implementation.channelUrl = this.getConfig().getString("channelUrl", channelUrlDefault);
|
|
@@ -188,8 +198,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
188
198
|
this.implementation.deviceID = this.prefs.getString("appUUID", UUID.randomUUID().toString()).toLowerCase();
|
|
189
199
|
this.editor.putString("appUUID", this.implementation.deviceID);
|
|
190
200
|
this.editor.commit();
|
|
191
|
-
Log.i(
|
|
192
|
-
Log.i(
|
|
201
|
+
Log.i(CapgoUpdater.TAG, "init for device " + this.implementation.deviceID);
|
|
202
|
+
Log.i(CapgoUpdater.TAG, "version native " + this.currentVersionNative.getOriginalString());
|
|
193
203
|
this.autoDeleteFailed = this.getConfig().getBoolean("autoDeleteFailed", true);
|
|
194
204
|
this.autoDeletePrevious = this.getConfig().getBoolean("autoDeletePrevious", true);
|
|
195
205
|
this.updateUrl = this.getConfig().getString("updateUrl", updateUrlDefault);
|
|
@@ -207,14 +217,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
207
217
|
}
|
|
208
218
|
|
|
209
219
|
private void semaphoreWait(Number waitTime) {
|
|
210
|
-
// Log.i(
|
|
220
|
+
// Log.i(CapgoUpdater.TAG, "semaphoreWait " + waitTime);
|
|
211
221
|
try {
|
|
212
|
-
// Log.i(
|
|
222
|
+
// Log.i(CapgoUpdater.TAG, "semaphoreReady count " + CapacitorUpdaterPlugin.this.semaphoreReady.getCount());
|
|
213
223
|
semaphoreReady.awaitAdvanceInterruptibly(semaphoreReady.getPhase(), waitTime.longValue(), TimeUnit.SECONDS);
|
|
214
|
-
// Log.i(
|
|
215
|
-
Log.i(
|
|
224
|
+
// Log.i(CapgoUpdater.TAG, "semaphoreReady await " + res);
|
|
225
|
+
Log.i(CapgoUpdater.TAG, "semaphoreReady count " + semaphoreReady.getPhase());
|
|
216
226
|
} catch (InterruptedException e) {
|
|
217
|
-
Log.i(
|
|
227
|
+
Log.i(CapgoUpdater.TAG, "semaphoreWait InterruptedException");
|
|
218
228
|
e.printStackTrace();
|
|
219
229
|
} catch (TimeoutException e) {
|
|
220
230
|
throw new RuntimeException(e);
|
|
@@ -222,25 +232,25 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
222
232
|
}
|
|
223
233
|
|
|
224
234
|
private void semaphoreUp() {
|
|
225
|
-
Log.i(
|
|
235
|
+
Log.i(CapgoUpdater.TAG, "semaphoreUp");
|
|
226
236
|
semaphoreReady.register();
|
|
227
237
|
}
|
|
228
238
|
|
|
229
239
|
private void semaphoreDown() {
|
|
230
|
-
Log.i(
|
|
231
|
-
Log.i(
|
|
240
|
+
Log.i(CapgoUpdater.TAG, "semaphoreDown");
|
|
241
|
+
Log.i(CapgoUpdater.TAG, "semaphoreDown count " + semaphoreReady.getPhase());
|
|
232
242
|
semaphoreReady.arriveAndDeregister();
|
|
233
243
|
}
|
|
234
244
|
|
|
235
245
|
private void sendReadyToJs(final BundleInfo current, final String msg) {
|
|
236
|
-
Log.i(
|
|
246
|
+
Log.i(CapgoUpdater.TAG, "sendReadyToJs");
|
|
237
247
|
final JSObject ret = new JSObject();
|
|
238
|
-
ret.put("bundle", current.
|
|
248
|
+
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
239
249
|
ret.put("status", msg);
|
|
240
250
|
startNewThread(() -> {
|
|
241
|
-
Log.i(
|
|
251
|
+
Log.i(CapgoUpdater.TAG, "semaphoreReady sendReadyToJs");
|
|
242
252
|
semaphoreWait(CapacitorUpdaterPlugin.this.appReadyTimeout);
|
|
243
|
-
Log.i(
|
|
253
|
+
Log.i(CapgoUpdater.TAG, "semaphoreReady sendReadyToJs done");
|
|
244
254
|
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
|
|
245
255
|
});
|
|
246
256
|
}
|
|
@@ -259,23 +269,23 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
259
269
|
!"".equals(previous.getOriginalString()) &&
|
|
260
270
|
!Objects.equals(this.currentVersionNative.getOriginalString(), previous.getOriginalString())
|
|
261
271
|
) {
|
|
262
|
-
Log.i(
|
|
272
|
+
Log.i(CapgoUpdater.TAG, "New native version detected: " + this.currentVersionNative);
|
|
263
273
|
this.implementation.reset(true);
|
|
264
274
|
final List<BundleInfo> installed = this.implementation.list(false);
|
|
265
275
|
for (final BundleInfo bundle : installed) {
|
|
266
276
|
try {
|
|
267
|
-
Log.i(
|
|
277
|
+
Log.i(CapgoUpdater.TAG, "Deleting obsolete bundle: " + bundle.getId());
|
|
268
278
|
this.implementation.delete(bundle.getId());
|
|
269
279
|
} catch (final Exception e) {
|
|
270
|
-
Log.e(
|
|
280
|
+
Log.e(CapgoUpdater.TAG, "Failed to delete: " + bundle.getId(), e);
|
|
271
281
|
}
|
|
272
282
|
}
|
|
273
283
|
}
|
|
274
284
|
} catch (final Exception e) {
|
|
275
|
-
Log.e(
|
|
285
|
+
Log.e(CapgoUpdater.TAG, "Could not determine the current version", e);
|
|
276
286
|
}
|
|
277
287
|
} catch (final Exception e) {
|
|
278
|
-
Log.e(
|
|
288
|
+
Log.e(CapgoUpdater.TAG, "Error calculating previous native version", e);
|
|
279
289
|
}
|
|
280
290
|
this.editor.putString("LatestVersionNative", this.currentVersionNative.toString());
|
|
281
291
|
this.editor.commit();
|
|
@@ -286,7 +296,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
286
296
|
final JSObject ret = new JSObject();
|
|
287
297
|
ret.put("percent", percent);
|
|
288
298
|
final BundleInfo bundleInfo = this.implementation.getBundleInfo(id);
|
|
289
|
-
ret.put("bundle", bundleInfo.
|
|
299
|
+
ret.put("bundle", mapToJSObject(bundleInfo.toJSONMap()));
|
|
290
300
|
this.notifyListeners("download", ret);
|
|
291
301
|
|
|
292
302
|
if (percent == 100) {
|
|
@@ -302,20 +312,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
302
312
|
}
|
|
303
313
|
}
|
|
304
314
|
} catch (final Exception e) {
|
|
305
|
-
Log.e(
|
|
315
|
+
Log.e(CapgoUpdater.TAG, "Could not notify listeners", e);
|
|
306
316
|
}
|
|
307
317
|
}
|
|
308
318
|
|
|
309
319
|
@PluginMethod
|
|
310
320
|
public void setUpdateUrl(final PluginCall call) {
|
|
311
321
|
if (!this.getConfig().getBoolean("allowModifyUrl", false)) {
|
|
312
|
-
Log.e(
|
|
322
|
+
Log.e(CapgoUpdater.TAG, "setUpdateUrl not allowed set allowModifyUrl in your config to true to allow it");
|
|
313
323
|
call.reject("setUpdateUrl not allowed");
|
|
314
324
|
return;
|
|
315
325
|
}
|
|
316
326
|
final String url = call.getString("url");
|
|
317
327
|
if (url == null) {
|
|
318
|
-
Log.e(
|
|
328
|
+
Log.e(CapgoUpdater.TAG, "setUpdateUrl called without url");
|
|
319
329
|
call.reject("setUpdateUrl called without url");
|
|
320
330
|
return;
|
|
321
331
|
}
|
|
@@ -326,13 +336,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
326
336
|
@PluginMethod
|
|
327
337
|
public void setStatsUrl(final PluginCall call) {
|
|
328
338
|
if (!this.getConfig().getBoolean("allowModifyUrl", false)) {
|
|
329
|
-
Log.e(
|
|
339
|
+
Log.e(CapgoUpdater.TAG, "setStatsUrl not allowed set allowModifyUrl in your config to true to allow it");
|
|
330
340
|
call.reject("setStatsUrl not allowed");
|
|
331
341
|
return;
|
|
332
342
|
}
|
|
333
343
|
final String url = call.getString("url");
|
|
334
344
|
if (url == null) {
|
|
335
|
-
Log.e(
|
|
345
|
+
Log.e(CapgoUpdater.TAG, "setStatsUrl called without url");
|
|
336
346
|
call.reject("setStatsUrl called without url");
|
|
337
347
|
return;
|
|
338
348
|
}
|
|
@@ -343,13 +353,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
343
353
|
@PluginMethod
|
|
344
354
|
public void setChannelUrl(final PluginCall call) {
|
|
345
355
|
if (!this.getConfig().getBoolean("allowModifyUrl", false)) {
|
|
346
|
-
Log.e(
|
|
356
|
+
Log.e(CapgoUpdater.TAG, "setChannelUrl not allowed set allowModifyUrl in your config to true to allow it");
|
|
347
357
|
call.reject("setChannelUrl not allowed");
|
|
348
358
|
return;
|
|
349
359
|
}
|
|
350
360
|
final String url = call.getString("url");
|
|
351
361
|
if (url == null) {
|
|
352
|
-
Log.e(
|
|
362
|
+
Log.e(CapgoUpdater.TAG, "setChannelUrl called without url");
|
|
353
363
|
call.reject("setChannelUrl called without url");
|
|
354
364
|
return;
|
|
355
365
|
}
|
|
@@ -364,7 +374,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
364
374
|
ret.put("version", this.implementation.versionBuild);
|
|
365
375
|
call.resolve(ret);
|
|
366
376
|
} catch (final Exception e) {
|
|
367
|
-
Log.e(
|
|
377
|
+
Log.e(CapgoUpdater.TAG, "Could not get version", e);
|
|
368
378
|
call.reject("Could not get version", e);
|
|
369
379
|
}
|
|
370
380
|
}
|
|
@@ -376,7 +386,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
376
386
|
ret.put("deviceId", this.implementation.deviceID);
|
|
377
387
|
call.resolve(ret);
|
|
378
388
|
} catch (final Exception e) {
|
|
379
|
-
Log.e(
|
|
389
|
+
Log.e(CapgoUpdater.TAG, "Could not get device id", e);
|
|
380
390
|
call.reject("Could not get device id", e);
|
|
381
391
|
}
|
|
382
392
|
}
|
|
@@ -385,7 +395,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
385
395
|
public void setCustomId(final PluginCall call) {
|
|
386
396
|
final String customId = call.getString("customId");
|
|
387
397
|
if (customId == null) {
|
|
388
|
-
Log.e(
|
|
398
|
+
Log.e(CapgoUpdater.TAG, "setCustomId called without customId");
|
|
389
399
|
call.reject("setCustomId called without customId");
|
|
390
400
|
return;
|
|
391
401
|
}
|
|
@@ -399,7 +409,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
399
409
|
ret.put("version", this.PLUGIN_VERSION);
|
|
400
410
|
call.resolve(ret);
|
|
401
411
|
} catch (final Exception e) {
|
|
402
|
-
Log.e(
|
|
412
|
+
Log.e(CapgoUpdater.TAG, "Could not get plugin version", e);
|
|
403
413
|
call.reject("Could not get plugin version", e);
|
|
404
414
|
}
|
|
405
415
|
}
|
|
@@ -409,22 +419,23 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
409
419
|
final Boolean triggerAutoUpdate = call.getBoolean("triggerAutoUpdate", false);
|
|
410
420
|
|
|
411
421
|
try {
|
|
412
|
-
Log.i(
|
|
422
|
+
Log.i(CapgoUpdater.TAG, "unsetChannel triggerAutoUpdate: " + triggerAutoUpdate);
|
|
413
423
|
startNewThread(() ->
|
|
414
424
|
CapacitorUpdaterPlugin.this.implementation.unsetChannel(res -> {
|
|
415
|
-
|
|
416
|
-
|
|
425
|
+
JSObject jsRes = mapToJSObject(res);
|
|
426
|
+
if (jsRes.has("error")) {
|
|
427
|
+
call.reject(jsRes.getString("error"));
|
|
417
428
|
} else {
|
|
418
429
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() && Boolean.TRUE.equals(triggerAutoUpdate)) {
|
|
419
|
-
Log.i(
|
|
430
|
+
Log.i(CapgoUpdater.TAG, "Calling autoupdater after channel change!");
|
|
420
431
|
backgroundDownload();
|
|
421
432
|
}
|
|
422
|
-
call.resolve(
|
|
433
|
+
call.resolve(jsRes);
|
|
423
434
|
}
|
|
424
435
|
})
|
|
425
436
|
);
|
|
426
437
|
} catch (final Exception e) {
|
|
427
|
-
Log.e(
|
|
438
|
+
Log.e(CapgoUpdater.TAG, "Failed to unsetChannel: ", e);
|
|
428
439
|
call.reject("Failed to unsetChannel: ", e);
|
|
429
440
|
}
|
|
430
441
|
}
|
|
@@ -435,27 +446,28 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
435
446
|
final Boolean triggerAutoUpdate = call.getBoolean("triggerAutoUpdate", false);
|
|
436
447
|
|
|
437
448
|
if (channel == null) {
|
|
438
|
-
Log.e(
|
|
449
|
+
Log.e(CapgoUpdater.TAG, "setChannel called without channel");
|
|
439
450
|
call.reject("setChannel called without channel");
|
|
440
451
|
return;
|
|
441
452
|
}
|
|
442
453
|
try {
|
|
443
|
-
Log.i(
|
|
454
|
+
Log.i(CapgoUpdater.TAG, "setChannel " + channel + " triggerAutoUpdate: " + triggerAutoUpdate);
|
|
444
455
|
startNewThread(() ->
|
|
445
456
|
CapacitorUpdaterPlugin.this.implementation.setChannel(channel, res -> {
|
|
446
|
-
|
|
447
|
-
|
|
457
|
+
JSObject jsRes = mapToJSObject(res);
|
|
458
|
+
if (jsRes.has("error")) {
|
|
459
|
+
call.reject(jsRes.getString("error"));
|
|
448
460
|
} else {
|
|
449
461
|
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled() && Boolean.TRUE.equals(triggerAutoUpdate)) {
|
|
450
|
-
Log.i(
|
|
462
|
+
Log.i(CapgoUpdater.TAG, "Calling autoupdater after channel change!");
|
|
451
463
|
backgroundDownload();
|
|
452
464
|
}
|
|
453
|
-
call.resolve(
|
|
465
|
+
call.resolve(jsRes);
|
|
454
466
|
}
|
|
455
467
|
})
|
|
456
468
|
);
|
|
457
469
|
} catch (final Exception e) {
|
|
458
|
-
Log.e(
|
|
470
|
+
Log.e(CapgoUpdater.TAG, "Failed to setChannel: " + channel, e);
|
|
459
471
|
call.reject("Failed to setChannel: " + channel, e);
|
|
460
472
|
}
|
|
461
473
|
}
|
|
@@ -463,18 +475,19 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
463
475
|
@PluginMethod
|
|
464
476
|
public void getChannel(final PluginCall call) {
|
|
465
477
|
try {
|
|
466
|
-
Log.i(
|
|
478
|
+
Log.i(CapgoUpdater.TAG, "getChannel");
|
|
467
479
|
startNewThread(() ->
|
|
468
480
|
CapacitorUpdaterPlugin.this.implementation.getChannel(res -> {
|
|
469
|
-
|
|
470
|
-
|
|
481
|
+
JSObject jsRes = mapToJSObject(res);
|
|
482
|
+
if (jsRes.has("error")) {
|
|
483
|
+
call.reject(jsRes.getString("error"));
|
|
471
484
|
} else {
|
|
472
|
-
call.resolve(
|
|
485
|
+
call.resolve(jsRes);
|
|
473
486
|
}
|
|
474
487
|
})
|
|
475
488
|
);
|
|
476
489
|
} catch (final Exception e) {
|
|
477
|
-
Log.e(
|
|
490
|
+
Log.e(CapgoUpdater.TAG, "Failed to getChannel", e);
|
|
478
491
|
call.reject("Failed to getChannel", e);
|
|
479
492
|
}
|
|
480
493
|
}
|
|
@@ -486,27 +499,27 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
486
499
|
final String sessionKey = call.getString("sessionKey", "");
|
|
487
500
|
final String checksum = call.getString("checksum", "");
|
|
488
501
|
if (url == null) {
|
|
489
|
-
Log.e(
|
|
502
|
+
Log.e(CapgoUpdater.TAG, "Download called without url");
|
|
490
503
|
call.reject("Download called without url");
|
|
491
504
|
return;
|
|
492
505
|
}
|
|
493
506
|
if (version == null) {
|
|
494
|
-
Log.e(
|
|
507
|
+
Log.e(CapgoUpdater.TAG, "Download called without version");
|
|
495
508
|
call.reject("Download called without version");
|
|
496
509
|
return;
|
|
497
510
|
}
|
|
498
511
|
try {
|
|
499
|
-
Log.i(
|
|
512
|
+
Log.i(CapgoUpdater.TAG, "Downloading " + url);
|
|
500
513
|
startNewThread(() -> {
|
|
501
514
|
try {
|
|
502
515
|
final BundleInfo downloaded = CapacitorUpdaterPlugin.this.implementation.download(url, version, sessionKey, checksum);
|
|
503
516
|
if (downloaded.isErrorStatus()) {
|
|
504
517
|
throw new RuntimeException("Download failed: " + downloaded.getStatus());
|
|
505
518
|
} else {
|
|
506
|
-
call.resolve(downloaded.
|
|
519
|
+
call.resolve(mapToJSObject(downloaded.toJSONMap()));
|
|
507
520
|
}
|
|
508
521
|
} catch (final Exception e) {
|
|
509
|
-
Log.e(
|
|
522
|
+
Log.e(CapgoUpdater.TAG, "Failed to download from: " + url, e);
|
|
510
523
|
call.reject("Failed to download from: " + url, e);
|
|
511
524
|
final JSObject ret = new JSObject();
|
|
512
525
|
ret.put("version", version);
|
|
@@ -516,7 +529,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
516
529
|
}
|
|
517
530
|
});
|
|
518
531
|
} catch (final Exception e) {
|
|
519
|
-
Log.e(
|
|
532
|
+
Log.e(CapgoUpdater.TAG, "Failed to download from: " + url, e);
|
|
520
533
|
call.reject("Failed to download from: " + url, e);
|
|
521
534
|
final JSObject ret = new JSObject();
|
|
522
535
|
ret.put("version", version);
|
|
@@ -529,7 +542,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
529
542
|
protected boolean _reload() {
|
|
530
543
|
final String path = this.implementation.getCurrentBundlePath();
|
|
531
544
|
this.semaphoreUp();
|
|
532
|
-
Log.i(
|
|
545
|
+
Log.i(CapgoUpdater.TAG, "Reloading: " + path);
|
|
533
546
|
|
|
534
547
|
AtomicReference<URL> url = new AtomicReference<>();
|
|
535
548
|
if (this.keepUrlPathAfterReload) {
|
|
@@ -540,7 +553,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
540
553
|
try {
|
|
541
554
|
url.set(new URL(this.bridge.getWebView().getUrl()));
|
|
542
555
|
} catch (Exception e) {
|
|
543
|
-
Log.e(
|
|
556
|
+
Log.e(CapgoUpdater.TAG, "Error executing on main thread", e);
|
|
544
557
|
}
|
|
545
558
|
mainThreadSemaphore.release();
|
|
546
559
|
});
|
|
@@ -549,11 +562,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
549
562
|
try {
|
|
550
563
|
url.set(new URL(this.bridge.getWebView().getUrl()));
|
|
551
564
|
} catch (Exception e) {
|
|
552
|
-
Log.e(
|
|
565
|
+
Log.e(CapgoUpdater.TAG, "Error executing on main thread", e);
|
|
553
566
|
}
|
|
554
567
|
}
|
|
555
568
|
} catch (InterruptedException e) {
|
|
556
|
-
Log.e(
|
|
569
|
+
Log.e(CapgoUpdater.TAG, "Error waiting for main thread or getting the current URL from webview", e);
|
|
557
570
|
}
|
|
558
571
|
}
|
|
559
572
|
|
|
@@ -575,7 +588,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
575
588
|
this.bridge.getWebView().clearHistory();
|
|
576
589
|
});
|
|
577
590
|
} catch (MalformedURLException e) {
|
|
578
|
-
Log.e(
|
|
591
|
+
Log.e(CapgoUpdater.TAG, "Cannot get finalUrl from capacitor bridge", e);
|
|
579
592
|
|
|
580
593
|
if (this.implementation.isUsingBuiltin()) {
|
|
581
594
|
this.bridge.setServerAssetPath(path);
|
|
@@ -602,11 +615,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
602
615
|
if (this._reload()) {
|
|
603
616
|
call.resolve();
|
|
604
617
|
} else {
|
|
605
|
-
Log.e(
|
|
618
|
+
Log.e(CapgoUpdater.TAG, "Reload failed");
|
|
606
619
|
call.reject("Reload failed");
|
|
607
620
|
}
|
|
608
621
|
} catch (final Exception e) {
|
|
609
|
-
Log.e(
|
|
622
|
+
Log.e(CapgoUpdater.TAG, "Could not reload", e);
|
|
610
623
|
call.reject("Could not reload", e);
|
|
611
624
|
}
|
|
612
625
|
}
|
|
@@ -615,20 +628,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
615
628
|
public void next(final PluginCall call) {
|
|
616
629
|
final String id = call.getString("id");
|
|
617
630
|
if (id == null) {
|
|
618
|
-
Log.e(
|
|
631
|
+
Log.e(CapgoUpdater.TAG, "Next called without id");
|
|
619
632
|
call.reject("Next called without id");
|
|
620
633
|
return;
|
|
621
634
|
}
|
|
622
635
|
try {
|
|
623
|
-
Log.i(
|
|
636
|
+
Log.i(CapgoUpdater.TAG, "Setting next active id " + id);
|
|
624
637
|
if (!this.implementation.setNextBundle(id)) {
|
|
625
|
-
Log.e(
|
|
638
|
+
Log.e(CapgoUpdater.TAG, "Set next id failed. Bundle " + id + " does not exist.");
|
|
626
639
|
call.reject("Set next id failed. Bundle " + id + " does not exist.");
|
|
627
640
|
} else {
|
|
628
|
-
call.resolve(this.implementation.getBundleInfo(id).
|
|
641
|
+
call.resolve(mapToJSObject(this.implementation.getBundleInfo(id).toJSONMap()));
|
|
629
642
|
}
|
|
630
643
|
} catch (final Exception e) {
|
|
631
|
-
Log.e(
|
|
644
|
+
Log.e(CapgoUpdater.TAG, "Could not set next id " + id, e);
|
|
632
645
|
call.reject("Could not set next id: " + id, e);
|
|
633
646
|
}
|
|
634
647
|
}
|
|
@@ -637,21 +650,21 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
637
650
|
public void set(final PluginCall call) {
|
|
638
651
|
final String id = call.getString("id");
|
|
639
652
|
if (id == null) {
|
|
640
|
-
Log.e(
|
|
653
|
+
Log.e(CapgoUpdater.TAG, "Set called without id");
|
|
641
654
|
call.reject("Set called without id");
|
|
642
655
|
return;
|
|
643
656
|
}
|
|
644
657
|
try {
|
|
645
|
-
Log.i(
|
|
658
|
+
Log.i(CapgoUpdater.TAG, "Setting active bundle " + id);
|
|
646
659
|
if (!this.implementation.set(id)) {
|
|
647
|
-
Log.i(
|
|
660
|
+
Log.i(CapgoUpdater.TAG, "No such bundle " + id);
|
|
648
661
|
call.reject("Update failed, id " + id + " does not exist.");
|
|
649
662
|
} else {
|
|
650
|
-
Log.i(
|
|
663
|
+
Log.i(CapgoUpdater.TAG, "Bundle successfully set to " + id);
|
|
651
664
|
this.reload(call);
|
|
652
665
|
}
|
|
653
666
|
} catch (final Exception e) {
|
|
654
|
-
Log.e(
|
|
667
|
+
Log.e(CapgoUpdater.TAG, "Could not set id " + id, e);
|
|
655
668
|
call.reject("Could not set id " + id, e);
|
|
656
669
|
}
|
|
657
670
|
}
|
|
@@ -660,21 +673,21 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
660
673
|
public void delete(final PluginCall call) {
|
|
661
674
|
final String id = call.getString("id");
|
|
662
675
|
if (id == null) {
|
|
663
|
-
Log.e(
|
|
676
|
+
Log.e(CapgoUpdater.TAG, "missing id");
|
|
664
677
|
call.reject("missing id");
|
|
665
678
|
return;
|
|
666
679
|
}
|
|
667
|
-
Log.i(
|
|
680
|
+
Log.i(CapgoUpdater.TAG, "Deleting id " + id);
|
|
668
681
|
try {
|
|
669
682
|
final Boolean res = this.implementation.delete(id);
|
|
670
683
|
if (res) {
|
|
671
684
|
call.resolve();
|
|
672
685
|
} else {
|
|
673
|
-
Log.e(
|
|
686
|
+
Log.e(CapgoUpdater.TAG, "Delete failed, id " + id + " does not exist");
|
|
674
687
|
call.reject("Delete failed, id " + id + " does not exist or it cannot be deleted (perhaps it is the 'next' bundle)");
|
|
675
688
|
}
|
|
676
689
|
} catch (final Exception e) {
|
|
677
|
-
Log.e(
|
|
690
|
+
Log.e(CapgoUpdater.TAG, "Could not delete id " + id, e);
|
|
678
691
|
call.reject("Could not delete id " + id, e);
|
|
679
692
|
}
|
|
680
693
|
}
|
|
@@ -686,12 +699,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
686
699
|
final JSObject ret = new JSObject();
|
|
687
700
|
final JSArray values = new JSArray();
|
|
688
701
|
for (final BundleInfo bundle : res) {
|
|
689
|
-
values.put(bundle.
|
|
702
|
+
values.put(mapToJSObject(bundle.toJSONMap()));
|
|
690
703
|
}
|
|
691
704
|
ret.put("bundles", values);
|
|
692
705
|
call.resolve(ret);
|
|
693
706
|
} catch (final Exception e) {
|
|
694
|
-
Log.e(
|
|
707
|
+
Log.e(CapgoUpdater.TAG, "Could not list bundles", e);
|
|
695
708
|
call.reject("Could not list bundles", e);
|
|
696
709
|
}
|
|
697
710
|
}
|
|
@@ -701,28 +714,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
701
714
|
final String channel = call.getString("channel");
|
|
702
715
|
startNewThread(() ->
|
|
703
716
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, channel, res -> {
|
|
704
|
-
|
|
705
|
-
|
|
717
|
+
JSObject jsRes = mapToJSObject(res);
|
|
718
|
+
if (jsRes.has("error")) {
|
|
719
|
+
call.reject(jsRes.getString("error"));
|
|
706
720
|
return;
|
|
707
|
-
} else if (
|
|
708
|
-
call.reject(
|
|
721
|
+
} else if (jsRes.has("message")) {
|
|
722
|
+
call.reject(jsRes.getString("message"));
|
|
709
723
|
return;
|
|
710
724
|
} else {
|
|
711
|
-
call.resolve(
|
|
712
|
-
}
|
|
713
|
-
final JSObject ret = new JSObject();
|
|
714
|
-
Iterator<String> keys = res.keys();
|
|
715
|
-
while (keys.hasNext()) {
|
|
716
|
-
String key = keys.next();
|
|
717
|
-
if (res.has(key)) {
|
|
718
|
-
try {
|
|
719
|
-
ret.put(key, res.get(key));
|
|
720
|
-
} catch (JSONException e) {
|
|
721
|
-
e.printStackTrace();
|
|
722
|
-
}
|
|
723
|
-
}
|
|
725
|
+
call.resolve(jsRes);
|
|
724
726
|
}
|
|
725
|
-
call.resolve(ret);
|
|
726
727
|
})
|
|
727
728
|
);
|
|
728
729
|
}
|
|
@@ -732,11 +733,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
732
733
|
this.implementation.reset();
|
|
733
734
|
|
|
734
735
|
if (toLastSuccessful && !fallback.isBuiltin()) {
|
|
735
|
-
Log.i(
|
|
736
|
+
Log.i(CapgoUpdater.TAG, "Resetting to: " + fallback);
|
|
736
737
|
return this.implementation.set(fallback) && this._reload();
|
|
737
738
|
}
|
|
738
739
|
|
|
739
|
-
Log.i(
|
|
740
|
+
Log.i(CapgoUpdater.TAG, "Resetting to native.");
|
|
740
741
|
return this._reload();
|
|
741
742
|
}
|
|
742
743
|
|
|
@@ -748,10 +749,10 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
748
749
|
call.resolve();
|
|
749
750
|
return;
|
|
750
751
|
}
|
|
751
|
-
Log.e(
|
|
752
|
+
Log.e(CapgoUpdater.TAG, "Reset failed");
|
|
752
753
|
call.reject("Reset failed");
|
|
753
754
|
} catch (final Exception e) {
|
|
754
|
-
Log.e(
|
|
755
|
+
Log.e(CapgoUpdater.TAG, "Reset failed", e);
|
|
755
756
|
call.reject("Reset failed", e);
|
|
756
757
|
}
|
|
757
758
|
}
|
|
@@ -761,11 +762,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
761
762
|
try {
|
|
762
763
|
final JSObject ret = new JSObject();
|
|
763
764
|
final BundleInfo bundle = this.implementation.getCurrentBundle();
|
|
764
|
-
ret.put("bundle", bundle.
|
|
765
|
+
ret.put("bundle", mapToJSObject(bundle.toJSONMap()));
|
|
765
766
|
ret.put("native", this.currentVersionNative);
|
|
766
767
|
call.resolve(ret);
|
|
767
768
|
} catch (final Exception e) {
|
|
768
|
-
Log.e(
|
|
769
|
+
Log.e(CapgoUpdater.TAG, "Could not get current bundle", e);
|
|
769
770
|
call.reject("Could not get current bundle", e);
|
|
770
771
|
}
|
|
771
772
|
}
|
|
@@ -779,9 +780,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
779
780
|
return;
|
|
780
781
|
}
|
|
781
782
|
|
|
782
|
-
call.resolve(bundle.
|
|
783
|
+
call.resolve(mapToJSObject(bundle.toJSONMap()));
|
|
783
784
|
} catch (final Exception e) {
|
|
784
|
-
Log.e(
|
|
785
|
+
Log.e(CapgoUpdater.TAG, "Could not get next bundle", e);
|
|
785
786
|
call.reject("Could not get next bundle", e);
|
|
786
787
|
}
|
|
787
788
|
}
|
|
@@ -797,19 +798,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
797
798
|
public void run() {
|
|
798
799
|
try {
|
|
799
800
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
801
|
+
JSObject jsRes = mapToJSObject(res);
|
|
802
|
+
if (jsRes.has("error")) {
|
|
803
|
+
Log.e(CapgoUpdater.TAG, Objects.requireNonNull(jsRes.getString("error")));
|
|
804
|
+
} else if (jsRes.has("version")) {
|
|
805
|
+
String newVersion = jsRes.getString("version");
|
|
804
806
|
String currentVersion = String.valueOf(CapacitorUpdaterPlugin.this.implementation.getCurrentBundle());
|
|
805
807
|
if (!Objects.equals(newVersion, currentVersion)) {
|
|
806
|
-
Log.i(
|
|
808
|
+
Log.i(CapgoUpdater.TAG, "New version found: " + newVersion);
|
|
807
809
|
CapacitorUpdaterPlugin.this.backgroundDownload();
|
|
808
810
|
}
|
|
809
811
|
}
|
|
810
812
|
});
|
|
811
813
|
} catch (final Exception e) {
|
|
812
|
-
Log.e(
|
|
814
|
+
Log.e(CapgoUpdater.TAG, "Failed to check for update", e);
|
|
813
815
|
}
|
|
814
816
|
}
|
|
815
817
|
},
|
|
@@ -823,15 +825,15 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
823
825
|
try {
|
|
824
826
|
final BundleInfo bundle = this.implementation.getCurrentBundle();
|
|
825
827
|
this.implementation.setSuccess(bundle, this.autoDeletePrevious);
|
|
826
|
-
Log.i(
|
|
827
|
-
Log.i(
|
|
828
|
+
Log.i(CapgoUpdater.TAG, "Current bundle loaded successfully. ['notifyAppReady()' was called] " + bundle);
|
|
829
|
+
Log.i(CapgoUpdater.TAG, "semaphoreReady countDown");
|
|
828
830
|
this.semaphoreDown();
|
|
829
|
-
Log.i(
|
|
831
|
+
Log.i(CapgoUpdater.TAG, "semaphoreReady countDown done");
|
|
830
832
|
final JSObject ret = new JSObject();
|
|
831
|
-
ret.put("bundle", bundle.
|
|
833
|
+
ret.put("bundle", mapToJSObject(bundle.toJSONMap()));
|
|
832
834
|
call.resolve(ret);
|
|
833
835
|
} catch (final Exception e) {
|
|
834
|
-
Log.e(
|
|
836
|
+
Log.e(CapgoUpdater.TAG, "Failed to notify app ready state. [Error calling 'notifyAppReady()']", e);
|
|
835
837
|
call.reject("Failed to commit app ready state.", e);
|
|
836
838
|
}
|
|
837
839
|
}
|
|
@@ -841,7 +843,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
841
843
|
try {
|
|
842
844
|
final JSONArray delayConditions = call.getData().optJSONArray("delayConditions");
|
|
843
845
|
if (delayConditions == null) {
|
|
844
|
-
Log.e(
|
|
846
|
+
Log.e(CapgoUpdater.TAG, "setMultiDelay called without delayCondition");
|
|
845
847
|
call.reject("setMultiDelay called without delayCondition");
|
|
846
848
|
return;
|
|
847
849
|
}
|
|
@@ -859,7 +861,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
859
861
|
call.reject("Failed to delay update");
|
|
860
862
|
}
|
|
861
863
|
} catch (final Exception e) {
|
|
862
|
-
Log.e(
|
|
864
|
+
Log.e(CapgoUpdater.TAG, "Failed to delay update, [Error calling 'setMultiDelay()']", e);
|
|
863
865
|
call.reject("Failed to delay update", e);
|
|
864
866
|
}
|
|
865
867
|
}
|
|
@@ -878,7 +880,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
878
880
|
String serverUrl = config.getServerUrl();
|
|
879
881
|
if (serverUrl != null && !serverUrl.isEmpty()) {
|
|
880
882
|
// log warning autoupdate disabled when serverUrl is set
|
|
881
|
-
Log.w(
|
|
883
|
+
Log.w(CapgoUpdater.TAG, "AutoUpdate is automatic disabled when serverUrl is set.");
|
|
882
884
|
}
|
|
883
885
|
return (
|
|
884
886
|
CapacitorUpdaterPlugin.this.autoUpdate &&
|
|
@@ -894,7 +896,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
894
896
|
ret.put("enabled", this._isAutoUpdateEnabled());
|
|
895
897
|
call.resolve(ret);
|
|
896
898
|
} catch (final Exception e) {
|
|
897
|
-
Log.e(
|
|
899
|
+
Log.e(CapgoUpdater.TAG, "Could not get autoUpdate status", e);
|
|
898
900
|
call.reject("Could not get autoUpdate status", e);
|
|
899
901
|
}
|
|
900
902
|
}
|
|
@@ -908,7 +910,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
908
910
|
ret.put("available", serverUrl == null || serverUrl.isEmpty());
|
|
909
911
|
call.resolve(ret);
|
|
910
912
|
} catch (final Exception e) {
|
|
911
|
-
Log.e(
|
|
913
|
+
Log.e(CapgoUpdater.TAG, "Could not get autoUpdate availability", e);
|
|
912
914
|
call.reject("Could not get autoUpdate availability", e);
|
|
913
915
|
}
|
|
914
916
|
}
|
|
@@ -920,7 +922,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
920
922
|
}
|
|
921
923
|
this.appReadyCheck = startNewThread(new DeferredNotifyAppReadyCheck());
|
|
922
924
|
} catch (final Exception e) {
|
|
923
|
-
Log.e(
|
|
925
|
+
Log.e(CapgoUpdater.TAG, "Failed to start " + DeferredNotifyAppReadyCheck.class.getName(), e);
|
|
924
926
|
}
|
|
925
927
|
}
|
|
926
928
|
|
|
@@ -936,7 +938,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
936
938
|
private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
|
|
937
939
|
if (error) {
|
|
938
940
|
Log.i(
|
|
939
|
-
|
|
941
|
+
CapgoUpdater.TAG,
|
|
940
942
|
"endBackGroundTaskWithNotif error: " +
|
|
941
943
|
error +
|
|
942
944
|
" current: " +
|
|
@@ -950,11 +952,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
950
952
|
this.notifyListeners("downloadFailed", ret);
|
|
951
953
|
}
|
|
952
954
|
final JSObject ret = new JSObject();
|
|
953
|
-
ret.put("bundle", current.
|
|
955
|
+
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
954
956
|
this.notifyListeners("noNeedUpdate", ret);
|
|
955
957
|
this.sendReadyToJs(current, msg);
|
|
956
958
|
this.backgroundDownloadTask = null;
|
|
957
|
-
Log.i(
|
|
959
|
+
Log.i(CapgoUpdater.TAG, "endBackGroundTaskWithNotif " + msg);
|
|
958
960
|
}
|
|
959
961
|
|
|
960
962
|
private Thread backgroundDownload() {
|
|
@@ -962,19 +964,20 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
962
964
|
? "Update will occur now."
|
|
963
965
|
: "Update will occur next time app moves to background.";
|
|
964
966
|
return startNewThread(() -> {
|
|
965
|
-
Log.i(
|
|
967
|
+
Log.i(CapgoUpdater.TAG, "Check for update via: " + CapacitorUpdaterPlugin.this.updateUrl);
|
|
966
968
|
CapacitorUpdaterPlugin.this.implementation.getLatest(CapacitorUpdaterPlugin.this.updateUrl, null, res -> {
|
|
969
|
+
JSObject jsRes = mapToJSObject(res);
|
|
967
970
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
968
971
|
try {
|
|
969
|
-
if (
|
|
970
|
-
Log.i(
|
|
971
|
-
if (
|
|
972
|
+
if (jsRes.has("message")) {
|
|
973
|
+
Log.i(CapgoUpdater.TAG, "API message: " + jsRes.get("message"));
|
|
974
|
+
if (jsRes.has("major") && jsRes.getBoolean("major") && jsRes.has("version")) {
|
|
972
975
|
final JSObject majorAvailable = new JSObject();
|
|
973
|
-
majorAvailable.put("version",
|
|
976
|
+
majorAvailable.put("version", jsRes.getString("version"));
|
|
974
977
|
CapacitorUpdaterPlugin.this.notifyListeners("majorAvailable", majorAvailable);
|
|
975
978
|
}
|
|
976
979
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
977
|
-
|
|
980
|
+
jsRes.getString("message"),
|
|
978
981
|
current.getVersionName(),
|
|
979
982
|
current,
|
|
980
983
|
true
|
|
@@ -982,12 +985,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
982
985
|
return;
|
|
983
986
|
}
|
|
984
987
|
|
|
985
|
-
final String latestVersionName =
|
|
988
|
+
final String latestVersionName = jsRes.getString("version");
|
|
986
989
|
|
|
987
990
|
if ("builtin".equals(latestVersionName)) {
|
|
988
|
-
Log.i(
|
|
991
|
+
Log.i(CapgoUpdater.TAG, "Latest version is builtin");
|
|
989
992
|
if (CapacitorUpdaterPlugin.this.implementation.directUpdate) {
|
|
990
|
-
Log.i(
|
|
993
|
+
Log.i(CapgoUpdater.TAG, "Direct update to builtin version");
|
|
991
994
|
this._reset(false);
|
|
992
995
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
993
996
|
"Updated to builtin version",
|
|
@@ -996,7 +999,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
996
999
|
false
|
|
997
1000
|
);
|
|
998
1001
|
} else {
|
|
999
|
-
Log.i(
|
|
1002
|
+
Log.i(CapgoUpdater.TAG, "Setting next bundle to builtin");
|
|
1000
1003
|
CapacitorUpdaterPlugin.this.implementation.setNextBundle(BundleInfo.ID_BUILTIN);
|
|
1001
1004
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1002
1005
|
"Next update will be to builtin version",
|
|
@@ -1008,8 +1011,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1008
1011
|
return;
|
|
1009
1012
|
}
|
|
1010
1013
|
|
|
1011
|
-
if (!
|
|
1012
|
-
Log.e(
|
|
1014
|
+
if (!jsRes.has("url") || !CapacitorUpdaterPlugin.this.isValidURL(jsRes.getString("url"))) {
|
|
1015
|
+
Log.e(CapgoUpdater.TAG, "Error no url or wrong format");
|
|
1013
1016
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1014
1017
|
"Error no url or wrong format",
|
|
1015
1018
|
current.getVersionName(),
|
|
@@ -1025,9 +1028,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1025
1028
|
final BundleInfo latest = CapacitorUpdaterPlugin.this.implementation.getBundleInfoByName(latestVersionName);
|
|
1026
1029
|
if (latest != null) {
|
|
1027
1030
|
final JSObject ret = new JSObject();
|
|
1028
|
-
ret.put("bundle", latest.
|
|
1031
|
+
ret.put("bundle", mapToJSObject(latest.toJSONMap()));
|
|
1029
1032
|
if (latest.isErrorStatus()) {
|
|
1030
|
-
Log.e(
|
|
1033
|
+
Log.e(CapgoUpdater.TAG, "Latest bundle already exists, and is in error state. Aborting update.");
|
|
1031
1034
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1032
1035
|
"Latest bundle already exists, and is in error state. Aborting update.",
|
|
1033
1036
|
latestVersionName,
|
|
@@ -1037,17 +1040,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1037
1040
|
return;
|
|
1038
1041
|
}
|
|
1039
1042
|
if (latest.isDownloaded()) {
|
|
1040
|
-
Log.i(
|
|
1041
|
-
CapacitorUpdater.TAG,
|
|
1042
|
-
"Latest bundle already exists and download is NOT required. " + messageUpdate
|
|
1043
|
-
);
|
|
1043
|
+
Log.i(CapgoUpdater.TAG, "Latest bundle already exists and download is NOT required. " + messageUpdate);
|
|
1044
1044
|
if (CapacitorUpdaterPlugin.this.implementation.directUpdate) {
|
|
1045
1045
|
Gson gson = new Gson();
|
|
1046
1046
|
String delayUpdatePreferences = prefs.getString(DelayUpdateUtils.DELAY_CONDITION_PREFERENCES, "[]");
|
|
1047
1047
|
Type type = new TypeToken<ArrayList<DelayCondition>>() {}.getType();
|
|
1048
1048
|
ArrayList<DelayCondition> delayConditionList = gson.fromJson(delayUpdatePreferences, type);
|
|
1049
1049
|
if (delayConditionList != null && !delayConditionList.isEmpty()) {
|
|
1050
|
-
Log.i(
|
|
1050
|
+
Log.i(CapgoUpdater.TAG, "Update delayed until delay conditions met");
|
|
1051
1051
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1052
1052
|
"Update delayed until delay conditions met",
|
|
1053
1053
|
latestVersionName,
|
|
@@ -1078,23 +1078,23 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1078
1078
|
}
|
|
1079
1079
|
if (latest.isDeleted()) {
|
|
1080
1080
|
Log.i(
|
|
1081
|
-
|
|
1081
|
+
CapgoUpdater.TAG,
|
|
1082
1082
|
"Latest bundle already exists and will be deleted, download will overwrite it."
|
|
1083
1083
|
);
|
|
1084
1084
|
try {
|
|
1085
1085
|
final Boolean deleted = CapacitorUpdaterPlugin.this.implementation.delete(latest.getId(), true);
|
|
1086
1086
|
if (deleted) {
|
|
1087
|
-
Log.i(
|
|
1087
|
+
Log.i(CapgoUpdater.TAG, "Failed bundle deleted: " + latest.getVersionName());
|
|
1088
1088
|
}
|
|
1089
1089
|
} catch (final IOException e) {
|
|
1090
|
-
Log.e(
|
|
1090
|
+
Log.e(CapgoUpdater.TAG, "Failed to delete failed bundle: " + latest.getVersionName(), e);
|
|
1091
1091
|
}
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
1094
|
startNewThread(() -> {
|
|
1095
1095
|
try {
|
|
1096
1096
|
Log.i(
|
|
1097
|
-
|
|
1097
|
+
CapgoUpdater.TAG,
|
|
1098
1098
|
"New bundle: " +
|
|
1099
1099
|
latestVersionName +
|
|
1100
1100
|
" found. Current is: " +
|
|
@@ -1103,13 +1103,13 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1103
1103
|
messageUpdate
|
|
1104
1104
|
);
|
|
1105
1105
|
|
|
1106
|
-
final String url =
|
|
1107
|
-
final String sessionKey =
|
|
1108
|
-
final String checksum =
|
|
1106
|
+
final String url = jsRes.getString("url");
|
|
1107
|
+
final String sessionKey = jsRes.has("sessionKey") ? jsRes.getString("sessionKey") : "";
|
|
1108
|
+
final String checksum = jsRes.has("checksum") ? jsRes.getString("checksum") : "";
|
|
1109
1109
|
|
|
1110
|
-
if (
|
|
1110
|
+
if (jsRes.has("manifest")) {
|
|
1111
1111
|
// Handle manifest-based download
|
|
1112
|
-
JSONArray manifest =
|
|
1112
|
+
JSONArray manifest = jsRes.getJSONArray("manifest");
|
|
1113
1113
|
CapacitorUpdaterPlugin.this.implementation.downloadBackground(
|
|
1114
1114
|
url,
|
|
1115
1115
|
latestVersionName,
|
|
@@ -1128,7 +1128,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1128
1128
|
);
|
|
1129
1129
|
}
|
|
1130
1130
|
} catch (final Exception e) {
|
|
1131
|
-
Log.e(
|
|
1131
|
+
Log.e(CapgoUpdater.TAG, "error downloading file", e);
|
|
1132
1132
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1133
1133
|
"Error downloading file",
|
|
1134
1134
|
latestVersionName,
|
|
@@ -1138,11 +1138,11 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1138
1138
|
}
|
|
1139
1139
|
});
|
|
1140
1140
|
} else {
|
|
1141
|
-
Log.i(
|
|
1141
|
+
Log.i(CapgoUpdater.TAG, "No need to update, " + current.getId() + " is the latest bundle.");
|
|
1142
1142
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif("No need to update", latestVersionName, current, false);
|
|
1143
1143
|
}
|
|
1144
1144
|
} catch (final JSONException e) {
|
|
1145
|
-
Log.e(
|
|
1145
|
+
Log.e(CapgoUpdater.TAG, "error parsing JSON", e);
|
|
1146
1146
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1147
1147
|
"Error parsing JSON",
|
|
1148
1148
|
current.getVersionName(),
|
|
@@ -1161,7 +1161,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1161
1161
|
Type type = new TypeToken<ArrayList<DelayCondition>>() {}.getType();
|
|
1162
1162
|
ArrayList<DelayCondition> delayConditionList = gson.fromJson(delayUpdatePreferences, type);
|
|
1163
1163
|
if (delayConditionList != null && !delayConditionList.isEmpty()) {
|
|
1164
|
-
Log.i(
|
|
1164
|
+
Log.i(CapgoUpdater.TAG, "Update delayed until delay conditions met");
|
|
1165
1165
|
return;
|
|
1166
1166
|
}
|
|
1167
1167
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
@@ -1169,16 +1169,16 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1169
1169
|
|
|
1170
1170
|
if (next != null && !next.isErrorStatus() && !next.getId().equals(current.getId())) {
|
|
1171
1171
|
// There is a next bundle waiting for activation
|
|
1172
|
-
Log.d(
|
|
1172
|
+
Log.d(CapgoUpdater.TAG, "Next bundle is: " + next.getVersionName());
|
|
1173
1173
|
if (this.implementation.set(next) && this._reload()) {
|
|
1174
|
-
Log.i(
|
|
1174
|
+
Log.i(CapgoUpdater.TAG, "Updated to bundle: " + next.getVersionName());
|
|
1175
1175
|
this.implementation.setNextBundle(null);
|
|
1176
1176
|
} else {
|
|
1177
|
-
Log.e(
|
|
1177
|
+
Log.e(CapgoUpdater.TAG, "Update to bundle: " + next.getVersionName() + " Failed!");
|
|
1178
1178
|
}
|
|
1179
1179
|
}
|
|
1180
1180
|
} catch (final Exception e) {
|
|
1181
|
-
Log.e(
|
|
1181
|
+
Log.e(CapgoUpdater.TAG, "Error during onActivityStopped", e);
|
|
1182
1182
|
}
|
|
1183
1183
|
}
|
|
1184
1184
|
|
|
@@ -1187,33 +1187,33 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1187
1187
|
final BundleInfo current = this.implementation.getCurrentBundle();
|
|
1188
1188
|
|
|
1189
1189
|
if (current.isBuiltin()) {
|
|
1190
|
-
Log.i(
|
|
1190
|
+
Log.i(CapgoUpdater.TAG, "Built-in bundle is active. We skip the check for notifyAppReady.");
|
|
1191
1191
|
return;
|
|
1192
1192
|
}
|
|
1193
|
-
Log.d(
|
|
1193
|
+
Log.d(CapgoUpdater.TAG, "Current bundle is: " + current);
|
|
1194
1194
|
|
|
1195
1195
|
if (BundleStatus.SUCCESS != current.getStatus()) {
|
|
1196
|
-
Log.e(
|
|
1197
|
-
Log.i(
|
|
1196
|
+
Log.e(CapgoUpdater.TAG, "notifyAppReady was not called, roll back current bundle: " + current.getId());
|
|
1197
|
+
Log.i(CapgoUpdater.TAG, "Did you forget to call 'notifyAppReady()' in your Capacitor App code?");
|
|
1198
1198
|
final JSObject ret = new JSObject();
|
|
1199
|
-
ret.put("bundle", current.
|
|
1199
|
+
ret.put("bundle", mapToJSObject(current.toJSONMap()));
|
|
1200
1200
|
this.notifyListeners("updateFailed", ret);
|
|
1201
1201
|
this.implementation.sendStats("update_fail", current.getVersionName());
|
|
1202
1202
|
this.implementation.setError(current);
|
|
1203
1203
|
this._reset(true);
|
|
1204
1204
|
if (CapacitorUpdaterPlugin.this.autoDeleteFailed && !current.isBuiltin()) {
|
|
1205
|
-
Log.i(
|
|
1205
|
+
Log.i(CapgoUpdater.TAG, "Deleting failing bundle: " + current.getVersionName());
|
|
1206
1206
|
try {
|
|
1207
1207
|
final Boolean res = this.implementation.delete(current.getId(), false);
|
|
1208
1208
|
if (res) {
|
|
1209
|
-
Log.i(
|
|
1209
|
+
Log.i(CapgoUpdater.TAG, "Failed bundle deleted: " + current.getVersionName());
|
|
1210
1210
|
}
|
|
1211
1211
|
} catch (final IOException e) {
|
|
1212
|
-
Log.e(
|
|
1212
|
+
Log.e(CapgoUpdater.TAG, "Failed to delete failed bundle: " + current.getVersionName(), e);
|
|
1213
1213
|
}
|
|
1214
1214
|
}
|
|
1215
1215
|
} else {
|
|
1216
|
-
Log.i(
|
|
1216
|
+
Log.i(CapgoUpdater.TAG, "notifyAppReady was called. This is fine: " + current.getId());
|
|
1217
1217
|
}
|
|
1218
1218
|
}
|
|
1219
1219
|
|
|
@@ -1222,15 +1222,12 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1222
1222
|
@Override
|
|
1223
1223
|
public void run() {
|
|
1224
1224
|
try {
|
|
1225
|
-
Log.i(
|
|
1226
|
-
CapacitorUpdater.TAG,
|
|
1227
|
-
"Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady"
|
|
1228
|
-
);
|
|
1225
|
+
Log.i(CapgoUpdater.TAG, "Wait for " + CapacitorUpdaterPlugin.this.appReadyTimeout + "ms, then check for notifyAppReady");
|
|
1229
1226
|
Thread.sleep(CapacitorUpdaterPlugin.this.appReadyTimeout);
|
|
1230
1227
|
CapacitorUpdaterPlugin.this.checkRevert();
|
|
1231
1228
|
CapacitorUpdaterPlugin.this.appReadyCheck = null;
|
|
1232
1229
|
} catch (final InterruptedException e) {
|
|
1233
|
-
Log.i(
|
|
1230
|
+
Log.i(CapgoUpdater.TAG, DeferredNotifyAppReadyCheck.class.getName() + " was interrupted.");
|
|
1234
1231
|
}
|
|
1235
1232
|
}
|
|
1236
1233
|
}
|
|
@@ -1246,7 +1243,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1246
1243
|
) {
|
|
1247
1244
|
this.backgroundDownloadTask = this.backgroundDownload();
|
|
1248
1245
|
} else {
|
|
1249
|
-
Log.i(
|
|
1246
|
+
Log.i(CapgoUpdater.TAG, "Auto update is disabled");
|
|
1250
1247
|
this.sendReadyToJs(current, "disabled");
|
|
1251
1248
|
}
|
|
1252
1249
|
this.checkAppReady();
|
|
@@ -1255,14 +1252,14 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1255
1252
|
public void appMovedToBackground() {
|
|
1256
1253
|
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
1257
1254
|
CapacitorUpdaterPlugin.this.implementation.sendStats("app_moved_to_background", current.getVersionName());
|
|
1258
|
-
Log.i(
|
|
1255
|
+
Log.i(CapgoUpdater.TAG, "Checking for pending update");
|
|
1259
1256
|
try {
|
|
1260
1257
|
// We need to set "backgrounded time"
|
|
1261
1258
|
this.delayUpdateUtils.setBackgroundTimestamp(System.currentTimeMillis());
|
|
1262
1259
|
this.delayUpdateUtils.checkCancelDelay(DelayUpdateUtils.CancelDelaySource.BACKGROUND);
|
|
1263
1260
|
this.installNext();
|
|
1264
1261
|
} catch (final Exception e) {
|
|
1265
|
-
Log.e(
|
|
1262
|
+
Log.e(CapgoUpdater.TAG, "Error during onActivityStopped", e);
|
|
1266
1263
|
}
|
|
1267
1264
|
}
|
|
1268
1265
|
|
|
@@ -1290,7 +1287,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1290
1287
|
}
|
|
1291
1288
|
|
|
1292
1289
|
private void appKilled() {
|
|
1293
|
-
Log.d(
|
|
1290
|
+
Log.d(CapgoUpdater.TAG, "onActivityDestroyed: all activity destroyed");
|
|
1294
1291
|
this.delayUpdateUtils.checkCancelDelay(DelayUpdateUtils.CancelDelaySource.KILLED);
|
|
1295
1292
|
}
|
|
1296
1293
|
|
|
@@ -1299,7 +1296,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1299
1296
|
if (isPreviousMainActivity) {
|
|
1300
1297
|
this.appMovedToForeground();
|
|
1301
1298
|
}
|
|
1302
|
-
Log.i(
|
|
1299
|
+
Log.i(CapgoUpdater.TAG, "onActivityStarted " + getActivity().getClass().getName());
|
|
1303
1300
|
isPreviousMainActivity = true;
|
|
1304
1301
|
}
|
|
1305
1302
|
|
|
@@ -1326,7 +1323,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1326
1323
|
|
|
1327
1324
|
@Override
|
|
1328
1325
|
public void handleOnDestroy() {
|
|
1329
|
-
Log.i(
|
|
1326
|
+
Log.i(CapgoUpdater.TAG, "onActivityDestroyed " + getActivity().getClass().getName());
|
|
1330
1327
|
this.implementation.activity = getActivity();
|
|
1331
1328
|
counterActivityCreate--;
|
|
1332
1329
|
if (counterActivityCreate == 0) {
|