diff --git a/menu.js b/menu.js index d2b778e7..776a52eb 100644 --- a/menu.js +++ b/menu.js @@ -141,18 +141,17 @@ const mainMenuTemplate = (win) => [ ], }, { type: "separator" }, - // Should be put in Advanced Options submenu - { - label: "Proxy", - type: "checkbox", - checked: !!config.get("options.proxy"), - click: (item) => { - setProxy(item, win); - } - }, { label: "Advanced options", submenu: [ + { + label: "Proxy", + type: "checkbox", + checked: !!config.get("options.proxy"), + click: (item) => { + setProxy(item, win); + } + }, { label: "Disable hardware acceleration", type: "checkbox", diff --git a/plugins/precise-volume/front.js b/plugins/precise-volume/front.js index a1b30fe4..5b66b31f 100644 --- a/plugins/precise-volume/front.js +++ b/plugins/precise-volume/front.js @@ -12,9 +12,7 @@ module.exports = (options) => { setupLocalArrowShortcuts(options); - if (options.globalShortcuts?.enabled) { - setupGlobalShortcuts(options); - } + setupGlobalShortcuts(options); firstRun(options); diff --git a/plugins/precise-volume/menu.js b/plugins/precise-volume/menu.js index d4ed37a7..ba03193e 100644 --- a/plugins/precise-volume/menu.js +++ b/plugins/precise-volume/menu.js @@ -1,13 +1,17 @@ const { enabled } = require("./back"); +const { app } = require("electron") const { setOptions } = require("../../config/plugins"); +const prompt = require("custom-electron-prompt"); +const path = require("path"); +const is = require("electron-is"); module.exports = (win, options) => [ { - label: "Arrowkeys controls", + label: "Local Arrowkeys Controls", type: "checkbox", checked: !!options.arrowsShortcut, click: (item) => { - // Dynamically change setting if plugin enabled + // Dynamically change setting if plugin is enabled if (enabled()) { win.webContents.send("setArrowsShortcut", item.checked); } else { // Fallback to usual method if disabled @@ -15,5 +19,93 @@ module.exports = (win, options) => [ setOptions("precise-volume", options); } } + }, + { + label: "Global Hotkeys", + type: "checkbox", + checked: !!options.globalShortcuts.volumeUp || !!options.globalShortcuts.volumeDown, + click: item => { + promptGlobalShortcuts(win, options, item); + } + }, + { + label: "Set Custom Volume Steps", + click: () => { + promptVolumeSteps(win, options); + } } ]; + +const iconPath = path.join(app.getAppPath(), "assets", "youtube-music-tray.png"); +const customTitlebarPath = path.join(app.getAppPath(), "plugins", "in-app-menu", "prompt-custom-titlebar.js"); +// helper function for globalShortcuts prompt +const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined }; }; + +function useCustomTitlebar(options) { + if (!is.macOS()) { + Object.assign(options, { + customStylesheet: "dark", + icon: iconPath, + frame: false, + customScript: customTitlebarPath, + enableRemoteModule: true, + }); + } else { + Object.assign(options, { + customStylesheet: "dark", + icon: iconPath, + }) + } +} + +function promptVolumeSteps(win, options) { + let promptOptions = { + title: "Volume Steps", + label: "Choose Volume Increase/Decrease Steps", + value: options.steps || 1, + type: "counter", + counterOptions: { minimum: 0, maximum: 100, multiFire: true }, + } + + useCustomTitlebar(promptOptions); + + prompt(promptOptions, win).then(input => { + if (input || input === 0) { // 0 is somehow valid + options.steps = input; + setOptions("precise-volume", options); + } + }).catch(console.error) +} + +function promptGlobalShortcuts(win, options, item) { + let promptOptions = { + title: "Global Volume Keybinds", + label: "Choose Global Volume Keybinds:", + type: "keybind", + keybindOptions: [ + kb("Volume Up", "volumeUp", options.globalShortcuts?.volumeUp), + kb("Volume Down", "volumeDown", options.globalShortcuts?.volumeDown), + ], + height: 230 + }; + + useCustomTitlebar(promptOptions); + + prompt(promptOptions, win) + .then(output => { + if (output) { + for (const keybindObject of output) { + options.globalShortcuts[keybindObject.value] = keybindObject.accelerator; + } + + setOptions("precise-volume", options); + + item.checked = !!options.globalShortcuts.volumeUp || !!options.globalShortcuts.volumeDown; + } + else { + // Reset checkbox if prompt was canceled + item.checked = !item.checked; + } + }) + .catch(console.error); +} \ No newline at end of file diff --git a/plugins/shortcuts/menu.js b/plugins/shortcuts/menu.js index fff28951..0eec4572 100644 --- a/plugins/shortcuts/menu.js +++ b/plugins/shortcuts/menu.js @@ -18,7 +18,7 @@ module.exports = (win, options) => [ ]; function setOption(options, key = null, newValue = null) { - if (key && newValue) { + if (key && newValue !== null) { options[key] = newValue; }