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:
20
menu.js
20
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,19 +322,10 @@ 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,
|
||||
};
|
||||
}
|
||||
const output = await prompt(options, win);
|
||||
...promptOptions()
|
||||
}, win);
|
||||
|
||||
if (output !== null && output !== example) {
|
||||
config.set("options.proxy", output);
|
||||
item.checked = output !== "";
|
||||
|
||||
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
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