@capgo/capacitor-updater 5.2.14 → 5.2.16
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.
|
@@ -15,7 +15,6 @@ import android.content.pm.PackageInfo;
|
|
|
15
15
|
import android.content.pm.PackageManager;
|
|
16
16
|
import android.os.Build;
|
|
17
17
|
import android.os.Bundle;
|
|
18
|
-
import android.os.Handler;
|
|
19
18
|
import android.util.Log;
|
|
20
19
|
import androidx.annotation.NonNull;
|
|
21
20
|
import androidx.annotation.Nullable;
|
|
@@ -58,7 +57,7 @@ public class CapacitorUpdaterPlugin
|
|
|
58
57
|
private static final String channelUrlDefault =
|
|
59
58
|
"https://api.capgo.app/channel_self";
|
|
60
59
|
|
|
61
|
-
private final String PLUGIN_VERSION = "5.2.
|
|
60
|
+
private final String PLUGIN_VERSION = "5.2.16";
|
|
62
61
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
63
62
|
|
|
64
63
|
private SharedPreferences.Editor editor;
|
|
@@ -80,21 +79,34 @@ public class CapacitorUpdaterPlugin
|
|
|
80
79
|
|
|
81
80
|
private volatile Thread appReadyCheck;
|
|
82
81
|
|
|
83
|
-
private static final CountDownLatch semaphoreReady = new CountDownLatch(
|
|
82
|
+
private static final CountDownLatch semaphoreReady = new CountDownLatch(0);
|
|
83
|
+
|
|
84
|
+
public void startNewThread(final Runnable function) {
|
|
85
|
+
new Thread(() -> {
|
|
86
|
+
try {
|
|
87
|
+
function.run();
|
|
88
|
+
} catch (Exception e) {
|
|
89
|
+
e.printStackTrace();
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
.start();
|
|
93
|
+
}
|
|
84
94
|
|
|
85
95
|
@Override
|
|
86
96
|
public void load() {
|
|
87
97
|
super.load();
|
|
88
|
-
|
|
98
|
+
startNewThread(() -> {
|
|
99
|
+
Log.i(CapacitorUpdater.TAG, "semaphoreReady load");
|
|
89
100
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
CapacitorUpdaterPlugin.this.semaphoreReady.await(
|
|
102
|
+
CapacitorUpdaterPlugin.this.appReadyTimeout,
|
|
103
|
+
TimeUnit.SECONDS
|
|
104
|
+
);
|
|
93
105
|
} catch (InterruptedException e) {
|
|
94
106
|
e.printStackTrace();
|
|
95
107
|
}
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
Log.i(CapacitorUpdater.TAG, "semaphoreReady load done");
|
|
109
|
+
});
|
|
98
110
|
this.prefs =
|
|
99
111
|
this.getContext()
|
|
100
112
|
.getSharedPreferences(
|
|
@@ -194,20 +206,19 @@ public class CapacitorUpdaterPlugin
|
|
|
194
206
|
ret.put("status", "update installed");
|
|
195
207
|
CapacitorUpdaterPlugin.this.implementation.set(latest);
|
|
196
208
|
CapacitorUpdaterPlugin.this._reload();
|
|
197
|
-
|
|
209
|
+
startNewThread(() -> {
|
|
210
|
+
Log.i(CapacitorUpdater.TAG, "semaphoreReady directUpdateFinish");
|
|
198
211
|
try {
|
|
199
|
-
Log.i(CapacitorUpdater.TAG, "semaphoreReady directUpdateFinish");
|
|
200
212
|
CapacitorUpdaterPlugin.this.semaphoreReady.await(
|
|
201
213
|
CapacitorUpdaterPlugin.this.appReadyTimeout,
|
|
202
214
|
TimeUnit.SECONDS
|
|
203
215
|
);
|
|
204
|
-
Log.i(CapacitorUpdater.TAG, "semaphoreReady directUpdateFinish done");
|
|
205
216
|
} catch (InterruptedException e) {
|
|
206
217
|
e.printStackTrace();
|
|
207
218
|
}
|
|
219
|
+
Log.i(CapacitorUpdater.TAG, "semaphoreReady directUpdateFinish done");
|
|
208
220
|
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
|
|
209
|
-
})
|
|
210
|
-
.start();
|
|
221
|
+
});
|
|
211
222
|
}
|
|
212
223
|
|
|
213
224
|
private void cleanupObsoleteVersions() {
|
|
@@ -349,24 +360,18 @@ public class CapacitorUpdaterPlugin
|
|
|
349
360
|
}
|
|
350
361
|
try {
|
|
351
362
|
Log.i(CapacitorUpdater.TAG, "setChannel " + channel);
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
)
|
|
369
|
-
.start();
|
|
363
|
+
startNewThread(() -> {
|
|
364
|
+
CapacitorUpdaterPlugin.this.implementation.setChannel(
|
|
365
|
+
channel,
|
|
366
|
+
res -> {
|
|
367
|
+
if (res.has("error")) {
|
|
368
|
+
call.reject(res.getString("error"));
|
|
369
|
+
} else {
|
|
370
|
+
call.resolve(res);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
);
|
|
374
|
+
});
|
|
370
375
|
} catch (final Exception e) {
|
|
371
376
|
Log.e(CapacitorUpdater.TAG, "Failed to setChannel: " + channel, e);
|
|
372
377
|
call.reject("Failed to setChannel: " + channel, e);
|
|
@@ -377,21 +382,15 @@ public class CapacitorUpdaterPlugin
|
|
|
377
382
|
public void getChannel(final PluginCall call) {
|
|
378
383
|
try {
|
|
379
384
|
Log.i(CapacitorUpdater.TAG, "getChannel");
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
)
|
|
394
|
-
.start();
|
|
385
|
+
startNewThread(() -> {
|
|
386
|
+
CapacitorUpdaterPlugin.this.implementation.getChannel(res -> {
|
|
387
|
+
if (res.has("error")) {
|
|
388
|
+
call.reject(res.getString("error"));
|
|
389
|
+
} else {
|
|
390
|
+
call.resolve(res);
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
});
|
|
395
394
|
} catch (final Exception e) {
|
|
396
395
|
Log.e(CapacitorUpdater.TAG, "Failed to getChannel", e);
|
|
397
396
|
call.reject("Failed to getChannel", e);
|
|
@@ -416,40 +415,31 @@ public class CapacitorUpdaterPlugin
|
|
|
416
415
|
}
|
|
417
416
|
try {
|
|
418
417
|
Log.i(CapacitorUpdater.TAG, "Downloading " + url);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
sessionKey,
|
|
429
|
-
checksum
|
|
430
|
-
);
|
|
418
|
+
startNewThread(() -> {
|
|
419
|
+
try {
|
|
420
|
+
final BundleInfo downloaded =
|
|
421
|
+
CapacitorUpdaterPlugin.this.implementation.download(
|
|
422
|
+
url,
|
|
423
|
+
version,
|
|
424
|
+
sessionKey,
|
|
425
|
+
checksum
|
|
426
|
+
);
|
|
431
427
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
"download_fail",
|
|
446
|
-
current.getVersionName()
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
428
|
+
call.resolve(downloaded.toJSON());
|
|
429
|
+
} catch (final IOException e) {
|
|
430
|
+
Log.e(CapacitorUpdater.TAG, "Failed to download from: " + url, e);
|
|
431
|
+
call.reject("Failed to download from: " + url, e);
|
|
432
|
+
final JSObject ret = new JSObject();
|
|
433
|
+
ret.put("version", version);
|
|
434
|
+
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
435
|
+
final BundleInfo current =
|
|
436
|
+
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
437
|
+
CapacitorUpdaterPlugin.this.implementation.sendStats(
|
|
438
|
+
"download_fail",
|
|
439
|
+
current.getVersionName()
|
|
440
|
+
);
|
|
450
441
|
}
|
|
451
|
-
)
|
|
452
|
-
.start();
|
|
442
|
+
});
|
|
453
443
|
} catch (final Exception e) {
|
|
454
444
|
Log.e(CapacitorUpdater.TAG, "Failed to download from: " + url, e);
|
|
455
445
|
call.reject("Failed to download from: " + url, e);
|
|
@@ -467,16 +457,18 @@ public class CapacitorUpdaterPlugin
|
|
|
467
457
|
|
|
468
458
|
private boolean _reload() {
|
|
469
459
|
final String path = this.implementation.getCurrentBundlePath();
|
|
470
|
-
|
|
460
|
+
startNewThread(() -> {
|
|
461
|
+
Log.i(CapacitorUpdater.TAG, "semaphoreReady _reload");
|
|
471
462
|
try {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
463
|
+
CapacitorUpdaterPlugin.this.semaphoreReady.await(
|
|
464
|
+
CapacitorUpdaterPlugin.this.appReadyTimeout,
|
|
465
|
+
TimeUnit.SECONDS
|
|
466
|
+
);
|
|
475
467
|
} catch (InterruptedException e) {
|
|
476
468
|
e.printStackTrace();
|
|
477
469
|
}
|
|
478
|
-
|
|
479
|
-
|
|
470
|
+
Log.i(CapacitorUpdater.TAG, "semaphoreReady _reload done");
|
|
471
|
+
});
|
|
480
472
|
Log.i(CapacitorUpdater.TAG, "Reloading: " + path);
|
|
481
473
|
if (this.implementation.isUsingBuiltin()) {
|
|
482
474
|
this.bridge.setServerAssetPath(path);
|
|
@@ -596,46 +588,35 @@ public class CapacitorUpdaterPlugin
|
|
|
596
588
|
|
|
597
589
|
@PluginMethod
|
|
598
590
|
public void getLatest(final PluginCall call) {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
try {
|
|
622
|
-
ret.put(key, res.get(key));
|
|
623
|
-
} catch (JSONException e) {
|
|
624
|
-
e.printStackTrace();
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
call.resolve(ret);
|
|
591
|
+
startNewThread(() -> {
|
|
592
|
+
CapacitorUpdaterPlugin.this.implementation.getLatest(
|
|
593
|
+
CapacitorUpdaterPlugin.this.updateUrl,
|
|
594
|
+
res -> {
|
|
595
|
+
if (res.has("error")) {
|
|
596
|
+
call.reject(res.getString("error"));
|
|
597
|
+
return;
|
|
598
|
+
} else if (res.has("message")) {
|
|
599
|
+
call.reject(res.getString("message"));
|
|
600
|
+
return;
|
|
601
|
+
} else {
|
|
602
|
+
call.resolve(res);
|
|
603
|
+
}
|
|
604
|
+
final JSObject ret = new JSObject();
|
|
605
|
+
Iterator<String> keys = res.keys();
|
|
606
|
+
while (keys.hasNext()) {
|
|
607
|
+
String key = keys.next();
|
|
608
|
+
if (res.has(key)) {
|
|
609
|
+
try {
|
|
610
|
+
ret.put(key, res.get(key));
|
|
611
|
+
} catch (JSONException e) {
|
|
612
|
+
e.printStackTrace();
|
|
629
613
|
}
|
|
630
|
-
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
call.resolve(ret);
|
|
631
617
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
.start();
|
|
635
|
-
} catch (final Exception e) {
|
|
636
|
-
Log.e(CapacitorUpdater.TAG, "Failed to getLatest", e);
|
|
637
|
-
call.reject("Failed to getLatest", e);
|
|
638
|
-
}
|
|
618
|
+
);
|
|
619
|
+
});
|
|
639
620
|
}
|
|
640
621
|
|
|
641
622
|
private boolean _reset(final Boolean toLastSuccessful) {
|
|
@@ -15,7 +15,7 @@ import Version
|
|
|
15
15
|
@objc(CapacitorUpdaterPlugin)
|
|
16
16
|
public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
17
17
|
private var implementation = CapacitorUpdater()
|
|
18
|
-
private let PLUGIN_VERSION: String = "5.2.
|
|
18
|
+
private let PLUGIN_VERSION: String = "5.2.16"
|
|
19
19
|
static let updateUrlDefault = "https://api.capgo.app/updates"
|
|
20
20
|
static let statsUrlDefault = "https://api.capgo.app/stats"
|
|
21
21
|
static let channelUrlDefault = "https://api.capgo.app/channel_self"
|