mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
lint
This commit is contained in:
@ -60,9 +60,8 @@ const defaultConfig = {
|
||||
steps: 1, //percentage of volume to change
|
||||
arrowsShortcut: true, //enable ArrowUp + ArrowDown local shortcuts
|
||||
globalShortcuts: {
|
||||
enabled: false, // enable global shortcuts
|
||||
volumeUp: "Shift+PageUp", // Keybind default can be changed
|
||||
volumeDown: "Shift+PageDown"
|
||||
volumeUp: "",
|
||||
volumeDown: ""
|
||||
},
|
||||
savedVolume: undefined //plugin save volume between session here
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const { enabled } = require("./back");
|
||||
const { app } = require("electron")
|
||||
const { app } = require("electron");
|
||||
const { setOptions } = require("../../config/plugins");
|
||||
const prompt = require("custom-electron-prompt");
|
||||
const path = require("path");
|
||||
@ -10,7 +10,7 @@ module.exports = (win, options) => [
|
||||
label: "Local Arrowkeys Controls",
|
||||
type: "checkbox",
|
||||
checked: !!options.arrowsShortcut,
|
||||
click: (item) => {
|
||||
click: item => {
|
||||
// Dynamically change setting if plugin is enabled
|
||||
if (enabled()) {
|
||||
win.webContents.send("setArrowsShortcut", item.checked);
|
||||
@ -24,88 +24,85 @@ module.exports = (win, options) => [
|
||||
label: "Global Hotkeys",
|
||||
type: "checkbox",
|
||||
checked: !!options.globalShortcuts.volumeUp || !!options.globalShortcuts.volumeDown,
|
||||
click: item => {
|
||||
promptGlobalShortcuts(win, options, item);
|
||||
}
|
||||
click: item => promptGlobalShortcuts(win, options, item)
|
||||
},
|
||||
{
|
||||
label: "Set Custom Volume Steps",
|
||||
click: () => {
|
||||
promptVolumeSteps(win, options);
|
||||
}
|
||||
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
|
||||
// Helper function for globalShortcuts prompt
|
||||
const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined }; };
|
||||
|
||||
function useCustomTitlebar(options) {
|
||||
if (!is.macOS()) {
|
||||
function setupPromptOptions(options) {
|
||||
// TODO Custom titlebar needs testing on macOS
|
||||
if (is.macOS()) {
|
||||
Object.assign(options, {
|
||||
customStylesheet: "dark",
|
||||
icon: iconPath,
|
||||
frame: false,
|
||||
customScript: customTitlebarPath,
|
||||
enableRemoteModule: true,
|
||||
icon: iconPath
|
||||
});
|
||||
} else {
|
||||
Object.assign(options, {
|
||||
customStylesheet: "dark",
|
||||
icon: iconPath,
|
||||
})
|
||||
// The following are used for custom titlebar
|
||||
frame: false,
|
||||
customScript: customTitlebarPath,
|
||||
enableRemoteModule: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function promptVolumeSteps(win, options) {
|
||||
let promptOptions = {
|
||||
const promptOptions = {
|
||||
title: "Volume Steps",
|
||||
label: "Choose Volume Increase/Decrease Steps",
|
||||
value: options.steps || 1,
|
||||
type: "counter",
|
||||
counterOptions: { minimum: 0, maximum: 100, multiFire: true },
|
||||
}
|
||||
counterOptions: { minimum: 0, maximum: 100, multiFire: true }
|
||||
};
|
||||
|
||||
useCustomTitlebar(promptOptions);
|
||||
setupPromptOptions(promptOptions);
|
||||
|
||||
prompt(promptOptions, win).then(input => {
|
||||
if (input || input === 0) { // 0 is somehow valid
|
||||
options.steps = input;
|
||||
setOptions("precise-volume", options);
|
||||
}
|
||||
}).catch(console.error)
|
||||
}).catch(console.error);
|
||||
}
|
||||
|
||||
function promptGlobalShortcuts(win, options, item) {
|
||||
let promptOptions = {
|
||||
const 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),
|
||||
kb("Increase Volume", "volumeUp", options.globalShortcuts?.volumeUp),
|
||||
kb("Decrease Volume", "volumeDown", options.globalShortcuts?.volumeDown)
|
||||
],
|
||||
height: 230
|
||||
};
|
||||
|
||||
useCustomTitlebar(promptOptions);
|
||||
setupPromptOptions(promptOptions);
|
||||
|
||||
prompt(promptOptions, win)
|
||||
.then(output => {
|
||||
if (output) {
|
||||
for (const keybindObject of output) {
|
||||
options.globalShortcuts[keybindObject.value] = keybindObject.accelerator;
|
||||
.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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ function registerShortcuts(win, options) {
|
||||
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
||||
|
||||
const { global, local } = options;
|
||||
const shortcutOptions = {global, local};
|
||||
const shortcutOptions = { global, local };
|
||||
|
||||
for (const optionType in shortcutOptions) {
|
||||
registerAllShortcuts(shortcutOptions[optionType], optionType);
|
||||
@ -41,23 +41,25 @@ function registerShortcuts(win, options) {
|
||||
function registerAllShortcuts(container, type) {
|
||||
for (const action in container) {
|
||||
if (!container[action]) {
|
||||
continue; //accelerator is empty
|
||||
continue; // Action accelerator is empty
|
||||
}
|
||||
|
||||
|
||||
console.debug(`Registering ${type} shortcut`, container[action], ":", action);
|
||||
if (!songControls[action]) {
|
||||
console.warn("Invalid action", action);
|
||||
continue;
|
||||
}
|
||||
|
||||
type === "global" ?
|
||||
_registerGlobalShortcut(win.webContents, container[action], songControls[action]) :
|
||||
_registerLocalShortcut(win, local[action], songControls[action]);
|
||||
|
||||
if (type === "global") {
|
||||
_registerGlobalShortcut(win.webContents, container[action], songControls[action]);
|
||||
} else { // type === "local"
|
||||
_registerLocalShortcut(win, local[action], songControls[action]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Update options to new format */
|
||||
/** Update options to new format if they are still an array (old format) */
|
||||
function updateOptions(options) {
|
||||
let updated = false;
|
||||
for (const optionType of ["global", "local"]) {
|
||||
|
||||
@ -25,16 +25,17 @@ function setOption(options, key = null, newValue = null) {
|
||||
setOptions("shortcuts", options);
|
||||
}
|
||||
|
||||
const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || undefined }; };
|
||||
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) {
|
||||
let promptOptions = {
|
||||
const promptOptions = {
|
||||
title: "Global Keybinds",
|
||||
icon: iconPath,
|
||||
label: "Choose Global Keybinds for Songs Control:",
|
||||
type: "keybind",
|
||||
keybindOptions: [
|
||||
keybindOptions: [ // If default=undefined then no default is used
|
||||
kb("Previous", "previous", options.global?.previous),
|
||||
kb("Play / Pause", "playPause", options.global?.playPause),
|
||||
kb("Next", "next", options.global?.next)
|
||||
|
||||
Reference in New Issue
Block a user