-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(panel): global hotkey to playerlist filter
- Loading branch information
Showing
10 changed files
with
101 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { throttle } from "throttle-debounce"; | ||
|
||
export type GlobalHotkeyAction = 'focusPlayerlistFilter' | 'toggleLightMode'; | ||
|
||
const keyDebounceTime = 150; //ms | ||
const sendHotkeyEvent = throttle(keyDebounceTime, (action: GlobalHotkeyAction) => { | ||
console.log('sending hotkey event', action); | ||
window.postMessage({ | ||
type: 'globalHotkey', | ||
action, | ||
}); | ||
}, { noTrailing: true }); | ||
|
||
|
||
/** | ||
* Handles events and returns true if the event was handled. | ||
*/ | ||
export function handleHotkeyEvent(e: KeyboardEvent) { | ||
if (e.code === 'KeyK' && e.ctrlKey) { | ||
sendHotkeyEvent('focusPlayerlistFilter'); | ||
return true; | ||
} else if (e.code === 'KeyL' && e.ctrlKey && e.shiftKey && window.txConsts.showAdvanced) { | ||
sendHotkeyEvent('toggleLightMode'); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
/** | ||
* Event listener for hotkeys with preventDefault. | ||
*/ | ||
export function hotkeyEventListener(e: KeyboardEvent) { | ||
if (handleHotkeyEvent(e)) { | ||
e.preventDefault(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters