From adde4f277b33e29ea02dca0c478a9fac9e20466b Mon Sep 17 00:00:00 2001 From: chaorace Date: Wed, 18 May 2016 19:23:48 +0000 Subject: [PATCH] Added exit function to tray icon --- src/main/java/GUI.scala | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/GUI.scala b/src/main/java/GUI.scala index c20bb8d..78c412e 100644 --- a/src/main/java/GUI.scala +++ b/src/main/java/GUI.scala @@ -84,10 +84,7 @@ class Gui(startHidden: Boolean, config: Config) extends JFXApp { }) //If the user tries closing the GUI while the engine is running, the thread gets shut down onCloseRequest = handle { - GlobalScreen.unregisterNativeHook() - toggleTray(false) - if(engineThread != null) engineThread.stop() - Platform.exit() + exit } } @@ -106,13 +103,21 @@ class Gui(startHidden: Boolean, config: Config) extends JFXApp { Platform.runLater(engineToggler()) } } + val exitAction = new ActionListener(){ + override def actionPerformed(e: ActionEvent): Unit = { + Platform.runLater(exit()) + } + } val showGuiItem = new MenuItem("Show GUI") showGuiItem.addActionListener(defaultAction) val toggleEngineItem = new MenuItem("On/Off Toggle") toggleEngineItem.addActionListener(engineAction) + val exitItem = new MenuItem("Exit") + exitItem.addActionListener(exitAction) val popup = new PopupMenu() popup.add(showGuiItem) popup.add(toggleEngineItem) + popup.add(exitItem) val image = ImageIO.read(getClass.getResourceAsStream("icon.png")) val trayIcon = new TrayIcon(image, Main.name, popup) trayIcon.addActionListener(defaultAction) @@ -154,6 +159,13 @@ class Gui(startHidden: Boolean, config: Config) extends JFXApp { case true => engineThread.stop(); engine = false } } + + def exit(): Unit ={ + GlobalScreen.unregisterNativeHook() + toggleTray(false) + if(engineThread != null) engineThread.stop() + Platform.exit() + } } class InputField(description: String, tt: Tooltip) extends HBox {