mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
Volume Steps Prompt
Precise-Volume Global Shortcuts Prompt
This commit is contained in:
@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user