mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2026-10-16 21:21:33 +08:00
enhance(macos): 日志、游戏崩溃、HMCL崩溃窗口按下 CMD+W 时退出 (#6813)
This commit is contained in:
@@ -72,6 +72,8 @@ public class CrashWindow extends Stage {
|
||||
FXUtils.setIcon(this);
|
||||
setTitle(i18n("message.error"));
|
||||
|
||||
FXUtils.addMacOSCloseWindowHandler(this, null);
|
||||
|
||||
setOnCloseRequest(e -> javafx.application.Platform.exit());
|
||||
}
|
||||
|
||||
|
||||
@@ -58,9 +58,7 @@ import javafx.scene.paint.Paint;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextFlow;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Screen;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.*;
|
||||
import javafx.util.Duration;
|
||||
import javafx.util.StringConverter;
|
||||
import org.glavo.url.WebURL;
|
||||
@@ -109,10 +107,7 @@ import java.nio.file.Path;
|
||||
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;
|
||||
|
||||
@@ -1200,6 +1195,18 @@ public final class FXUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void addMacOSCloseWindowHandler(Window window, @Nullable Supplier<Boolean> restriction) {
|
||||
window.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
|
||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS
|
||||
&& event.isMetaDown()
|
||||
&& event.getCode() == KeyCode.W
|
||||
&& (restriction == null || restriction.get())) {
|
||||
window.fireEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSE_REQUEST));
|
||||
event.consume();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static <N extends Parent> N prepareNode(N node) {
|
||||
Scene dummyScene = new Scene(node);
|
||||
StyleSheets.init(dummyScene);
|
||||
|
||||
@@ -114,6 +114,8 @@ public class GameCrashWindow extends Stage {
|
||||
setTitle(i18n("game.crash.title"));
|
||||
FXUtils.setIcon(this);
|
||||
|
||||
FXUtils.addMacOSCloseWindowHandler(this, null);
|
||||
|
||||
analyzeCrashReport();
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,8 @@ public final class LogWindow extends Stage {
|
||||
}
|
||||
|
||||
this.gameProcess = gameProcess;
|
||||
|
||||
FXUtils.addMacOSCloseWindowHandler(this, () -> !gameProcess.isRunning());
|
||||
}
|
||||
|
||||
public void logLine(Log log) {
|
||||
|
||||
Reference in New Issue
Block a user