From e4eed2e51979378e62dab902e425218cae5108dc Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 28 Apr 2021 02:41:44 +0300 Subject: [PATCH 01/26] add custom-electron-prompt also use it to set proxy option --- index.js | 6 +- menu.js | 193 +++++++++++------- package.json | 1 + plugins/in-app-menu/prompt-custom-titlebar.js | 14 ++ yarn.lock | 16 ++ 5 files changed, 154 insertions(+), 76 deletions(-) create mode 100644 plugins/in-app-menu/prompt-custom-titlebar.js diff --git a/index.js b/index.js index 82bb3320..a21f45f4 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,9 @@ if (config.get("options.proxy")) { } // Adds debug features like hotkeys for triggering dev tools and reload -require("electron-debug")(); +require("electron-debug")({ + showDevTools: false, //disable automatic devTools on new window +}); // Prevent window being garbage collected let mainWindow; @@ -58,7 +60,7 @@ function onClosed() { function loadPlugins(win) { injectCSS(win.webContents, path.join(__dirname, "youtube-music.css")); - win.webContents.on("did-finish-load", () => { + win.webContents.once("did-finish-load", () => { if (is.dev()) { console.log("did finish load"); win.webContents.openDevTools(); diff --git a/menu.js b/menu.js index f974c4e4..438fe4cb 100644 --- a/menu.js +++ b/menu.js @@ -6,6 +6,7 @@ const is = require("electron-is"); const { getAllPlugins } = require("./plugins/utils"); const config = require("./config"); +const prompt = require("custom-electron-prompt"); const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu = false) => ({ label: label || plugin, @@ -103,30 +104,38 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ }, ...(is.windows() || is.linux() ? [ - { - label: "Hide menu", - type: "checkbox", - checked: config.get("options.hideMenu"), - click: (item) => { - config.set("options.hideMenu", item.checked); - }, + { + label: "Hide menu", + type: "checkbox", + checked: config.get("options.hideMenu"), + click: (item) => { + config.set("options.hideMenu", item.checked); }, - ] + }, + ] : []), ...(is.windows() || is.macOS() ? // Only works on Win/Mac - // https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows - [ - { - label: "Start at login", - type: "checkbox", - checked: config.get("options.startAtLogin"), - click: (item) => { - config.set("options.startAtLogin", item.checked); - }, + // https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows + [ + { + label: "Start at login", + type: "checkbox", + checked: config.get("options.startAtLogin"), + click: (item) => { + config.set("options.startAtLogin", item.checked); }, - ] + }, + ] : []), + { + label: "Proxy", + type: "checkbox", + checked: !!config.get("options.proxy"), + click: (item) => { + setProxy(item, win); + } + }, { label: "Tray", submenu: [ @@ -194,56 +203,56 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ }, ...(!isTray ? [ - { - label: "View", - submenu: withRoles - ? [ - { role: "reload" }, - { role: "forceReload" }, - { type: "separator" }, - { role: "zoomIn" }, - { role: "zoomOut" }, - { role: "resetZoom" }, - ] - : [ - { - label: "Reload", - click: () => { - win.webContents.reload(); - }, - }, - { - label: "Force Reload", - click: () => { - win.webContents.reloadIgnoringCache(); - }, - }, - { type: "separator" }, - { - label: "Zoom In", - click: () => { - win.webContents.setZoomLevel( - win.webContents.getZoomLevel() + 1 - ); - }, - }, - { - label: "Zoom Out", - click: () => { - win.webContents.setZoomLevel( - win.webContents.getZoomLevel() - 1 - ); - }, - }, - { - label: "Reset Zoom", - click: () => { - win.webContents.setZoomLevel(0); - }, - }, - ], - }, - ] + { + label: "View", + submenu: withRoles + ? [ + { role: "reload" }, + { role: "forceReload" }, + { type: "separator" }, + { role: "zoomIn" }, + { role: "zoomOut" }, + { role: "resetZoom" }, + ] + : [ + { + label: "Reload", + click: () => { + win.webContents.reload(); + }, + }, + { + label: "Force Reload", + click: () => { + win.webContents.reloadIgnoringCache(); + }, + }, + { type: "separator" }, + { + label: "Zoom In", + click: () => { + win.webContents.setZoomLevel( + win.webContents.getZoomLevel() + 1 + ); + }, + }, + { + label: "Zoom Out", + click: () => { + win.webContents.setZoomLevel( + win.webContents.getZoomLevel() - 1 + ); + }, + }, + { + label: "Reset Zoom", + click: () => { + win.webContents.setZoomLevel(0); + }, + }, + ], + }, + ] : []), { label: "Navigation", @@ -273,13 +282,13 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ }, ...(!isTray ? [ - { - label: "Quit App", - click: () => { - app.quit(); - }, + { + label: "Quit App", + click: () => { + app.quit(); }, - ] + }, + ] : []), ], }, @@ -318,3 +327,39 @@ module.exports.setApplicationMenu = (win) => { const menu = Menu.buildFromTemplate(menuTemplate); Menu.setApplicationMenu(menu); }; + +const iconPath = path.join(__dirname, "assets", "youtube-music-tray.png"); +const example = `Example: "socks5://127.0.0.1:9999"`; +function setProxy(item, win) { + let options = { + title: 'Set Proxy', + label: 'Enter Proxy Address: (leave empty to disable)', + value: config.get("options.proxy") || example, + inputAttrs: { + type: 'text' + }, + type: 'input', + icon: iconPath, + customStylesheet: "dark", + }; + //TODO: custom bar on prompt need testing on macOS + if (!is.macOS()) { + Object.assign(options, { + frame: false, + customScript: path.join(__dirname, "plugins", "in-app-menu", "prompt-custom-titlebar.js"), + enableRemoteModule: true, + height: 200, + width: 450, + }); + } + prompt(options, win) + .then(input => { + if (input !== null && input !== example) { + config.set("options.proxy", input); + item.checked = input !== ""; + } else { //user pressed cancel + item.checked = !item.checked; //reset checkbox + } + }) + .catch(console.error); +} diff --git a/package.json b/package.json index ce144c38..e498c410 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.8.1", "async-mutex": "^0.3.1", "browser-id3-writer": "^4.4.0", + "custom-electron-prompt": "^1.0.2", "custom-electron-titlebar": "^3.2.6", "discord-rpc": "^3.2.0", "downloads-folder": "^3.0.1", diff --git a/plugins/in-app-menu/prompt-custom-titlebar.js b/plugins/in-app-menu/prompt-custom-titlebar.js new file mode 100644 index 00000000..c36ce5f5 --- /dev/null +++ b/plugins/in-app-menu/prompt-custom-titlebar.js @@ -0,0 +1,14 @@ +const customTitlebar = require("custom-electron-titlebar"); + +module.exports = () => { + const bar = new customTitlebar.Titlebar({ + backgroundColor: customTitlebar.Color.fromHex("#050505"), + minimizable: false, + maximizable: false, + menu: null + }); + const mainStyle = document.querySelector("#container").style; + mainStyle.width = "100%"; + mainStyle.position = "fixed"; + mainStyle.border = "unset"; +}; diff --git a/yarn.lock b/yarn.lock index c969527e..7371b7cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2636,6 +2636,13 @@ cssstyle@^2.2.0: dependencies: cssom "~0.3.6" +custom-electron-prompt@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.0.1.tgz#6d11c6e5130a444a9425bd27864777b36f1fef11" + integrity sha512-ldEiZ1t3rBDOb0nfvVpxQOjWJvkkUO3B/sD9IIYr2C/VG9COkc6IJNO2E3rXMPdDDIwejXEQx3CTWp2N2d4moQ== + dependencies: + electron "^11.4.4" + custom-electron-titlebar@^3.2.6: version "3.2.6" resolved "https://registry.yarnpkg.com/custom-electron-titlebar/-/custom-electron-titlebar-3.2.6.tgz#4cd064efa5020954c09732efa8c667a7ee3636e3" @@ -3140,6 +3147,15 @@ electron@^11.2.3: "@types/node" "^12.0.12" extract-zip "^1.0.3" +electron@^11.4.4: + version "11.4.4" + resolved "https://registry.yarnpkg.com/electron/-/electron-11.4.4.tgz#d6c046dedd9e22df5f6408841c3f8ae1a1d59414" + integrity sha512-m52nF85VADCmL9DpzJfgmkvc9fNiGZPYwptv/4fTYrYhAMiO+hmClGMXncCoSAzoULQjl+f+0b9CY4yd6nRFlQ== + dependencies: + "@electron/get" "^1.0.1" + "@types/node" "^12.0.12" + extract-zip "^1.0.3" + elliptic@^6.5.3: version "6.5.4" resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb" From a229ba9c15a8a034726915f7423aefa42ef65b05 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 28 Apr 2021 02:46:13 +0300 Subject: [PATCH 02/26] disable reload of plugins on window created --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a21f45f4..9cdc0ceb 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,7 @@ if (config.get("options.proxy")) { // Adds debug features like hotkeys for triggering dev tools and reload require("electron-debug")({ - showDevTools: false, //disable automatic devTools on new window + showDevTools: false //disable automatic devTools on new window }); // Prevent window being garbage collected @@ -154,7 +154,7 @@ function createMainWindow() { return win; } -app.on("browser-window-created", (event, win) => { +app.once("browser-window-created", (event, win) => { loadPlugins(win); win.webContents.on("did-fail-load", () => { From 964974c142837429d4003fca38c7a8c4fb237121 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Fri, 30 Apr 2021 03:04:38 +0300 Subject: [PATCH 03/26] add keybind changer v1 --- config/defaults.js | 1 + menu.js | 3 - plugins/shortcuts/back.js | 9 ++- plugins/shortcuts/menu.js | 118 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 plugins/shortcuts/menu.js diff --git a/config/defaults.js b/config/defaults.js index fb87e566..ccd6976a 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -30,6 +30,7 @@ const defaultConfig = { // Disabled plugins shortcuts: { enabled: false, + overrideMediaKeys: false, }, downloader: { enabled: false, diff --git a/menu.js b/menu.js index 438fe4cb..a178a575 100644 --- a/menu.js +++ b/menu.js @@ -335,9 +335,6 @@ function setProxy(item, win) { title: 'Set Proxy', label: 'Enter Proxy Address: (leave empty to disable)', value: config.get("options.proxy") || example, - inputAttrs: { - type: 'text' - }, type: 'input', icon: iconPath, customStylesheet: "dark", diff --git a/plugins/shortcuts/back.js b/plugins/shortcuts/back.js index 59ebd737..9a1481d8 100644 --- a/plugins/shortcuts/back.js +++ b/plugins/shortcuts/back.js @@ -19,9 +19,12 @@ function registerShortcuts(win, options) { const songControls = getSongControls(win); const { playPause, next, previous, search } = songControls; - _registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause); - _registerGlobalShortcut(win.webContents, "MediaNextTrack", next); - _registerGlobalShortcut(win.webContents, "MediaPreviousTrack", previous); + if (options.overrideMediaKeys) { + _registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause); + _registerGlobalShortcut(win.webContents, "MediaNextTrack", next); + _registerGlobalShortcut(win.webContents, "MediaPreviousTrack", previous); + } + _registerLocalShortcut(win, "CommandOrControl+F", search); _registerLocalShortcut(win, "CommandOrControl+L", search); diff --git a/plugins/shortcuts/menu.js b/plugins/shortcuts/menu.js new file mode 100644 index 00000000..443e052a --- /dev/null +++ b/plugins/shortcuts/menu.js @@ -0,0 +1,118 @@ +const { setOptions } = require("../../config/plugins"); +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", + type: "checkbox", + checked: true, + click: () => promptKeybind(options, win) + }, + { + label: "Override MediaKeys", + type: "checkbox", + checked: options.overrideMediaKeys, + click: (item) => setOption(options, "overrideMediaKeys", item.checked) + } +]; + +function getGlobalKeybinds(options) { + let playPause, next, previous; + if (options.global) { + for (const global of options.global) { + switch (global.action) { + case "playPause": + playPause = global.shortcut; + break; + case "previous": + previous = global.shortcut; + break; + case "next": + next = global.shortcut; + } + } + } + return { playPause, next, previous }; +} + +function setGlobalKeybinds(options, newShortcuts) { + let didSet = {}; + for (const shortcut in newShortcuts) { + didSet[shortcut] = false; + } + if (!options.global) { + options.global = []; + } + for (let i in options.global) { + switch (options.global[i].action) { + case "playPause": + options.global[i].shortcut = newShortcuts.playPause; + didSet["playPause"] = true; + break; + case "previous": + options.global[i].shortcut = newShortcuts.previous; + didSet["previous"] = true; + break; + case "next": + options.global[i].shortcut = newShortcuts.next; + didSet["next"] = true; + break; + } + } + for (const action in didSet) { + if (!didSet[action]) { + options.global.push({ action: action, shortcut: newShortcuts[action] }); + } + } + options.global.forEach((obj) => console.log(obj)); + setOption(options); +} + +const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || "" } }; +const iconPath = path.join(process.cwd(), "assets", "youtube-music-tray.png"); + +function promptKeybind(options, win) { + let globalKeybinds = getGlobalKeybinds(options); + let promptOptions = { + title: "Global Keybinds", + icon: iconPath, + label: "Choose Global Keybinds for Songs Control:", + type: "keybind", + keybindOptions: [ + kb("Previous", "previous", globalKeybinds.previous), + kb("Play / Pause", "playPause", globalKeybinds.playPause), + kb("Next", "next", globalKeybinds.next), + ], + customStylesheet: "dark", + height: 250 + }; + if (!is.macOS()) { + Object.assign(promptOptions, { + frame: false, + customScript: path.join(process.cwd(), "plugins", "in-app-menu", "prompt-custom-titlebar.js"), + enableRemoteModule: true, + height: 270 + }); + } + prompt(promptOptions, win) + .then(output => { + if (output) { + let toSave = {}; + for (const keybindObj of output) { + toSave[keybindObj.value] = keybindObj.accelerator; + } + setGlobalKeybinds(options, toSave); + } + //else = pressed cancel + }) + .catch(console.error) +} \ No newline at end of file From e456035f295107382dae7b58ac302551146ad41a Mon Sep 17 00:00:00 2001 From: Araxeus Date: Fri, 30 Apr 2021 03:22:36 +0300 Subject: [PATCH 04/26] fix typo --- plugins/shortcuts/menu.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/shortcuts/menu.js b/plugins/shortcuts/menu.js index 443e052a..f7edabb6 100644 --- a/plugins/shortcuts/menu.js +++ b/plugins/shortcuts/menu.js @@ -13,8 +13,6 @@ function setOption(options, key = null, newValue = null) { module.exports = (win, options) => [ { label: "Set Global Song Controls", - type: "checkbox", - checked: true, click: () => promptKeybind(options, win) }, { @@ -25,6 +23,7 @@ module.exports = (win, options) => [ } ]; +//will not be needed if globalKeybinds will be an object function getGlobalKeybinds(options) { let playPause, next, previous; if (options.global) { @@ -44,6 +43,7 @@ function getGlobalKeybinds(options) { return { playPause, next, previous }; } +//will not be needed if globalKeybinds will be an object function setGlobalKeybinds(options, newShortcuts) { let didSet = {}; for (const shortcut in newShortcuts) { From 49e51de27424b108e0375f2eb13acd049f244702 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Fri, 30 Apr 2021 04:13:03 +0300 Subject: [PATCH 05/26] update shortcuts config --- plugins/shortcuts/back.js | 63 ++++++++++++++++++++++++++--------- plugins/shortcuts/menu.js | 69 ++++----------------------------------- 2 files changed, 55 insertions(+), 77 deletions(-) diff --git a/plugins/shortcuts/back.js b/plugins/shortcuts/back.js index 9a1481d8..a187ded8 100644 --- a/plugins/shortcuts/back.js +++ b/plugins/shortcuts/back.js @@ -1,5 +1,6 @@ const { globalShortcut } = require("electron"); const electronLocalshortcut = require("electron-localshortcut"); +const { setOptions } = require("../../config/plugins"); const getSongControls = require("../../providers/song-controls"); @@ -19,6 +20,8 @@ function registerShortcuts(win, options) { const songControls = getSongControls(win); const { playPause, next, previous, search } = songControls; + updateOptions(options); + if (options.overrideMediaKeys) { _registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause); _registerGlobalShortcut(win.webContents, "MediaNextTrack", next); @@ -29,24 +32,54 @@ function registerShortcuts(win, options) { _registerLocalShortcut(win, "CommandOrControl+L", search); const { global, local } = options; - (global || []).forEach(({ shortcut, action }) => { - console.debug("Registering global shortcut", shortcut, ":", action); - if (!action || !songControls[action]) { - console.warn("Invalid action", action); - return; - } - _registerGlobalShortcut(win.webContents, shortcut, songControls[action]); - }); - (local || []).forEach(({ shortcut, action }) => { - console.debug("Registering local shortcut", shortcut, ":", action); - if (!action || !songControls[action]) { - console.warn("Invalid action", action); - return; + if (global) { + for (const action in global) { + if (!global[action]) { + return; //accelerator is empty + } + console.debug("Registering global shortcut", global[action], ":", action); + if (!songControls[action]) { + console.warn("Invalid action", action); + return; + } + _registerGlobalShortcut(win.webContents, global[action], songControls[action]); } + } - _registerLocalShortcut(win, shortcut, songControls[action]); - }); + if (local) { + for (const action in local) { + if (!local[action]) { + return; //accelerator is empty + } + console.debug("Registering local shortcut", local[action], ":", action); + if (!songControls[action]) { + console.warn("Invalid action", action); + return; + } + _registerLocalShortcut(win, local[action], songControls[action]); + } + } +} + +/** Update options to new format */ +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; + } + } + options[optionType] = updatedOptions; + updated = true; + } + } + if (updated) { + setOptions("shortcuts", options); + } } module.exports = registerShortcuts; diff --git a/plugins/shortcuts/menu.js b/plugins/shortcuts/menu.js index f7edabb6..2b5622c2 100644 --- a/plugins/shortcuts/menu.js +++ b/plugins/shortcuts/menu.js @@ -1,5 +1,6 @@ const { setOptions } = require("../../config/plugins"); const prompt = require("custom-electron-prompt"); + const path = require("path"); const is = require("electron-is"); @@ -23,74 +24,19 @@ module.exports = (win, options) => [ } ]; -//will not be needed if globalKeybinds will be an object -function getGlobalKeybinds(options) { - let playPause, next, previous; - if (options.global) { - for (const global of options.global) { - switch (global.action) { - case "playPause": - playPause = global.shortcut; - break; - case "previous": - previous = global.shortcut; - break; - case "next": - next = global.shortcut; - } - } - } - return { playPause, next, previous }; -} - -//will not be needed if globalKeybinds will be an object -function setGlobalKeybinds(options, newShortcuts) { - let didSet = {}; - for (const shortcut in newShortcuts) { - didSet[shortcut] = false; - } - if (!options.global) { - options.global = []; - } - for (let i in options.global) { - switch (options.global[i].action) { - case "playPause": - options.global[i].shortcut = newShortcuts.playPause; - didSet["playPause"] = true; - break; - case "previous": - options.global[i].shortcut = newShortcuts.previous; - didSet["previous"] = true; - break; - case "next": - options.global[i].shortcut = newShortcuts.next; - didSet["next"] = true; - break; - } - } - for (const action in didSet) { - if (!didSet[action]) { - options.global.push({ action: action, shortcut: newShortcuts[action] }); - } - } - options.global.forEach((obj) => console.log(obj)); - setOption(options); -} - -const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || "" } }; +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) { - let globalKeybinds = getGlobalKeybinds(options); let promptOptions = { title: "Global Keybinds", icon: iconPath, label: "Choose Global Keybinds for Songs Control:", type: "keybind", keybindOptions: [ - kb("Previous", "previous", globalKeybinds.previous), - kb("Play / Pause", "playPause", globalKeybinds.playPause), - kb("Next", "next", globalKeybinds.next), + kb("Previous", "previous", options.global?.previous), + kb("Play / Pause", "playPause", options.global?.playPause), + kb("Next", "next", options.global?.next), ], customStylesheet: "dark", height: 250 @@ -106,11 +52,10 @@ function promptKeybind(options, win) { prompt(promptOptions, win) .then(output => { if (output) { - let toSave = {}; for (const keybindObj of output) { - toSave[keybindObj.value] = keybindObj.accelerator; + options.global[keybindObj.value] = keybindObj.accelerator; } - setGlobalKeybinds(options, toSave); + setOption(options); } //else = pressed cancel }) From 54cbe3faa473710a11283facd529f42d587d1848 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Fri, 30 Apr 2021 04:29:01 +0300 Subject: [PATCH 06/26] lint --- plugins/shortcuts/back.js | 22 +++++++++++++------- plugins/shortcuts/menu.js | 44 +++++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 28 deletions(-) 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); +} From d0d4ada7c22d6b8cb17157018957b2324274c4ca Mon Sep 17 00:00:00 2001 From: Araxeus Date: Fri, 30 Apr 2021 04:33:23 +0300 Subject: [PATCH 07/26] restore original menu lint --- menu.js | 165 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/menu.js b/menu.js index a178a575..dcbc9db5 100644 --- a/menu.js +++ b/menu.js @@ -104,38 +104,30 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ }, ...(is.windows() || is.linux() ? [ - { - label: "Hide menu", - type: "checkbox", - checked: config.get("options.hideMenu"), - click: (item) => { - config.set("options.hideMenu", item.checked); + { + label: "Hide menu", + type: "checkbox", + checked: config.get("options.hideMenu"), + click: (item) => { + config.set("options.hideMenu", item.checked); + }, }, - }, - ] + ] : []), ...(is.windows() || is.macOS() ? // Only works on Win/Mac - // https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows - [ - { - label: "Start at login", - type: "checkbox", - checked: config.get("options.startAtLogin"), - click: (item) => { - config.set("options.startAtLogin", item.checked); + // https://www.electronjs.org/docs/api/app#appsetloginitemsettingssettings-macos-windows + [ + { + label: "Start at login", + type: "checkbox", + checked: config.get("options.startAtLogin"), + click: (item) => { + config.set("options.startAtLogin", item.checked); + }, }, - }, - ] + ] : []), - { - label: "Proxy", - type: "checkbox", - checked: !!config.get("options.proxy"), - click: (item) => { - setProxy(item, win); - } - }, { label: "Tray", submenu: [ @@ -180,6 +172,15 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ ], }, { type: "separator" }, + // Should be put in Advanced Options submenu + { + label: "Proxy", + type: "checkbox", + checked: !!config.get("options.proxy"), + click: (item) => { + setProxy(item, win); + } + }, { label: "Toggle DevTools", // Cannot use "toggleDevTools" role in MacOS @@ -203,56 +204,56 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ }, ...(!isTray ? [ - { - label: "View", - submenu: withRoles - ? [ - { role: "reload" }, - { role: "forceReload" }, - { type: "separator" }, - { role: "zoomIn" }, - { role: "zoomOut" }, - { role: "resetZoom" }, - ] - : [ - { - label: "Reload", - click: () => { - win.webContents.reload(); - }, - }, - { - label: "Force Reload", - click: () => { - win.webContents.reloadIgnoringCache(); - }, - }, - { type: "separator" }, - { - label: "Zoom In", - click: () => { - win.webContents.setZoomLevel( - win.webContents.getZoomLevel() + 1 - ); - }, - }, - { - label: "Zoom Out", - click: () => { - win.webContents.setZoomLevel( - win.webContents.getZoomLevel() - 1 - ); - }, - }, - { - label: "Reset Zoom", - click: () => { - win.webContents.setZoomLevel(0); - }, - }, - ], - }, - ] + { + label: "View", + submenu: withRoles + ? [ + { role: "reload" }, + { role: "forceReload" }, + { type: "separator" }, + { role: "zoomIn" }, + { role: "zoomOut" }, + { role: "resetZoom" }, + ] + : [ + { + label: "Reload", + click: () => { + win.webContents.reload(); + }, + }, + { + label: "Force Reload", + click: () => { + win.webContents.reloadIgnoringCache(); + }, + }, + { type: "separator" }, + { + label: "Zoom In", + click: () => { + win.webContents.setZoomLevel( + win.webContents.getZoomLevel() + 1 + ); + }, + }, + { + label: "Zoom Out", + click: () => { + win.webContents.setZoomLevel( + win.webContents.getZoomLevel() - 1 + ); + }, + }, + { + label: "Reset Zoom", + click: () => { + win.webContents.setZoomLevel(0); + }, + }, + ], + }, + ] : []), { label: "Navigation", @@ -282,13 +283,13 @@ const mainMenuTemplate = (win, withRoles = true, isTray = false) => [ }, ...(!isTray ? [ - { - label: "Quit App", - click: () => { - app.quit(); + { + label: "Quit App", + click: () => { + app.quit(); + }, }, - }, - ] + ] : []), ], }, From ec981ac547334db5f970f8edc70140845a44b725 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Fri, 30 Apr 2021 05:09:49 +0300 Subject: [PATCH 08/26] refactor registerAllShortcuts --- plugins/shortcuts/back.js | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/plugins/shortcuts/back.js b/plugins/shortcuts/back.js index f4f73e0b..a3452351 100644 --- a/plugins/shortcuts/back.js +++ b/plugins/shortcuts/back.js @@ -32,35 +32,26 @@ function registerShortcuts(win, options) { _registerLocalShortcut(win, "CommandOrControl+L", search); const { global, local } = options; + const shortcutOptions = {global, local}; - if (global) { - for (const action in global) { - 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]); - } + for (const optionType in shortcutOptions) { + registerAllShortcuts(shortcutOptions[optionType], optionType); } - if (local) { - for (const action in local) { - if (!local[action]) { + function registerAllShortcuts(container, type) { + for (const action in container) { + if (!container[action]) { continue; //accelerator is empty } - - console.debug("Registering local shortcut", local[action], ":", action); + + 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]); } } From 79acf6c0ba2770888d25f1932f437b40ba9f7c02 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 5 May 2021 00:42:42 +0300 Subject: [PATCH 09/26] Volume Steps Prompt Precise-Volume Global Shortcuts Prompt --- menu.js | 17 +++--- plugins/precise-volume/front.js | 4 +- plugins/precise-volume/menu.js | 96 ++++++++++++++++++++++++++++++++- plugins/shortcuts/menu.js | 2 +- 4 files changed, 104 insertions(+), 15 deletions(-) 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; } From 22c5ea50002686c3b72a4d6f4a8c76494408c242 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 5 May 2021 01:25:45 +0300 Subject: [PATCH 10/26] 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) From 34a4e6be3dec0923b483ad8a5eecf7bc22bafdef Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 5 May 2021 01:47:53 +0300 Subject: [PATCH 11/26] proxy url check --- menu.js | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/menu.js b/menu.js index 776a52eb..afe8b93d 100644 --- a/menu.js +++ b/menu.js @@ -318,6 +318,9 @@ function setProxy(item, win) { label: 'Enter Proxy Address: (leave empty to disable)', value: config.get("options.proxy") || example, type: 'input', + inputAttrs: { + type: 'url' + }, icon: iconPath, customStylesheet: "dark", }; diff --git a/package.json b/package.json index 2092f6f5..bb793dde 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.9.0", "async-mutex": "^0.3.1", "browser-id3-writer": "^4.4.0", - "custom-electron-prompt": "^1.0.2", + "custom-electron-prompt": "^1.0.3", "custom-electron-titlebar": "^3.2.6", "discord-rpc": "^3.2.0", "electron-debug": "^3.2.0", From b97a86f6dcac140a5e64a0912e2f4ae72a8a5d86 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 5 May 2021 01:55:25 +0300 Subject: [PATCH 12/26] Update yarn.lock --- yarn.lock | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/yarn.lock b/yarn.lock index c1857d13..845e34ea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2849,10 +2849,10 @@ cssstyle@^2.2.0: dependencies: cssom "~0.3.6" -custom-electron-prompt@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.0.1.tgz#6d11c6e5130a444a9425bd27864777b36f1fef11" - integrity sha512-ldEiZ1t3rBDOb0nfvVpxQOjWJvkkUO3B/sD9IIYr2C/VG9COkc6IJNO2E3rXMPdDDIwejXEQx3CTWp2N2d4moQ== +custom-electron-prompt@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.0.3.tgz#fc1f8313917d07d137fd80d060f9ca96fa953037" + integrity sha512-lEI/KH7qBn8sw7jkw4kAuE24rSfmjxSTdVKlLG2EKfUCvYKyDSLAOS1z8M6PEGAeAmHQxp4lA8kiA2BPFjpANA== dependencies: electron "^11.4.4" @@ -3381,15 +3381,6 @@ electron@^11.4.4: "@types/node" "^12.0.12" extract-zip "^1.0.3" -electron@^11.4.4: - version "11.4.4" - resolved "https://registry.yarnpkg.com/electron/-/electron-11.4.4.tgz#d6c046dedd9e22df5f6408841c3f8ae1a1d59414" - integrity sha512-m52nF85VADCmL9DpzJfgmkvc9fNiGZPYwptv/4fTYrYhAMiO+hmClGMXncCoSAzoULQjl+f+0b9CY4yd6nRFlQ== - dependencies: - "@electron/get" "^1.0.1" - "@types/node" "^12.0.12" - extract-zip "^1.0.3" - elliptic@^6.5.3: version "6.5.4" resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb" From db8d946178d058dd700b3a4c4a704808061eb639 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 5 May 2021 02:08:24 +0300 Subject: [PATCH 13/26] fix electron dependency --- package.json | 2 +- yarn.lock | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index bb793dde..73a52902 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.9.0", "async-mutex": "^0.3.1", "browser-id3-writer": "^4.4.0", - "custom-electron-prompt": "^1.0.3", + "custom-electron-prompt": "^1.0.4", "custom-electron-titlebar": "^3.2.6", "discord-rpc": "^3.2.0", "electron-debug": "^3.2.0", diff --git a/yarn.lock b/yarn.lock index 845e34ea..ae0a453b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2849,12 +2849,10 @@ cssstyle@^2.2.0: dependencies: cssom "~0.3.6" -custom-electron-prompt@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.0.3.tgz#fc1f8313917d07d137fd80d060f9ca96fa953037" - integrity sha512-lEI/KH7qBn8sw7jkw4kAuE24rSfmjxSTdVKlLG2EKfUCvYKyDSLAOS1z8M6PEGAeAmHQxp4lA8kiA2BPFjpANA== - dependencies: - electron "^11.4.4" +custom-electron-prompt@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.0.4.tgz#b729cb10687b8fa9029e82d68652fd94e59b1918" + integrity sha512-Yj73jce2Sx7+ngnqGvth0aBuD6vx/QLrkziLJ5Iznh+n3qRrWnO1Qz+dJCdThCvobO5VUAbTXbHebtLuKj+7qw== custom-electron-titlebar@^3.2.6: version "3.2.6" From 98c00f7a60ccbf397e09a34f23a3ce75fa7d0875 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 5 May 2021 02:30:08 +0300 Subject: [PATCH 14/26] format proxy example --- menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/menu.js b/menu.js index afe8b93d..15b99bf9 100644 --- a/menu.js +++ b/menu.js @@ -311,7 +311,7 @@ module.exports.setApplicationMenu = (win) => { }; const iconPath = path.join(__dirname, "assets", "youtube-music-tray.png"); -const example = `Example: "socks5://127.0.0.1:9999"`; +const example = "Example: 'socks5://127.0.0.1:9999'"; function setProxy(item, win) { let options = { title: 'Set Proxy', From 5cee331abe80a0a2c0212f123d5bced5922092a8 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 5 May 2021 02:53:05 +0300 Subject: [PATCH 15/26] update prompt version and lint --- menu.js | 8 +++--- package.json | 2 +- plugins/precise-volume/menu.js | 51 +++++++++++++++++----------------- yarn.lock | 8 +++--- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/menu.js b/menu.js index 15b99bf9..bca09e7b 100644 --- a/menu.js +++ b/menu.js @@ -335,10 +335,10 @@ function setProxy(item, win) { }); } prompt(options, win) - .then(input => { - if (input !== null && input !== example) { - config.set("options.proxy", input); - item.checked = input !== ""; + .then(output => { + if (output !== null && output !== example) { + config.set("options.proxy", output); + item.checked = output !== ""; } else { //user pressed cancel item.checked = !item.checked; //reset checkbox } diff --git a/package.json b/package.json index 73a52902..931c3e8a 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.9.0", "async-mutex": "^0.3.1", "browser-id3-writer": "^4.4.0", - "custom-electron-prompt": "^1.0.4", + "custom-electron-prompt": "^1.0.5", "custom-electron-titlebar": "^3.2.6", "discord-rpc": "^3.2.0", "electron-debug": "^3.2.0", diff --git a/plugins/precise-volume/menu.js b/plugins/precise-volume/menu.js index 1919052f..bfe73265 100644 --- a/plugins/precise-volume/menu.js +++ b/plugins/precise-volume/menu.js @@ -37,25 +37,6 @@ const customTitlebarPath = path.join(app.getAppPath(), "plugins", "in-app-menu", // Helper function for globalShortcuts prompt const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined }; }; -function setupPromptOptions(options) { - // TODO Custom titlebar needs testing on macOS - if (is.macOS()) { - Object.assign(options, { - customStylesheet: "dark", - 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) { const promptOptions = { title: "Volume Steps", @@ -67,12 +48,13 @@ function promptVolumeSteps(win, options) { 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); + prompt(promptOptions, win) + .then(output => { + if (output || output === 0) { // 0 is somehow valid + options.steps = output; + setOptions("precise-volume", options); + } + }).catch(console.error); } function promptGlobalShortcuts(win, options, item) { @@ -106,3 +88,22 @@ function promptGlobalShortcuts(win, options, item) { }) .catch(console.error); } + +function setupPromptOptions(options) { + // TODO Custom titlebar needs testing on macOS + if (is.macOS()) { + Object.assign(options, { + customStylesheet: "dark", + icon: iconPath + }); + } else { + Object.assign(options, { + customStylesheet: "dark", + icon: iconPath, + // The following are used for custom titlebar + frame: false, + customScript: customTitlebarPath, + enableRemoteModule: true + }); + } +} diff --git a/yarn.lock b/yarn.lock index ae0a453b..e513ddc4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2849,10 +2849,10 @@ cssstyle@^2.2.0: dependencies: cssom "~0.3.6" -custom-electron-prompt@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.0.4.tgz#b729cb10687b8fa9029e82d68652fd94e59b1918" - integrity sha512-Yj73jce2Sx7+ngnqGvth0aBuD6vx/QLrkziLJ5Iznh+n3qRrWnO1Qz+dJCdThCvobO5VUAbTXbHebtLuKj+7qw== +custom-electron-prompt@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.0.5.tgz#2b72ac108f3038bab3757345f8faee3cd91b1f43" + integrity sha512-BEAlGVf7obLmAwSO/rgnWvLQxtYaPEXSu79XySx0qRuR7WEYdQgJdBpycQF+3ivjv8oRe5f4pjxaxu657fs+mg== custom-electron-titlebar@^3.2.6: version "3.2.6" From 834f8674a3dc1617f233e0af5dffd3c682da312b Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 5 May 2021 03:27:47 +0300 Subject: [PATCH 16/26] massive prompt speed boost with v1.1.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 931c3e8a..acddcb90 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.9.0", "async-mutex": "^0.3.1", "browser-id3-writer": "^4.4.0", - "custom-electron-prompt": "^1.0.5", + "custom-electron-prompt": "^1.1.0", "custom-electron-titlebar": "^3.2.6", "discord-rpc": "^3.2.0", "electron-debug": "^3.2.0", diff --git a/yarn.lock b/yarn.lock index e513ddc4..8ba6b788 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2849,10 +2849,10 @@ cssstyle@^2.2.0: dependencies: cssom "~0.3.6" -custom-electron-prompt@^1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.0.5.tgz#2b72ac108f3038bab3757345f8faee3cd91b1f43" - integrity sha512-BEAlGVf7obLmAwSO/rgnWvLQxtYaPEXSu79XySx0qRuR7WEYdQgJdBpycQF+3ivjv8oRe5f4pjxaxu657fs+mg== +custom-electron-prompt@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/custom-electron-prompt/-/custom-electron-prompt-1.1.0.tgz#611b790047c91f6b532c7861355a0e1f9a81aef2" + integrity sha512-YZYmwZnMOdoWROUlJ+rEMHYsp4XJNNqLj6sZnx5aKBJ8cprEjKP4L5wfo6U+yyX/L9fxVOtvYD0Mp8ki5I9Kow== custom-electron-titlebar@^3.2.6: version "3.2.6" From 6b147b098a7f31695e1d6b8a6f73996f1fd6f49f Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 5 May 2021 03:48:07 +0300 Subject: [PATCH 17/26] fix prompt width --- menu.js | 5 ++--- plugins/precise-volume/menu.js | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/menu.js b/menu.js index bca09e7b..fcd18a7c 100644 --- a/menu.js +++ b/menu.js @@ -323,15 +323,14 @@ function setProxy(item, win) { }, icon: iconPath, customStylesheet: "dark", + width: 450, }; //TODO: custom bar on prompt need testing on macOS if (!is.macOS()) { Object.assign(options, { frame: false, customScript: path.join(__dirname, "plugins", "in-app-menu", "prompt-custom-titlebar.js"), - enableRemoteModule: true, - height: 200, - width: 450, + enableRemoteModule: true, }); } prompt(options, win) diff --git a/plugins/precise-volume/menu.js b/plugins/precise-volume/menu.js index bfe73265..c78c82df 100644 --- a/plugins/precise-volume/menu.js +++ b/plugins/precise-volume/menu.js @@ -43,7 +43,8 @@ function promptVolumeSteps(win, options) { 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 }, + width: 380 }; setupPromptOptions(promptOptions); @@ -65,8 +66,7 @@ function promptGlobalShortcuts(win, options, item) { keybindOptions: [ kb("Increase Volume", "volumeUp", options.globalShortcuts?.volumeUp), kb("Decrease Volume", "volumeDown", options.globalShortcuts?.volumeDown) - ], - height: 230 + ] }; setupPromptOptions(promptOptions); From f910593fb648171956f62222eb47cba5f7a458a4 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 10 May 2021 00:40:02 +0300 Subject: [PATCH 18/26] use spread operator + async await --- menu.js | 25 ++++++-------- plugins/precise-volume/menu.js | 63 +++++++++++++++------------------- plugins/shortcuts/menu.js | 29 +++++++--------- 3 files changed, 52 insertions(+), 65 deletions(-) diff --git a/menu.js b/menu.js index fcd18a7c..44cb3716 100644 --- a/menu.js +++ b/menu.js @@ -312,7 +312,7 @@ module.exports.setApplicationMenu = (win) => { const iconPath = path.join(__dirname, "assets", "youtube-music-tray.png"); const example = "Example: 'socks5://127.0.0.1:9999'"; -function setProxy(item, win) { +async function setProxy(item, win) { let options = { title: 'Set Proxy', label: 'Enter Proxy Address: (leave empty to disable)', @@ -325,22 +325,19 @@ function setProxy(item, win) { customStylesheet: "dark", width: 450, }; - //TODO: custom bar on prompt need testing on macOS if (!is.macOS()) { - Object.assign(options, { + options = { + ...options, frame: false, customScript: path.join(__dirname, "plugins", "in-app-menu", "prompt-custom-titlebar.js"), enableRemoteModule: true, - }); + }; } - prompt(options, win) - .then(output => { - if (output !== null && output !== example) { - config.set("options.proxy", output); - item.checked = output !== ""; - } else { //user pressed cancel - item.checked = !item.checked; //reset checkbox - } - }) - .catch(console.error); + const output = await prompt(options, win); + if (output !== null && output !== example) { + config.set("options.proxy", output); + item.checked = output !== ""; + } else { //user pressed cancel + item.checked = !item.checked; //reset checkbox + } } diff --git a/plugins/precise-volume/menu.js b/plugins/precise-volume/menu.js index c78c82df..495315f5 100644 --- a/plugins/precise-volume/menu.js +++ b/plugins/precise-volume/menu.js @@ -37,29 +37,25 @@ const customTitlebarPath = path.join(app.getAppPath(), "plugins", "in-app-menu", // Helper function for globalShortcuts prompt const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined }; }; -function promptVolumeSteps(win, options) { - const promptOptions = { +async function promptVolumeSteps(win, options) { + const promptOptions = setupPromptOptions({ title: "Volume Steps", label: "Choose Volume Increase/Decrease Steps", value: options.steps || 1, type: "counter", counterOptions: { minimum: 0, maximum: 100, multiFire: true }, width: 380 - }; + }); - setupPromptOptions(promptOptions); - - prompt(promptOptions, win) - .then(output => { - if (output || output === 0) { // 0 is somehow valid - options.steps = output; - setOptions("precise-volume", options); - } - }).catch(console.error); + const output = await prompt(promptOptions, win) + if (output || output === 0) { // 0 is somewhat valid + options.steps = output; + setOptions("precise-volume", options); + } } -function promptGlobalShortcuts(win, options, item) { - const promptOptions = { +async function promptGlobalShortcuts(win, options, item) { + const promptOptions = setupPromptOptions({ title: "Global Volume Keybinds", label: "Choose Global Volume Keybinds:", type: "keybind", @@ -67,43 +63,40 @@ function promptGlobalShortcuts(win, options, item) { kb("Increase Volume", "volumeUp", options.globalShortcuts?.volumeUp), kb("Decrease Volume", "volumeDown", options.globalShortcuts?.volumeDown) ] - }; + }); - setupPromptOptions(promptOptions); + const output = await prompt(promptOptions, win) + if (output) { + for (const keybindObject of output) { + options.globalShortcuts[keybindObject.value] = keybindObject.accelerator; + } - prompt(promptOptions, win) - .then(output => { - if (output) { - for (const keybindObject of output) { - options.globalShortcuts[keybindObject.value] = keybindObject.accelerator; - } + setOptions("precise-volume", options); - 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); + item.checked = !!options.globalShortcuts.volumeUp || !!options.globalShortcuts.volumeDown; + } else { + // Reset checkbox if prompt was canceled + item.checked = !item.checked; + } } function setupPromptOptions(options) { // TODO Custom titlebar needs testing on macOS if (is.macOS()) { - Object.assign(options, { + return { + ...options, customStylesheet: "dark", icon: iconPath - }); + }; } else { - Object.assign(options, { + return { + ...options, customStylesheet: "dark", icon: iconPath, // The following are used for custom titlebar frame: false, customScript: customTitlebarPath, enableRemoteModule: true - }); + }; } } diff --git a/plugins/shortcuts/menu.js b/plugins/shortcuts/menu.js index 12506a86..bf366182 100644 --- a/plugins/shortcuts/menu.js +++ b/plugins/shortcuts/menu.js @@ -29,8 +29,8 @@ 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) { - const promptOptions = { +async function promptKeybind(options, win) { + let promptOptions = { title: "Global Keybinds", icon: iconPath, label: "Choose Global Keybinds for Songs Control:", @@ -45,24 +45,21 @@ function promptKeybind(options, win) { }; if (!is.macOS()) { - Object.assign(promptOptions, { + promptOptions = { + ...promptOptions, frame: false, customScript: path.join(process.cwd(), "plugins", "in-app-menu", "prompt-custom-titlebar.js"), enableRemoteModule: true, height: 270 - }); + }; } - prompt(promptOptions, win) - .then(output => { - if (output) { - for (const keybindObject of output) { - options.global[keybindObject.value] = keybindObject.accelerator; - } - - setOption(options); - } - // else -> pressed cancel - }) - .catch(console.error); + const output = await prompt(promptOptions, win); + if (output) { + for (const keybindObject of output) { + options.global[keybindObject.value] = keybindObject.accelerator; + } + setOption(options); + } + // else -> pressed cancel } From 36317c953af7050864cd559a8341b4f7a7b5407c Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 10 May 2021 01:43:50 +0300 Subject: [PATCH 19/26] globalize promptOptions --- menu.js | 30 +++++-------- plugins/precise-volume/menu.js | 44 +++++-------------- plugins/shortcuts/menu.js | 25 +++-------- .../prompt-custom-titlebar.js | 0 providers/prompt-options.js | 19 ++++++++ 5 files changed, 45 insertions(+), 73 deletions(-) rename {plugins/in-app-menu => providers}/prompt-custom-titlebar.js (100%) create mode 100644 providers/prompt-options.js diff --git a/menu.js b/menu.js index 44cb3716..cdcea4cd 100644 --- a/menu.js +++ b/menu.js @@ -6,7 +6,9 @@ const is = require("electron-is"); const { getAllPlugins } = require("./plugins/utils"); const config = require("./config"); + const prompt = require("custom-electron-prompt"); +const promptOptions = require("./providers/prompt-options"); const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu = false) => ({ label: label || plugin, @@ -310,10 +312,9 @@ module.exports.setApplicationMenu = (win) => { Menu.setApplicationMenu(menu); }; -const iconPath = path.join(__dirname, "assets", "youtube-music-tray.png"); const example = "Example: 'socks5://127.0.0.1:9999'"; async function setProxy(item, win) { - let options = { + const output = await prompt({ title: 'Set Proxy', label: 'Enter Proxy Address: (leave empty to disable)', value: config.get("options.proxy") || example, @@ -321,23 +322,14 @@ async function setProxy(item, win) { inputAttrs: { type: 'url' }, - icon: iconPath, - customStylesheet: "dark", width: 450, - }; - if (!is.macOS()) { - options = { - ...options, - frame: false, - customScript: path.join(__dirname, "plugins", "in-app-menu", "prompt-custom-titlebar.js"), - enableRemoteModule: true, - }; + ...promptOptions() + }, win); + + if (output !== null && output !== example) { + config.set("options.proxy", output); + item.checked = output !== ""; + } else { //user pressed cancel + item.checked = !item.checked; //reset checkbox } - const output = await prompt(options, win); - if (output !== null && output !== example) { - config.set("options.proxy", output); - item.checked = output !== ""; - } else { //user pressed cancel - item.checked = !item.checked; //reset checkbox - } } diff --git a/plugins/precise-volume/menu.js b/plugins/precise-volume/menu.js index 495315f5..c605d75e 100644 --- a/plugins/precise-volume/menu.js +++ b/plugins/precise-volume/menu.js @@ -1,9 +1,8 @@ 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"); +const promptOptions = require("../../providers/prompt-options"); + module.exports = (win, options) => [ { @@ -32,22 +31,20 @@ module.exports = (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 }; }; async function promptVolumeSteps(win, options) { - const promptOptions = setupPromptOptions({ + const output = await prompt({ title: "Volume Steps", label: "Choose Volume Increase/Decrease Steps", value: options.steps || 1, type: "counter", counterOptions: { minimum: 0, maximum: 100, multiFire: true }, - width: 380 - }); + width: 380, + ...promptOptions() + }, win) - const output = await prompt(promptOptions, win) if (output || output === 0) { // 0 is somewhat valid options.steps = output; setOptions("precise-volume", options); @@ -55,17 +52,17 @@ async function promptVolumeSteps(win, options) { } async function promptGlobalShortcuts(win, options, item) { - const promptOptions = setupPromptOptions({ + const output = await prompt({ title: "Global Volume Keybinds", label: "Choose Global Volume Keybinds:", type: "keybind", keybindOptions: [ kb("Increase Volume", "volumeUp", options.globalShortcuts?.volumeUp), kb("Decrease Volume", "volumeDown", options.globalShortcuts?.volumeDown) - ] - }); + ], + ...promptOptions() + }, win) - const output = await prompt(promptOptions, win) if (output) { for (const keybindObject of output) { options.globalShortcuts[keybindObject.value] = keybindObject.accelerator; @@ -79,24 +76,3 @@ async function promptGlobalShortcuts(win, options, item) { item.checked = !item.checked; } } - -function setupPromptOptions(options) { - // TODO Custom titlebar needs testing on macOS - if (is.macOS()) { - return { - ...options, - customStylesheet: "dark", - icon: iconPath - }; - } else { - return { - ...options, - customStylesheet: "dark", - icon: iconPath, - // The following are used for custom titlebar - frame: false, - customScript: customTitlebarPath, - enableRemoteModule: true - }; - } -} diff --git a/plugins/shortcuts/menu.js b/plugins/shortcuts/menu.js index bf366182..cdb395f6 100644 --- a/plugins/shortcuts/menu.js +++ b/plugins/shortcuts/menu.js @@ -1,8 +1,6 @@ const { setOptions } = require("../../config/plugins"); const prompt = require("custom-electron-prompt"); - -const path = require("path"); -const is = require("electron-is"); +const promptOptions = require("../../providers/prompt-options"); module.exports = (win, options) => [ { @@ -25,14 +23,12 @@ function setOption(options, key = null, newValue = null) { setOptions("shortcuts", options); } -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_ }; }; async function promptKeybind(options, win) { - let promptOptions = { + const output = await prompt({ title: "Global Keybinds", - icon: iconPath, label: "Choose Global Keybinds for Songs Control:", type: "keybind", keybindOptions: [ // If default=undefined then no default is used @@ -40,21 +36,10 @@ async function promptKeybind(options, win) { kb("Play / Pause", "playPause", options.global?.playPause), kb("Next", "next", options.global?.next) ], - customStylesheet: "dark", - height: 250 - }; + height: 270, + ...promptOptions() + }, win); - if (!is.macOS()) { - promptOptions = { - ...promptOptions, - frame: false, - customScript: path.join(process.cwd(), "plugins", "in-app-menu", "prompt-custom-titlebar.js"), - enableRemoteModule: true, - height: 270 - }; - } - - const output = await prompt(promptOptions, win); if (output) { for (const keybindObject of output) { options.global[keybindObject.value] = keybindObject.accelerator; diff --git a/plugins/in-app-menu/prompt-custom-titlebar.js b/providers/prompt-custom-titlebar.js similarity index 100% rename from plugins/in-app-menu/prompt-custom-titlebar.js rename to providers/prompt-custom-titlebar.js diff --git a/providers/prompt-options.js b/providers/prompt-options.js new file mode 100644 index 00000000..1029a7b3 --- /dev/null +++ b/providers/prompt-options.js @@ -0,0 +1,19 @@ +const path = require("path"); +const is = require("electron-is"); + +const iconPath = path.resolve(__dirname, "../assets/youtube-music-tray.png"); +const customTitlebarPath = path.join(__dirname, "prompt-custom-titlebar.js"); + +const promptOptions = is.macOS() ? { + customStylesheet: "dark", + icon: iconPath +} : { + customStylesheet: "dark", + icon: iconPath, + // The following are used for custom titlebar + frame: false, + customScript: customTitlebarPath, + enableRemoteModule: true +} + +module.exports = () => promptOptions; \ No newline at end of file From 0eca30367f3db2789a3a1d5de68be34a483a26ef Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 10 May 2021 01:56:41 +0300 Subject: [PATCH 20/26] lint --- providers/prompt-custom-titlebar.js | 2 +- providers/prompt-options.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/providers/prompt-custom-titlebar.js b/providers/prompt-custom-titlebar.js index c36ce5f5..affa9206 100644 --- a/providers/prompt-custom-titlebar.js +++ b/providers/prompt-custom-titlebar.js @@ -1,7 +1,7 @@ const customTitlebar = require("custom-electron-titlebar"); module.exports = () => { - const bar = new customTitlebar.Titlebar({ + new customTitlebar.Titlebar({ backgroundColor: customTitlebar.Color.fromHex("#050505"), minimizable: false, maximizable: false, diff --git a/providers/prompt-options.js b/providers/prompt-options.js index 1029a7b3..79cbc36f 100644 --- a/providers/prompt-options.js +++ b/providers/prompt-options.js @@ -7,13 +7,13 @@ const customTitlebarPath = path.join(__dirname, "prompt-custom-titlebar.js"); const promptOptions = is.macOS() ? { customStylesheet: "dark", icon: iconPath -} : { +} : { customStylesheet: "dark", icon: iconPath, // The following are used for custom titlebar frame: false, customScript: customTitlebarPath, enableRemoteModule: true -} +}; -module.exports = () => promptOptions; \ No newline at end of file +module.exports = () => promptOptions; From 580caeffb93fa05baa3bd8d1db6b5beaf7752ea5 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 10 May 2021 16:53:57 +0300 Subject: [PATCH 21/26] destructure keybind output --- plugins/precise-volume/menu.js | 4 ++-- plugins/shortcuts/menu.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/precise-volume/menu.js b/plugins/precise-volume/menu.js index c605d75e..06ee84b9 100644 --- a/plugins/precise-volume/menu.js +++ b/plugins/precise-volume/menu.js @@ -64,8 +64,8 @@ async function promptGlobalShortcuts(win, options, item) { }, win) if (output) { - for (const keybindObject of output) { - options.globalShortcuts[keybindObject.value] = keybindObject.accelerator; + for (const { value, accelerator } of output) { + options.globalShortcuts[value] = accelerator; } setOptions("precise-volume", options); diff --git a/plugins/shortcuts/menu.js b/plugins/shortcuts/menu.js index cdb395f6..cef14665 100644 --- a/plugins/shortcuts/menu.js +++ b/plugins/shortcuts/menu.js @@ -41,8 +41,8 @@ async function promptKeybind(options, win) { }, win); if (output) { - for (const keybindObject of output) { - options.global[keybindObject.value] = keybindObject.accelerator; + for (const { value, accelerator } of output) { + options.global[value] = accelerator; } setOption(options); } From e43c01da6470d4ff0a2f844b8ac8bc219b2302a7 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Tue, 11 May 2021 00:20:00 +0300 Subject: [PATCH 22/26] lint --- providers/prompt-options.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/providers/prompt-options.js b/providers/prompt-options.js index 79cbc36f..16f02a99 100644 --- a/providers/prompt-options.js +++ b/providers/prompt-options.js @@ -1,7 +1,7 @@ const path = require("path"); const is = require("electron-is"); -const iconPath = path.resolve(__dirname, "../assets/youtube-music-tray.png"); +const iconPath = path.join(__dirname, "..", "assets", "youtube-music-tray.png"); const customTitlebarPath = path.join(__dirname, "prompt-custom-titlebar.js"); const promptOptions = is.macOS() ? { @@ -9,7 +9,6 @@ const promptOptions = is.macOS() ? { icon: iconPath } : { customStylesheet: "dark", - icon: iconPath, // The following are used for custom titlebar frame: false, customScript: customTitlebarPath, From 002081bcb91d1756684ed228cd8fa7241710ba70 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Wed, 12 May 2021 00:47:41 +0300 Subject: [PATCH 23/26] use store migration --- config/store.js | 22 ++++++++++++++++++++++ plugins/shortcuts/back.js | 25 ------------------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/config/store.js b/config/store.js index 9c0de1e4..c91174b7 100644 --- a/config/store.js +++ b/config/store.js @@ -3,6 +3,28 @@ const Store = require("electron-store"); const defaults = require("./defaults"); const migrations = { + /** Update shortcuts format from array to object */ + ">=1.12.0": (store) => { + const options = store.get("plugins.shortcuts") + let updated = false; + for (const optionType of ["global", "local"]) { + if (Array.isArray(options[optionType])) { + 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) { + store.set("plugins.shortcuts", options); + } + }, ">=1.11.0": (store) => { if (store.get("options.resumeOnStart") === undefined) { store.set("options.resumeOnStart", true); diff --git a/plugins/shortcuts/back.js b/plugins/shortcuts/back.js index 688dc5a4..075aefe5 100644 --- a/plugins/shortcuts/back.js +++ b/plugins/shortcuts/back.js @@ -1,6 +1,5 @@ const { globalShortcut } = require("electron"); const electronLocalshortcut = require("electron-localshortcut"); -const { setOptions } = require("../../config/plugins"); const getSongControls = require("../../providers/song-controls"); @@ -20,8 +19,6 @@ function registerShortcuts(win, options) { const songControls = getSongControls(win); const { playPause, next, previous, search } = songControls; - updateOptions(options); - if (options.overrideMediaKeys) { _registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause); _registerGlobalShortcut(win.webContents, "MediaNextTrack", next); @@ -59,26 +56,4 @@ function registerShortcuts(win, options) { } } -/** 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"]) { - if (Array.isArray(options[optionType])) { - 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); - } -} - module.exports = registerShortcuts; From 355f61188af082b491785a4716b5658c17ea9f95 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Thu, 13 May 2021 07:08:17 +0300 Subject: [PATCH 24/26] use placeholder proxy example --- menu.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/menu.js b/menu.js index cdcea4cd..11234900 100644 --- a/menu.js +++ b/menu.js @@ -312,21 +312,21 @@ module.exports.setApplicationMenu = (win) => { Menu.setApplicationMenu(menu); }; -const example = "Example: 'socks5://127.0.0.1:9999'"; async function setProxy(item, win) { const output = await prompt({ title: 'Set Proxy', label: 'Enter Proxy Address: (leave empty to disable)', - value: config.get("options.proxy") || example, + value: config.get("options.proxy"), type: 'input', inputAttrs: { - type: 'url' + type: 'url', + placeholder: "Example: 'socks5://127.0.0.1:9999" }, width: 450, ...promptOptions() }, win); - if (output !== null && output !== example) { + if (output) { config.set("options.proxy", output); item.checked = output !== ""; } else { //user pressed cancel From b2c209837c5ee75fce697a5779fc20ed8b842cb0 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Fri, 14 May 2021 03:12:27 +0300 Subject: [PATCH 25/26] fix empty string input validation in setProxy --- menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/menu.js b/menu.js index 11234900..4a8eeb1c 100644 --- a/menu.js +++ b/menu.js @@ -326,7 +326,7 @@ async function setProxy(item, win) { ...promptOptions() }, win); - if (output) { + if (typeof output === "string") { config.set("options.proxy", output); item.checked = output !== ""; } else { //user pressed cancel From 52a4608d764a3c81032179ca6e14e00161a20482 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Tue, 20 Jul 2021 10:57:32 +0300 Subject: [PATCH 26/26] create options.global if needed --- plugins/shortcuts/menu.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/shortcuts/menu.js b/plugins/shortcuts/menu.js index cef14665..20f21233 100644 --- a/plugins/shortcuts/menu.js +++ b/plugins/shortcuts/menu.js @@ -41,6 +41,9 @@ async function promptKeybind(options, win) { }, win); if (output) { + if (!options.global) { + options.global = {}; + } for (const { value, accelerator } of output) { options.global[value] = accelerator; }