diff --git a/plugins/shortcuts/back.js b/plugins/shortcuts/back.js index a187ded8..f4f73e0b 100644 --- a/plugins/shortcuts/back.js +++ b/plugins/shortcuts/back.js @@ -36,13 +36,15 @@ function registerShortcuts(win, options) { if (global) { for (const action in global) { if (!global[action]) { - return; //accelerator is empty + continue; //accelerator is empty } + console.debug("Registering global shortcut", global[action], ":", action); if (!songControls[action]) { console.warn("Invalid action", action); - return; + continue; } + _registerGlobalShortcut(win.webContents, global[action], songControls[action]); } } @@ -50,13 +52,15 @@ function registerShortcuts(win, options) { if (local) { for (const action in local) { if (!local[action]) { - return; //accelerator is empty + continue; //accelerator is empty } + console.debug("Registering local shortcut", local[action], ":", action); if (!songControls[action]) { console.warn("Invalid action", action); - return; + continue; } + _registerLocalShortcut(win, local[action], songControls[action]); } } @@ -67,16 +71,18 @@ function updateOptions(options) { let updated = false; for (const optionType of ["global", "local"]) { if (Array.isArray(options[optionType])) { - const updatedOptions = {} - for (const obj of options[optionType]) { - if (obj.action && obj.shortcut) { - updatedOptions[obj.action] = obj.shortcut; + const updatedOptions = {}; + for (const optionObject of options[optionType]) { + if (optionObject.action && optionObject.shortcut) { + updatedOptions[optionObject.action] = optionObject.shortcut; } } + options[optionType] = updatedOptions; updated = true; } } + if (updated) { setOptions("shortcuts", options); } diff --git a/plugins/shortcuts/menu.js b/plugins/shortcuts/menu.js index 2b5622c2..fff28951 100644 --- a/plugins/shortcuts/menu.js +++ b/plugins/shortcuts/menu.js @@ -4,13 +4,6 @@ const prompt = require("custom-electron-prompt"); const path = require("path"); const is = require("electron-is"); -function setOption(options, key = null, newValue = null) { - if (key && newValue) { - options[key] = newValue; - } - setOptions("shortcuts", options) -} - module.exports = (win, options) => [ { label: "Set Global Song Controls", @@ -20,11 +13,19 @@ module.exports = (win, options) => [ label: "Override MediaKeys", type: "checkbox", checked: options.overrideMediaKeys, - click: (item) => setOption(options, "overrideMediaKeys", item.checked) + click: item => setOption(options, "overrideMediaKeys", item.checked) } ]; -const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined } }; +function setOption(options, key = null, newValue = null) { + if (key && newValue) { + options[key] = newValue; + } + + setOptions("shortcuts", options); +} + +const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined }; }; const iconPath = path.join(process.cwd(), "assets", "youtube-music-tray.png"); function promptKeybind(options, win) { @@ -36,11 +37,12 @@ function promptKeybind(options, win) { keybindOptions: [ kb("Previous", "previous", options.global?.previous), kb("Play / Pause", "playPause", options.global?.playPause), - kb("Next", "next", options.global?.next), + kb("Next", "next", options.global?.next) ], customStylesheet: "dark", height: 250 }; + if (!is.macOS()) { Object.assign(promptOptions, { frame: false, @@ -49,15 +51,17 @@ function promptKeybind(options, win) { height: 270 }); } + prompt(promptOptions, win) - .then(output => { - if (output) { - for (const keybindObj of output) { - options.global[keybindObj.value] = keybindObj.accelerator; + .then(output => { + if (output) { + for (const keybindObject of output) { + options.global[keybindObject.value] = keybindObject.accelerator; + } + + setOption(options); } - setOption(options); - } - //else = pressed cancel - }) - .catch(console.error) -} \ No newline at end of file + // else -> pressed cancel + }) + .catch(console.error); +}