delay opening new dialogs on startup in wayland

This commit is contained in:
Craig Raw 2024-09-11 12:03:13 +02:00
parent 31f287125f
commit ec131bb8da
3 changed files with 40 additions and 16 deletions

View file

@ -573,6 +573,34 @@ public class AppServices {
}
}
public static void runAfterDelay(long delay, Runnable runnable) {
if(delay <= 0) {
if(Platform.isFxApplicationThread()) {
runnable.run();
} else {
Platform.runLater(runnable);
}
} else {
ScheduledService<Void> delayService = new ScheduledService<>() {
@Override
protected Task<Void> createTask() {
return new Task<>() {
@Override
protected Void call() {
return null;
}
};
}
};
delayService.setOnSucceeded(_ -> {
delayService.cancel();
runnable.run();
});
delayService.setDelay(Duration.millis(delay));
delayService.start();
}
}
private static Image getWindowIcon() {
if(windowIcon == null) {
windowIcon = new Image(SparrowWallet.class.getResourceAsStream("/image/sparrow-icon.png"));
@ -1114,6 +1142,15 @@ public class AppServices {
return Font.font("Roboto Mono", 13);
}
public static boolean isOnWayland() {
if(org.controlsfx.tools.Platform.getCurrent() != org.controlsfx.tools.Platform.UNIX) {
return false;
}
String waylandDisplay = System.getenv("WAYLAND_DISPLAY");
return waylandDisplay != null && !waylandDisplay.isEmpty();
}
@Subscribe
public void newConnection(ConnectionEvent event) {
currentBlockHeight = event.getBlockHeight();

View file

@ -90,7 +90,8 @@ public class SparrowDesktop extends Application {
AppController appController = AppServices.newAppWindow(stage);
final boolean showNewWallet = createNewWallet;
javafx.application.Platform.runLater(() -> {
//Delay opening new dialogs on Wayland
AppServices.runAfterDelay(AppServices.isOnWayland() ? 1000 : 0, () -> {
if(showNewWallet) {
appController.newWallet(null);
}

View file

@ -113,23 +113,9 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
wordEntry.getEditor().setText(words.get(i));
wordEntry.getEditor().setEditable(false);
} else {
ScheduledService<Void> service = new ScheduledService<>() {
@Override
protected Task<Void> createTask() {
return new Task<>() {
@Override
protected Void call() {
return null;
}
};
}
};
service.setDelay(Duration.millis(500));
service.setOnSucceeded(event1 -> {
service.cancel();
AppServices.runAfterDelay(500, () -> {
Platform.runLater(() -> wordEntry.getEditor().requestFocus());
});
service.start();
}
}
}