From 654b13e15001d412ace5cc562e333b6f73ea9e16 Mon Sep 17 00:00:00 2001 From: octopus_yan Date: Thu, 19 Sep 2024 12:25:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=98=E7=9B=98=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E4=B8=8E=E4=B8=BB=E7=95=8C=E9=9D=A2=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alistgui/manager/SystemTrayManager.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/cn/octopusyan/alistgui/manager/SystemTrayManager.java b/src/main/java/cn/octopusyan/alistgui/manager/SystemTrayManager.java index 966279f..b2e9407 100644 --- a/src/main/java/cn/octopusyan/alistgui/manager/SystemTrayManager.java +++ b/src/main/java/cn/octopusyan/alistgui/manager/SystemTrayManager.java @@ -76,7 +76,7 @@ public class SystemTrayManager { return; } - initTrayIcon(); + initTrayIcon(AListManager.isRunning()); try { if (!isShowing()) @@ -95,11 +95,12 @@ public class SystemTrayManager { //========================================={ private }=========================================== - private static void initTrayIcon() { + private static void initTrayIcon(boolean running) { if (trayIcon != null) return; // 系统托盘图标 - Image image = Toolkit.getDefaultToolkit().getImage(WindowsUtil.class.getResource("/assets/logo-disabled.png")); + URL resource = WindowsUtil.class.getResource(STR."/assets/logo\{running ? "" : "-disabled"}.png"); + Image image = Toolkit.getDefaultToolkit().getImage(resource); trayIcon = new TrayIcon(image); // 设置图标尺寸自动适应 @@ -129,7 +130,7 @@ public class SystemTrayManager { if (event.isPopupTrigger()) { // 弹出菜单 Platform.runLater(() -> { - initPopupMenu(); + initPopupMenu(running); popupMenu.show(event); }); } else if (event.getButton() == MouseEvent.BUTTON1) { @@ -143,12 +144,15 @@ public class SystemTrayManager { /** * 构建托盘菜单 */ - private static void initPopupMenu() { + private static void initPopupMenu(boolean running) { if (popupMenu != null) return; - MenuItem start = PopupMenu.menuItem(getString("main.control.start"), _ -> AListManager.openScheme()); + MenuItem start = PopupMenu.menuItem( + getString(STR."main.control.\{running ? "stop" : "start"}"), + _ -> AListManager.openScheme() + ); MenuItem browser = PopupMenu.menuItem(getString("main.more.browser"), _ -> AListManager.openScheme()); - browser.setDisable(true); + browser.setDisable(!running); AListManager.runningProperty().addListener((_, _, newValue) -> { start.setText(getString(STR."main.control.\{newValue ? "stop" : "start"}")); @@ -183,4 +187,4 @@ public class SystemTrayManager { private static Stage stage() { return WindowsUtil.getStage(); } -} +} \ No newline at end of file