diff --git a/js/hotkeys.ts b/js/hotkeys.ts index eef797c4..9b57251c 100644 --- a/js/hotkeys.ts +++ b/js/hotkeys.ts @@ -21,7 +21,7 @@ import { TOGGLE_TIME_MODE, TOGGLE_LLAMA_MODE } from "./actionTypes"; import { arraysAreEqual } from "./utils"; import { Dispatch } from "./types"; -export function bindHotkeys(dispatch: Dispatch): () => void { +export default function(dispatch: Dispatch) { let keylog: number[] = []; const trigger = [ 78, // N @@ -33,8 +33,7 @@ export function bindHotkeys(dispatch: Dispatch): () => void { 70, // F 84 // T ]; - - const listener = (e: KeyboardEvent) => { + document.addEventListener("keydown", e => { if (e.ctrlKey) { switch (e.keyCode) { case 68: // CTRL+D @@ -143,10 +142,5 @@ export function bindHotkeys(dispatch: Dispatch): () => void { dispatch({ type: TOGGLE_LLAMA_MODE }); } } - }; - document.addEventListener("keydown", listener); - - return () => { - document.removeEventListener("keydown", listener); - }; + }); } diff --git a/js/webampLazy.js b/js/webampLazy.js index c7db55a4..93e24673 100644 --- a/js/webampLazy.js +++ b/js/webampLazy.js @@ -4,7 +4,7 @@ import { Provider } from "react-redux"; import getStore from "./store"; import App from "./components/App"; -import { bindHotkeys } from "./hotkeys"; +import Hotkeys from "./hotkeys"; import Media from "./media"; import * as Selectors from "./selectors"; import { @@ -65,7 +65,6 @@ class Winamp { } constructor(options) { - this._subscriptions = []; this._actionEmitter = new Emitter(); this.options = options; const { @@ -162,7 +161,7 @@ class Winamp { } if (enableHotkeys) { - this._subscriptions.push(bindHotkeys(this.store.dispatch)); + new Hotkeys(this.store.dispatch); } }