From f910593fb648171956f62222eb47cba5f7a458a4 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 10 May 2021 00:40:02 +0300 Subject: [PATCH] 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 }