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