@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.14";
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(1);
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
- new Thread(() -> {
98
+ startNewThread(() -> {
99
+ Log.i(CapacitorUpdater.TAG, "semaphoreReady load");
89
100
  try {
90
- Log.i(CapacitorUpdater.TAG, "semaphoreReady load");
91
- CapacitorUpdaterPlugin.this.semaphoreReady.await(0, TimeUnit.SECONDS);
92
- Log.i(CapacitorUpdater.TAG, "semaphoreReady load done");
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
- .start();
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
- new Thread(() -> {
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
- new Thread(
353
- new Runnable() {
354
- @Override
355
- public void run() {
356
- CapacitorUpdaterPlugin.this.implementation.setChannel(
357
- channel,
358
- res -> {
359
- if (res.has("error")) {
360
- call.reject(res.getString("error"));
361
- } else {
362
- call.resolve(res);
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
- new Thread(
381
- new Runnable() {
382
- @Override
383
- public void run() {
384
- CapacitorUpdaterPlugin.this.implementation.getChannel(res -> {
385
- if (res.has("error")) {
386
- call.reject(res.getString("error"));
387
- } else {
388
- call.resolve(res);
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
- new Thread(
420
- new Runnable() {
421
- @Override
422
- public void run() {
423
- try {
424
- final BundleInfo downloaded =
425
- CapacitorUpdaterPlugin.this.implementation.download(
426
- url,
427
- version,
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
- call.resolve(downloaded.toJSON());
433
- } catch (final IOException e) {
434
- Log.e(CapacitorUpdater.TAG, "Failed to download from: " + url, e);
435
- call.reject("Failed to download from: " + url, e);
436
- final JSObject ret = new JSObject();
437
- ret.put("version", version);
438
- CapacitorUpdaterPlugin.this.notifyListeners(
439
- "downloadFailed",
440
- ret
441
- );
442
- final BundleInfo current =
443
- CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
444
- CapacitorUpdaterPlugin.this.implementation.sendStats(
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
- new Thread(() -> {
460
+ startNewThread(() -> {
461
+ Log.i(CapacitorUpdater.TAG, "semaphoreReady _reload");
471
462
  try {
472
- Log.i(CapacitorUpdater.TAG, "semaphoreReady _reload");
473
- CapacitorUpdaterPlugin.this.semaphoreReady.await(0, TimeUnit.SECONDS);
474
- Log.i(CapacitorUpdater.TAG, "semaphoreReady _reload done");
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
- .start();
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
- try {
600
- new Thread(
601
- new Runnable() {
602
- @Override
603
- public void run() {
604
- CapacitorUpdaterPlugin.this.implementation.getLatest(
605
- CapacitorUpdaterPlugin.this.updateUrl,
606
- res -> {
607
- if (res.has("error")) {
608
- call.reject(res.getString("error"));
609
- return;
610
- } else if (res.has("message")) {
611
- call.reject(res.getString("message"));
612
- return;
613
- } else {
614
- call.resolve(res);
615
- }
616
- final JSObject ret = new JSObject();
617
- Iterator<String> keys = res.keys();
618
- while (keys.hasNext()) {
619
- String key = keys.next();
620
- if (res.has(key)) {
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.14"
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"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "5.2.14",
3
+ "version": "5.2.16",
4
4
  "packageManager": "pnpm@8.6.12",
5
5
  "license": "MPL-2.0",
6
6
  "description": "Live update for capacitor apps",