mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-17 13:12:07 +00:00
add keybind changer v1
This commit is contained in:
@ -30,6 +30,7 @@ const defaultConfig = {
|
|||||||
// Disabled plugins
|
// Disabled plugins
|
||||||
shortcuts: {
|
shortcuts: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
overrideMediaKeys: false,
|
||||||
},
|
},
|
||||||
downloader: {
|
downloader: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|||||||
3
menu.js
3
menu.js
@ -335,9 +335,6 @@ function setProxy(item, win) {
|
|||||||
title: 'Set Proxy',
|
title: 'Set Proxy',
|
||||||
label: 'Enter Proxy Address: (leave empty to disable)',
|
label: 'Enter Proxy Address: (leave empty to disable)',
|
||||||
value: config.get("options.proxy") || example,
|
value: config.get("options.proxy") || example,
|
||||||
inputAttrs: {
|
|
||||||
type: 'text'
|
|
||||||
},
|
|
||||||
type: 'input',
|
type: 'input',
|
||||||
icon: iconPath,
|
icon: iconPath,
|
||||||
customStylesheet: "dark",
|
customStylesheet: "dark",
|
||||||
|
|||||||
@ -19,9 +19,12 @@ function registerShortcuts(win, options) {
|
|||||||
const songControls = getSongControls(win);
|
const songControls = getSongControls(win);
|
||||||
const { playPause, next, previous, search } = songControls;
|
const { playPause, next, previous, search } = songControls;
|
||||||
|
|
||||||
_registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause);
|
if (options.overrideMediaKeys) {
|
||||||
_registerGlobalShortcut(win.webContents, "MediaNextTrack", next);
|
_registerGlobalShortcut(win.webContents, "MediaPlayPause", playPause);
|
||||||
_registerGlobalShortcut(win.webContents, "MediaPreviousTrack", previous);
|
_registerGlobalShortcut(win.webContents, "MediaNextTrack", next);
|
||||||
|
_registerGlobalShortcut(win.webContents, "MediaPreviousTrack", previous);
|
||||||
|
}
|
||||||
|
|
||||||
_registerLocalShortcut(win, "CommandOrControl+F", search);
|
_registerLocalShortcut(win, "CommandOrControl+F", search);
|
||||||
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
_registerLocalShortcut(win, "CommandOrControl+L", search);
|
||||||
|
|
||||||
|
|||||||
118
plugins/shortcuts/menu.js
Normal file
118
plugins/shortcuts/menu.js
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
const { setOptions } = require("../../config/plugins");
|
||||||
|
const prompt = require("custom-electron-prompt");
|
||||||
|
const path = require("path");
|
||||||
|
const is = require("electron-is");
|
||||||
|
|
||||||
|
function setOption(options, key = null, newValue = null) {
|
||||||
|
if (key && newValue) {
|
||||||
|
options[key] = newValue;
|
||||||
|
}
|
||||||
|
setOptions("shortcuts", options)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = (win, options) => [
|
||||||
|
{
|
||||||
|
label: "Set Global Song Controls",
|
||||||
|
type: "checkbox",
|
||||||
|
checked: true,
|
||||||
|
click: () => promptKeybind(options, win)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Override MediaKeys",
|
||||||
|
type: "checkbox",
|
||||||
|
checked: options.overrideMediaKeys,
|
||||||
|
click: (item) => setOption(options, "overrideMediaKeys", item.checked)
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
function getGlobalKeybinds(options) {
|
||||||
|
let playPause, next, previous;
|
||||||
|
if (options.global) {
|
||||||
|
for (const global of options.global) {
|
||||||
|
switch (global.action) {
|
||||||
|
case "playPause":
|
||||||
|
playPause = global.shortcut;
|
||||||
|
break;
|
||||||
|
case "previous":
|
||||||
|
previous = global.shortcut;
|
||||||
|
break;
|
||||||
|
case "next":
|
||||||
|
next = global.shortcut;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { playPause, next, previous };
|
||||||
|
}
|
||||||
|
|
||||||
|
function setGlobalKeybinds(options, newShortcuts) {
|
||||||
|
let didSet = {};
|
||||||
|
for (const shortcut in newShortcuts) {
|
||||||
|
didSet[shortcut] = false;
|
||||||
|
}
|
||||||
|
if (!options.global) {
|
||||||
|
options.global = [];
|
||||||
|
}
|
||||||
|
for (let i in options.global) {
|
||||||
|
switch (options.global[i].action) {
|
||||||
|
case "playPause":
|
||||||
|
options.global[i].shortcut = newShortcuts.playPause;
|
||||||
|
didSet["playPause"] = true;
|
||||||
|
break;
|
||||||
|
case "previous":
|
||||||
|
options.global[i].shortcut = newShortcuts.previous;
|
||||||
|
didSet["previous"] = true;
|
||||||
|
break;
|
||||||
|
case "next":
|
||||||
|
options.global[i].shortcut = newShortcuts.next;
|
||||||
|
didSet["next"] = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const action in didSet) {
|
||||||
|
if (!didSet[action]) {
|
||||||
|
options.global.push({ action: action, shortcut: newShortcuts[action] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
options.global.forEach((obj) => console.log(obj));
|
||||||
|
setOption(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
const kb = (label_, value_, default_) => { return { value: value_, label: label_, default: default_ || "" } };
|
||||||
|
const iconPath = path.join(process.cwd(), "assets", "youtube-music-tray.png");
|
||||||
|
|
||||||
|
function promptKeybind(options, win) {
|
||||||
|
let globalKeybinds = getGlobalKeybinds(options);
|
||||||
|
let promptOptions = {
|
||||||
|
title: "Global Keybinds",
|
||||||
|
icon: iconPath,
|
||||||
|
label: "Choose Global Keybinds for Songs Control:",
|
||||||
|
type: "keybind",
|
||||||
|
keybindOptions: [
|
||||||
|
kb("Previous", "previous", globalKeybinds.previous),
|
||||||
|
kb("Play / Pause", "playPause", globalKeybinds.playPause),
|
||||||
|
kb("Next", "next", globalKeybinds.next),
|
||||||
|
],
|
||||||
|
customStylesheet: "dark",
|
||||||
|
height: 250
|
||||||
|
};
|
||||||
|
if (!is.macOS()) {
|
||||||
|
Object.assign(promptOptions, {
|
||||||
|
frame: false,
|
||||||
|
customScript: path.join(process.cwd(), "plugins", "in-app-menu", "prompt-custom-titlebar.js"),
|
||||||
|
enableRemoteModule: true,
|
||||||
|
height: 270
|
||||||
|
});
|
||||||
|
}
|
||||||
|
prompt(promptOptions, win)
|
||||||
|
.then(output => {
|
||||||
|
if (output) {
|
||||||
|
let toSave = {};
|
||||||
|
for (const keybindObj of output) {
|
||||||
|
toSave[keybindObj.value] = keybindObj.accelerator;
|
||||||
|
}
|
||||||
|
setGlobalKeybinds(options, toSave);
|
||||||
|
}
|
||||||
|
//else = pressed cancel
|
||||||
|
})
|
||||||
|
.catch(console.error)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user