Fix window not shown on second startup

This commit is contained in:
crschnick 2023-10-13 19:43:52 +00:00
parent 0d065dc14e
commit e34fd638a3

View file

@ -4,13 +4,12 @@ import io.xpipe.app.core.App;
import io.xpipe.app.core.AppGreetings; import io.xpipe.app.core.AppGreetings;
import io.xpipe.app.core.AppMainWindow; import io.xpipe.app.core.AppMainWindow;
import io.xpipe.app.fxcomps.util.PlatformThread; import io.xpipe.app.fxcomps.util.PlatformThread;
import io.xpipe.app.issue.*; import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.issue.TrackEvent;
import io.xpipe.app.update.CommercializationAlert; import io.xpipe.app.update.CommercializationAlert;
import io.xpipe.app.update.UpdateChangelogAlert; import io.xpipe.app.update.UpdateChangelogAlert;
import io.xpipe.app.util.UnlockAlert; import io.xpipe.app.util.UnlockAlert;
import javafx.application.Platform; import javafx.stage.Stage;
import java.util.concurrent.CountDownLatch;
public class GuiMode extends PlatformMode { public class GuiMode extends PlatformMode {
@ -28,26 +27,17 @@ public class GuiMode extends PlatformMode {
CommercializationAlert.showIfNeeded(); CommercializationAlert.showIfNeeded();
AppGreetings.showIfNeeded(); AppGreetings.showIfNeeded();
CountDownLatch latch = new CountDownLatch(1); TrackEvent.info("mode", "Waiting for window setup completion ...");
Platform.runLater(() -> { PlatformThread.runLaterIfNeededBlocking(() -> {
if (AppMainWindow.getInstance() == null) { if (AppMainWindow.getInstance() == null) {
try { try {
App.getApp().setupWindow(); App.getApp().setupWindow();
AppMainWindow.getInstance().show();
latch.countDown();
} catch (Throwable t) { } catch (Throwable t) {
ErrorEvent.fromThrowable(t).terminal(true).handle(); ErrorEvent.fromThrowable(t).terminal(true).handle();
} }
} else {
latch.countDown();
} }
AppMainWindow.getInstance().show();
}); });
TrackEvent.info("mode", "Waiting for window setup completion ...");
try {
latch.await();
} catch (InterruptedException ignored) {
}
TrackEvent.info("mode", "Window setup complete"); TrackEvent.info("mode", "Window setup complete");
} }
@ -55,8 +45,8 @@ public class GuiMode extends PlatformMode {
public void onSwitchFrom() { public void onSwitchFrom() {
super.onSwitchFrom(); super.onSwitchFrom();
PlatformThread.runLaterIfNeededBlocking(() -> { PlatformThread.runLaterIfNeededBlocking(() -> {
TrackEvent.info("mode", "Closing window"); TrackEvent.info("mode", "Closing windows");
App.getApp().close(); Stage.getWindows().stream().toList().forEach(w -> w.hide());
}); });
} }