Skip to content

Commit ec131bb

Browse files
committed
delay opening new dialogs on startup in wayland
1 parent 31f2871 commit ec131bb

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

src/main/java/com/sparrowwallet/sparrow/AppServices.java

+37
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,34 @@ public static AppController newAppWindow(Stage stage) {
573573
}
574574
}
575575

576+
public static void runAfterDelay(long delay, Runnable runnable) {
577+
if(delay <= 0) {
578+
if(Platform.isFxApplicationThread()) {
579+
runnable.run();
580+
} else {
581+
Platform.runLater(runnable);
582+
}
583+
} else {
584+
ScheduledService<Void> delayService = new ScheduledService<>() {
585+
@Override
586+
protected Task<Void> createTask() {
587+
return new Task<>() {
588+
@Override
589+
protected Void call() {
590+
return null;
591+
}
592+
};
593+
}
594+
};
595+
delayService.setOnSucceeded(_ -> {
596+
delayService.cancel();
597+
runnable.run();
598+
});
599+
delayService.setDelay(Duration.millis(delay));
600+
delayService.start();
601+
}
602+
}
603+
576604
private static Image getWindowIcon() {
577605
if(windowIcon == null) {
578606
windowIcon = new Image(SparrowWallet.class.getResourceAsStream("/image/sparrow-icon.png"));
@@ -1114,6 +1142,15 @@ public static Font getMonospaceFont() {
11141142
return Font.font("Roboto Mono", 13);
11151143
}
11161144

1145+
public static boolean isOnWayland() {
1146+
if(org.controlsfx.tools.Platform.getCurrent() != org.controlsfx.tools.Platform.UNIX) {
1147+
return false;
1148+
}
1149+
1150+
String waylandDisplay = System.getenv("WAYLAND_DISPLAY");
1151+
return waylandDisplay != null && !waylandDisplay.isEmpty();
1152+
}
1153+
11171154
@Subscribe
11181155
public void newConnection(ConnectionEvent event) {
11191156
currentBlockHeight = event.getBlockHeight();

src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public void start(Stage stage) throws Exception {
9090
AppController appController = AppServices.newAppWindow(stage);
9191

9292
final boolean showNewWallet = createNewWallet;
93-
javafx.application.Platform.runLater(() -> {
93+
//Delay opening new dialogs on Wayland
94+
AppServices.runAfterDelay(AppServices.isOnWayland() ? 1000 : 0, () -> {
9495
if(showNewWallet) {
9596
appController.newWallet(null);
9697
}

src/main/java/com/sparrowwallet/sparrow/control/MnemonicKeystorePane.java

+1-15
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,9 @@ protected void showGrid() {
113113
wordEntry.getEditor().setText(words.get(i));
114114
wordEntry.getEditor().setEditable(false);
115115
} else {
116-
ScheduledService<Void> service = new ScheduledService<>() {
117-
@Override
118-
protected Task<Void> createTask() {
119-
return new Task<>() {
120-
@Override
121-
protected Void call() {
122-
return null;
123-
}
124-
};
125-
}
126-
};
127-
service.setDelay(Duration.millis(500));
128-
service.setOnSucceeded(event1 -> {
129-
service.cancel();
116+
AppServices.runAfterDelay(500, () -> {
130117
Platform.runLater(() -> wordEntry.getEditor().requestFocus());
131118
});
132-
service.start();
133119
}
134120
}
135121
}

0 commit comments

Comments
 (0)