From fb3c830b7990f9a499753a349d5fd7d3cb27a91c Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Tue, 15 Mar 2016 03:56:12 +0000 Subject: [PATCH] Added shutdown hook to ensure closure of global keyboard hook. --- src/main/java/musicplayer/PlayerGUI.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java index d3eda46..fa78262 100644 --- a/src/main/java/musicplayer/PlayerGUI.java +++ b/src/main/java/musicplayer/PlayerGUI.java @@ -70,6 +70,8 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf try { GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook(); keyboardHook.addKeyListener(new GlobalKeyboardShortcuts()); + Thread hookShutdown = new Thread(keyboardHook::shutdownHook); + Runtime.getRuntime().addShutdownHook(hookShutdown); } catch(RuntimeException | UnsatisfiedLinkError ex){ System.out.println("Keyboard hook failed, global shortcuts will not work this session."); System.out.println(ex.getMessage());