mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 18:21:47 +00:00
globalize promptOptions
This commit is contained in:
30
menu.js
30
menu.js
@ -6,7 +6,9 @@ const is = require("electron-is");
|
|||||||
|
|
||||||
const { getAllPlugins } = require("./plugins/utils");
|
const { getAllPlugins } = require("./plugins/utils");
|
||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
|
|
||||||
const prompt = require("custom-electron-prompt");
|
const prompt = require("custom-electron-prompt");
|
||||||
|
const promptOptions = require("./providers/prompt-options");
|
||||||
|
|
||||||
const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu = false) => ({
|
const pluginEnabledMenu = (win, plugin, label = "", hasSubmenu = false) => ({
|
||||||
label: label || plugin,
|
label: label || plugin,
|
||||||
@ -310,10 +312,9 @@ module.exports.setApplicationMenu = (win) => {
|
|||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
};
|
};
|
||||||
|
|
||||||
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'";
|
||||||
async function setProxy(item, win) {
|
async function setProxy(item, win) {
|
||||||
let options = {
|
const output = await prompt({
|
||||||
title: 'Set Proxy',
|
title: 'Set Proxy',
|
||||||
label: 'Enter Proxy Address: (leave empty to disable)',
|
label: 'Enter Proxy Address: (leave empty to disable)',
|
||||||
value: config.get("options.proxy") || example,
|
value: config.get("options.proxy") || example,
|
||||||
@ -321,23 +322,14 @@ async function setProxy(item, win) {
|
|||||||
inputAttrs: {
|
inputAttrs: {
|
||||||
type: 'url'
|
type: 'url'
|
||||||
},
|
},
|
||||||
icon: iconPath,
|
|
||||||
customStylesheet: "dark",
|
|
||||||
width: 450,
|
width: 450,
|
||||||
};
|
...promptOptions()
|
||||||
if (!is.macOS()) {
|
}, win);
|
||||||
options = {
|
|
||||||
...options,
|
if (output !== null && output !== example) {
|
||||||
frame: false,
|
config.set("options.proxy", output);
|
||||||
customScript: path.join(__dirname, "plugins", "in-app-menu", "prompt-custom-titlebar.js"),
|
item.checked = output !== "";
|
||||||
enableRemoteModule: true,
|
} 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
const { enabled } = require("./back");
|
const { enabled } = require("./back");
|
||||||
const { app } = require("electron");
|
|
||||||
const { setOptions } = require("../../config/plugins");
|
const { setOptions } = require("../../config/plugins");
|
||||||
const prompt = require("custom-electron-prompt");
|
const prompt = require("custom-electron-prompt");
|
||||||
const path = require("path");
|
const promptOptions = require("../../providers/prompt-options");
|
||||||
const is = require("electron-is");
|
|
||||||
|
|
||||||
module.exports = (win, 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
|
// Helper function for globalShortcuts prompt
|
||||||
const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined }; };
|
const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined }; };
|
||||||
|
|
||||||
async function promptVolumeSteps(win, options) {
|
async function promptVolumeSteps(win, options) {
|
||||||
const promptOptions = setupPromptOptions({
|
const output = await prompt({
|
||||||
title: "Volume Steps",
|
title: "Volume Steps",
|
||||||
label: "Choose Volume Increase/Decrease Steps",
|
label: "Choose Volume Increase/Decrease Steps",
|
||||||
value: options.steps || 1,
|
value: options.steps || 1,
|
||||||
type: "counter",
|
type: "counter",
|
||||||
counterOptions: { minimum: 0, maximum: 100, multiFire: true },
|
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
|
if (output || output === 0) { // 0 is somewhat valid
|
||||||
options.steps = output;
|
options.steps = output;
|
||||||
setOptions("precise-volume", options);
|
setOptions("precise-volume", options);
|
||||||
@ -55,17 +52,17 @@ async function promptVolumeSteps(win, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function promptGlobalShortcuts(win, options, item) {
|
async function promptGlobalShortcuts(win, options, item) {
|
||||||
const promptOptions = setupPromptOptions({
|
const output = await prompt({
|
||||||
title: "Global Volume Keybinds",
|
title: "Global Volume Keybinds",
|
||||||
label: "Choose Global Volume Keybinds:",
|
label: "Choose Global Volume Keybinds:",
|
||||||
type: "keybind",
|
type: "keybind",
|
||||||
keybindOptions: [
|
keybindOptions: [
|
||||||
kb("Increase Volume", "volumeUp", options.globalShortcuts?.volumeUp),
|
kb("Increase Volume", "volumeUp", options.globalShortcuts?.volumeUp),
|
||||||
kb("Decrease Volume", "volumeDown", options.globalShortcuts?.volumeDown)
|
kb("Decrease Volume", "volumeDown", options.globalShortcuts?.volumeDown)
|
||||||
]
|
],
|
||||||
});
|
...promptOptions()
|
||||||
|
}, win)
|
||||||
|
|
||||||
const output = await prompt(promptOptions, win)
|
|
||||||
if (output) {
|
if (output) {
|
||||||
for (const keybindObject of output) {
|
for (const keybindObject of output) {
|
||||||
options.globalShortcuts[keybindObject.value] = keybindObject.accelerator;
|
options.globalShortcuts[keybindObject.value] = keybindObject.accelerator;
|
||||||
@ -79,24 +76,3 @@ async function promptGlobalShortcuts(win, options, item) {
|
|||||||
item.checked = !item.checked;
|
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
const { setOptions } = require("../../config/plugins");
|
const { setOptions } = require("../../config/plugins");
|
||||||
const prompt = require("custom-electron-prompt");
|
const prompt = require("custom-electron-prompt");
|
||||||
|
const promptOptions = require("../../providers/prompt-options");
|
||||||
const path = require("path");
|
|
||||||
const is = require("electron-is");
|
|
||||||
|
|
||||||
module.exports = (win, options) => [
|
module.exports = (win, options) => [
|
||||||
{
|
{
|
||||||
@ -25,14 +23,12 @@ function setOption(options, key = null, newValue = null) {
|
|||||||
setOptions("shortcuts", options);
|
setOptions("shortcuts", options);
|
||||||
}
|
}
|
||||||
|
|
||||||
const iconPath = path.join(process.cwd(), "assets", "youtube-music-tray.png");
|
|
||||||
// Helper function for keybind prompt
|
// Helper function for keybind prompt
|
||||||
const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ }; };
|
const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ }; };
|
||||||
|
|
||||||
async function promptKeybind(options, win) {
|
async function promptKeybind(options, win) {
|
||||||
let promptOptions = {
|
const output = await prompt({
|
||||||
title: "Global Keybinds",
|
title: "Global Keybinds",
|
||||||
icon: iconPath,
|
|
||||||
label: "Choose Global Keybinds for Songs Control:",
|
label: "Choose Global Keybinds for Songs Control:",
|
||||||
type: "keybind",
|
type: "keybind",
|
||||||
keybindOptions: [ // If default=undefined then no default is used
|
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("Play / Pause", "playPause", options.global?.playPause),
|
||||||
kb("Next", "next", options.global?.next)
|
kb("Next", "next", options.global?.next)
|
||||||
],
|
],
|
||||||
customStylesheet: "dark",
|
height: 270,
|
||||||
height: 250
|
...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) {
|
if (output) {
|
||||||
for (const keybindObject of output) {
|
for (const keybindObject of output) {
|
||||||
options.global[keybindObject.value] = keybindObject.accelerator;
|
options.global[keybindObject.value] = keybindObject.accelerator;
|
||||||
|
|||||||
19
providers/prompt-options.js
Normal file
19
providers/prompt-options.js
Normal file
@ -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;
|
||||||
Reference in New Issue
Block a user