refactor registerAllShortcuts

This commit is contained in:
Araxeus
2021-04-30 05:09:49 +03:00
parent d0d4ada7c2
commit ec981ac547

View File

@ -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]);
} }
} }