mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 18:21:47 +00:00
Volume Steps Prompt
Precise-Volume Global Shortcuts Prompt
This commit is contained in:
17
menu.js
17
menu.js
@ -141,18 +141,17 @@ const mainMenuTemplate = (win) => [
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ type: "separator" },
|
{ type: "separator" },
|
||||||
// Should be put in Advanced Options submenu
|
|
||||||
{
|
|
||||||
label: "Proxy",
|
|
||||||
type: "checkbox",
|
|
||||||
checked: !!config.get("options.proxy"),
|
|
||||||
click: (item) => {
|
|
||||||
setProxy(item, win);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: "Advanced options",
|
label: "Advanced options",
|
||||||
submenu: [
|
submenu: [
|
||||||
|
{
|
||||||
|
label: "Proxy",
|
||||||
|
type: "checkbox",
|
||||||
|
checked: !!config.get("options.proxy"),
|
||||||
|
click: (item) => {
|
||||||
|
setProxy(item, win);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "Disable hardware acceleration",
|
label: "Disable hardware acceleration",
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
|
|||||||
@ -12,9 +12,7 @@ module.exports = (options) => {
|
|||||||
|
|
||||||
setupLocalArrowShortcuts(options);
|
setupLocalArrowShortcuts(options);
|
||||||
|
|
||||||
if (options.globalShortcuts?.enabled) {
|
setupGlobalShortcuts(options);
|
||||||
setupGlobalShortcuts(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
firstRun(options);
|
firstRun(options);
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
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 path = require("path");
|
||||||
|
const is = require("electron-is");
|
||||||
|
|
||||||
module.exports = (win, options) => [
|
module.exports = (win, options) => [
|
||||||
{
|
{
|
||||||
label: "Arrowkeys controls",
|
label: "Local Arrowkeys Controls",
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: !!options.arrowsShortcut,
|
checked: !!options.arrowsShortcut,
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
// Dynamically change setting if plugin enabled
|
// Dynamically change setting if plugin is enabled
|
||||||
if (enabled()) {
|
if (enabled()) {
|
||||||
win.webContents.send("setArrowsShortcut", item.checked);
|
win.webContents.send("setArrowsShortcut", item.checked);
|
||||||
} else { // Fallback to usual method if disabled
|
} else { // Fallback to usual method if disabled
|
||||||
@ -15,5 +19,93 @@ module.exports = (win, options) => [
|
|||||||
setOptions("precise-volume", 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);
|
||||||
|
}
|
||||||
@ -18,7 +18,7 @@ module.exports = (win, options) => [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function setOption(options, key = null, newValue = null) {
|
function setOption(options, key = null, newValue = null) {
|
||||||
if (key && newValue) {
|
if (key && newValue !== null) {
|
||||||
options[key] = newValue;
|
options[key] = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user