Skip to content

Commit

Permalink
delay opening new dialogs on startup in wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
craigraw committed Sep 11, 2024
1 parent 31f2871 commit ec131bb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
37 changes: 37 additions & 0 deletions src/main/java/com/sparrowwallet/sparrow/AppServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,34 @@ public static AppController newAppWindow(Stage stage) {
}
}

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"));
Expand Down Expand Up @@ -1114,6 +1142,15 @@ public static Font getMonospaceFont() {
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();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public void start(Stage stage) throws Exception {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,9 @@ protected void showGrid() {
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();
}
}
}
Expand Down

0 comments on commit ec131bb

Please sign in to comment.