Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/CrashWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ else if (UpdateChecker.isOutdated())
FXUtils.setIcon(this);
setTitle(i18n("message.error"));

FXUtils.addMacOSCloseWindowHandler(this, null);

setOnCloseRequest(e -> javafx.application.Platform.exit());
}

Expand Down
17 changes: 13 additions & 4 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@
import java.nio.file.PathMatcher;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.ToIntFunction;
import java.util.function.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -1200,6 +1197,18 @@ public static void onSecondaryButtonClicked(Node node, Runnable action) {
});
}

public static void addMacOSCloseWindowHandler(Stage stage, @Nullable Supplier<Boolean> restriction) {
stage.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS
&& event.isMetaDown()
&& event.getCode() == KeyCode.W
&& (restriction == null || restriction.get())) {
stage.close();
event.consume();
}
});
}

public static <N extends Parent> N prepareNode(N node) {
Scene dummyScene = new Scene(node);
StyleSheets.init(dummyScene);
Expand Down
2 changes: 2 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/GameCrashWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public GameCrashWindow(ManagedProcess managedProcess, ProcessListener.ExitType e
setTitle(i18n("game.crash.title"));
FXUtils.setIcon(this);

FXUtils.addMacOSCloseWindowHandler(this, null);

analyzeCrashReport();
}

Expand Down
2 changes: 2 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public LogWindow(ManagedProcess gameProcess, CircularArrayList<Log> logs) {
}

this.gameProcess = gameProcess;

FXUtils.addMacOSCloseWindowHandler(this, () -> !gameProcess.isRunning());
}

public void logLine(Log log) {
Expand Down