mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 03:41:46 +00:00
Allow custom shortcuts in plugin
This commit is contained in:
@ -15,14 +15,35 @@ function _registerLocalShortcut(win, shortcut, action) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerShortcuts(win) {
|
function registerShortcuts(win, options) {
|
||||||
const { playPause, next, previous, search } = getSongControls(win);
|
const songControls = getSongControls(win);
|
||||||
|
const { playPause, next, previous, search } = songControls;
|
||||||
|
|
||||||
_registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause);
|
_registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause);
|
||||||
_registerGlobalShortcut(win.webContents, "MediaNextTrack", next);
|
_registerGlobalShortcut(win.webContents, "MediaNextTrack", next);
|
||||||
_registerGlobalShortcut(win.webContents, "MediaPreviousTrack", previous);
|
_registerGlobalShortcut(win.webContents, "MediaPreviousTrack", previous);
|
||||||
_registerLocalShortcut(win, "CommandOrControl+F", search);
|
_registerLocalShortcut(win, "CommandOrControl+F", search);
|
||||||
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
||||||
|
|
||||||
|
const { global, local } = options;
|
||||||
|
(global || []).forEach(({ shortcut, action }) => {
|
||||||
|
console.debug("Registering global shortcut", shortcut, ":", action);
|
||||||
|
if (!action || !songControls[action]) {
|
||||||
|
console.warn("Invalid action", action);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_registerGlobalShortcut(win.webContents, shortcut, songControls[action]);
|
||||||
|
});
|
||||||
|
(local || []).forEach(({ shortcut, action }) => {
|
||||||
|
console.debug("Registering local shortcut", shortcut, ":", action);
|
||||||
|
if (!action || !songControls[action]) {
|
||||||
|
console.warn("Invalid action", action);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_registerLocalShortcut(win, shortcut, songControls[action]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = registerShortcuts;
|
module.exports = registerShortcuts;
|
||||||
|
|||||||
Reference in New Issue
Block a user