From 22c5ea50002686c3b72a4d6f4a8c76494408c242 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 5 May 2021 01:25:45 +0300 Subject: [PATCH] lint --- config/defaults.js | 5 +-- plugins/precise-volume/menu.js | 79 ++++++++++++++++------------------ plugins/shortcuts/back.js | 18 ++++---- plugins/shortcuts/menu.js | 7 +-- 4 files changed, 54 insertions(+), 55 deletions(-) diff --git a/config/defaults.js b/config/defaults.js index a15d6b70..b89a920a 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -60,9 +60,8 @@ const defaultConfig = { steps: 1, //percentage of volume to change arrowsShortcut: true, //enable ArrowUp + ArrowDown local shortcuts globalShortcuts: { - enabled: false, // enable global shortcuts - volumeUp: "Shift+PageUp", // Keybind default can be changed - volumeDown: "Shift+PageDown" + volumeUp: "", + volumeDown: "" }, savedVolume: undefined //plugin save volume between session here } diff --git a/plugins/precise-volume/menu.js b/plugins/precise-volume/menu.js index ba03193e..1919052f 100644 --- a/plugins/precise-volume/menu.js +++ b/plugins/precise-volume/menu.js @@ -1,5 +1,5 @@ const { enabled } = require("./back"); -const { app } = require("electron") +const { app } = require("electron"); const { setOptions } = require("../../config/plugins"); const prompt = require("custom-electron-prompt"); const path = require("path"); @@ -10,7 +10,7 @@ module.exports = (win, options) => [ label: "Local Arrowkeys Controls", type: "checkbox", checked: !!options.arrowsShortcut, - click: (item) => { + click: item => { // Dynamically change setting if plugin is enabled if (enabled()) { win.webContents.send("setArrowsShortcut", item.checked); @@ -24,88 +24,85 @@ module.exports = (win, options) => [ label: "Global Hotkeys", type: "checkbox", checked: !!options.globalShortcuts.volumeUp || !!options.globalShortcuts.volumeDown, - click: item => { - promptGlobalShortcuts(win, options, item); - } + click: item => promptGlobalShortcuts(win, options, item) }, { label: "Set Custom Volume Steps", - click: () => { - promptVolumeSteps(win, options); - } + 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 +// Helper function for globalShortcuts prompt const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined }; }; -function useCustomTitlebar(options) { - if (!is.macOS()) { +function setupPromptOptions(options) { + // TODO Custom titlebar needs testing on macOS + if (is.macOS()) { Object.assign(options, { customStylesheet: "dark", - icon: iconPath, - frame: false, - customScript: customTitlebarPath, - enableRemoteModule: true, + icon: iconPath }); } else { Object.assign(options, { customStylesheet: "dark", icon: iconPath, - }) + // The following are used for custom titlebar + frame: false, + customScript: customTitlebarPath, + enableRemoteModule: true + }); } } function promptVolumeSteps(win, options) { - let promptOptions = { + const promptOptions = { title: "Volume Steps", label: "Choose Volume Increase/Decrease Steps", value: options.steps || 1, type: "counter", - counterOptions: { minimum: 0, maximum: 100, multiFire: true }, - } + counterOptions: { minimum: 0, maximum: 100, multiFire: true } + }; - useCustomTitlebar(promptOptions); + setupPromptOptions(promptOptions); prompt(promptOptions, win).then(input => { if (input || input === 0) { // 0 is somehow valid options.steps = input; setOptions("precise-volume", options); } - }).catch(console.error) + }).catch(console.error); } function promptGlobalShortcuts(win, options, item) { - let promptOptions = { + const 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), + kb("Increase Volume", "volumeUp", options.globalShortcuts?.volumeUp), + kb("Decrease Volume", "volumeDown", options.globalShortcuts?.volumeDown) ], height: 230 }; - useCustomTitlebar(promptOptions); + setupPromptOptions(promptOptions); prompt(promptOptions, win) - .then(output => { - if (output) { - for (const keybindObject of output) { - options.globalShortcuts[keybindObject.value] = keybindObject.accelerator; + .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; } - - 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 + }) + .catch(console.error); +} diff --git a/plugins/shortcuts/back.js b/plugins/shortcuts/back.js index a3452351..688dc5a4 100644 --- a/plugins/shortcuts/back.js +++ b/plugins/shortcuts/back.js @@ -32,7 +32,7 @@ function registerShortcuts(win, options) { _registerLocalShortcut(win, "CommandOrControl+L", search); const { global, local } = options; - const shortcutOptions = {global, local}; + const shortcutOptions = { global, local }; for (const optionType in shortcutOptions) { registerAllShortcuts(shortcutOptions[optionType], optionType); @@ -41,23 +41,25 @@ function registerShortcuts(win, options) { function registerAllShortcuts(container, type) { for (const action in container) { if (!container[action]) { - continue; //accelerator is empty + continue; // Action accelerator is empty } - + console.debug(`Registering ${type} shortcut`, container[action], ":", action); if (!songControls[action]) { console.warn("Invalid action", action); continue; } - - type === "global" ? - _registerGlobalShortcut(win.webContents, container[action], songControls[action]) : - _registerLocalShortcut(win, local[action], songControls[action]); + + if (type === "global") { + _registerGlobalShortcut(win.webContents, container[action], songControls[action]); + } else { // type === "local" + _registerLocalShortcut(win, local[action], songControls[action]); + } } } } -/** Update options to new format */ +/** Update options to new format if they are still an array (old format) */ function updateOptions(options) { let updated = false; for (const optionType of ["global", "local"]) { diff --git a/plugins/shortcuts/menu.js b/plugins/shortcuts/menu.js index 0eec4572..12506a86 100644 --- a/plugins/shortcuts/menu.js +++ b/plugins/shortcuts/menu.js @@ -25,16 +25,17 @@ function setOption(options, key = null, newValue = null) { 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"); +// Helper function for keybind prompt +const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ }; }; function promptKeybind(options, win) { - let promptOptions = { + const promptOptions = { title: "Global Keybinds", icon: iconPath, label: "Choose Global Keybinds for Songs Control:", type: "keybind", - keybindOptions: [ + keybindOptions: [ // If default=undefined then no default is used kb("Previous", "previous", options.global?.previous), kb("Play / Pause", "playPause", options.global?.playPause), kb("Next", "next", options.global?.next)