Skip to content

Commit

Permalink
Added exit function to tray icon
Browse files Browse the repository at this point in the history
  • Loading branch information
chaorace committed May 18, 2016
1 parent d0c3cbb commit adde4f2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/GUI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit adde4f2

Please sign in to comment.