mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 20:52:06 +00:00
refactor registerAllShortcuts
This commit is contained in:
@ -32,35 +32,26 @@ function registerShortcuts(win, options) {
|
|||||||
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
||||||
|
|
||||||
const { global, local } = options;
|
const { global, local } = options;
|
||||||
|
const shortcutOptions = {global, local};
|
||||||
|
|
||||||
if (global) {
|
for (const optionType in shortcutOptions) {
|
||||||
for (const action in global) {
|
registerAllShortcuts(shortcutOptions[optionType], optionType);
|
||||||
if (!global[action]) {
|
|
||||||
continue; //accelerator is empty
|
|
||||||
}
|
|
||||||
|
|
||||||
console.debug("Registering global shortcut", global[action], ":", action);
|
|
||||||
if (!songControls[action]) {
|
|
||||||
console.warn("Invalid action", action);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
_registerGlobalShortcut(win.webContents, global[action], songControls[action]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local) {
|
function registerAllShortcuts(container, type) {
|
||||||
for (const action in local) {
|
for (const action in container) {
|
||||||
if (!local[action]) {
|
if (!container[action]) {
|
||||||
continue; //accelerator is empty
|
continue; //accelerator is empty
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug("Registering local shortcut", local[action], ":", action);
|
console.debug(`Registering ${type} shortcut`, container[action], ":", action);
|
||||||
if (!songControls[action]) {
|
if (!songControls[action]) {
|
||||||
console.warn("Invalid action", action);
|
console.warn("Invalid action", action);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type === "global" ?
|
||||||
|
_registerGlobalShortcut(win.webContents, container[action], songControls[action]) :
|
||||||
_registerLocalShortcut(win, local[action], songControls[action]);
|
_registerLocalShortcut(win, local[action], songControls[action]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user