use spread operator + async await

This commit is contained in:
Araxeus
2021-05-10 00:40:02 +03:00
parent 5418ef7ae2
commit f910593fb6
3 changed files with 52 additions and 65 deletions

13
menu.js
View File

@ -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 => {
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
}
})
.catch(console.error);
}

View File

@ -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
const output = await prompt(promptOptions, win)
if (output || output === 0) { // 0 is somewhat valid
options.steps = output;
setOptions("precise-volume", options);
}
}).catch(console.error);
}
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,12 +63,9 @@ function promptGlobalShortcuts(win, options, item) {
kb("Increase Volume", "volumeUp", options.globalShortcuts?.volumeUp),
kb("Decrease Volume", "volumeDown", options.globalShortcuts?.volumeDown)
]
};
});
setupPromptOptions(promptOptions);
prompt(promptOptions, win)
.then(output => {
const output = await prompt(promptOptions, win)
if (output) {
for (const keybindObject of output) {
options.globalShortcuts[keybindObject.value] = keybindObject.accelerator;
@ -85,25 +78,25 @@ function promptGlobalShortcuts(win, options, item) {
// Reset checkbox if prompt was canceled
item.checked = !item.checked;
}
})
.catch(console.error);
}
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
});
};
}
}

View File

@ -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 => {
const output = await prompt(promptOptions, win);
if (output) {
for (const keybindObject of output) {
options.global[keybindObject.value] = keybindObject.accelerator;
}
setOption(options);
}
// else -> pressed cancel
})
.catch(console.error);
}