Skip to content

Commit

Permalink
fix: semaphore issue android
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Aug 18, 2023
1 parent f166255 commit 0da47c9
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,14 @@ private void directUpdateFinish(final BundleInfo latest) {
ret.put("status", "update installed");
CapacitorUpdaterPlugin.this.implementation.set(latest);
CapacitorUpdaterPlugin.this._reload();
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
new Thread(() -> {
try {
// Log.i(CapacitorUpdater.TAG, "semaphoreReady directUpdateFinish");
CapacitorUpdaterPlugin.this.semaphoreReady.await(
CapacitorUpdaterPlugin.this.appReadyTimeout,
TimeUnit.SECONDS
);
// Log.i(CapacitorUpdater.TAG, "semaphoreReady directUpdateFinish done");
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -456,7 +457,16 @@ public void run() {

private boolean _reload() {
final String path = this.implementation.getCurrentBundlePath();
this.semaphoreReady.countDown();
new Thread(() -> {
try {
// Log.i(CapacitorUpdater.TAG, "semaphoreReady _reload");
CapacitorUpdaterPlugin.this.semaphoreReady.await(0, TimeUnit.SECONDS);
// Log.i(CapacitorUpdater.TAG, "semaphoreReady _reload done");
} catch (InterruptedException e) {
e.printStackTrace();
}
})
.start();
Log.i(CapacitorUpdater.TAG, "Reloading: " + path);
if (this.implementation.isUsingBuiltin()) {
this.bridge.setServerAssetPath(path);
Expand Down Expand Up @@ -674,7 +684,9 @@ public void notifyAppReady(final PluginCall call) {
"Current bundle loaded successfully. ['notifyAppReady()' was called] " +
bundle
);
// Log.i(CapacitorUpdater.TAG, "semaphoreReady countDown");
this.semaphoreReady.countDown();
// Log.i(CapacitorUpdater.TAG, "semaphoreReady countDown done");
call.resolve();
} catch (final Exception e) {
Log.e(
Expand Down Expand Up @@ -885,7 +897,18 @@ private void endBackGroundTaskWithNotif(
ret.put("bundle", current.toJSON());
this.notifyListeners("noNeedUpdate", ret);
ret.put("message", msg);
this.notifyListeners("appReady", ret);
new Thread(() -> {
try {
CapacitorUpdaterPlugin.this.semaphoreReady.await(
CapacitorUpdaterPlugin.this.appReadyTimeout,
TimeUnit.SECONDS
);
} catch (InterruptedException e) {
e.printStackTrace();
}
CapacitorUpdaterPlugin.this.notifyListeners("appReady", ret);
})
.start();
Log.i(CapacitorUpdater.TAG, "endBackGroundTaskWithNotif " + msg);
}

Expand Down Expand Up @@ -1257,10 +1280,12 @@ public void appMovedToForeground() {
Log.i(CapacitorUpdater.TAG, "Auto update is disabled");
new Thread(() -> {
try {
// Log.i(CapacitorUpdater.TAG, "semaphoreReady Auto update");
CapacitorUpdaterPlugin.this.semaphoreReady.await(
CapacitorUpdaterPlugin.this.appReadyTimeout,
TimeUnit.SECONDS
);
// Log.i(CapacitorUpdater.TAG, "semaphoreReady Auto update done");
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 0da47c9

Please sign in to comment.