mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 02:31:45 +00:00
add optional arrowkeys controls option
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
const { setOptions } = require("../../config/plugins");
|
||||
const { ipcRenderer } = require("electron");
|
||||
|
||||
module.exports = (options) => {
|
||||
setPlaybarOnwheel(options);
|
||||
setObserver(options);
|
||||
firstRun(options);
|
||||
setupArrowShortcuts(options);
|
||||
};
|
||||
|
||||
function saveVolume(volume, options) {
|
||||
@ -42,6 +44,28 @@ function setPlaybarOnwheel(options) {
|
||||
};
|
||||
}
|
||||
|
||||
function setupArrowShortcuts(options) {
|
||||
//change options from renderer to keep sync
|
||||
ipcRenderer.on("setArrowsShortcut", (event, value) => {
|
||||
options.arrowsShortcut = value;
|
||||
setOptions("precise-volume", options);
|
||||
});
|
||||
|
||||
//register shortcuts if enabled
|
||||
if (options.arrowsShortcut) {
|
||||
window.addEventListener('keydown', (event) => {
|
||||
switch (event.code) {
|
||||
case `ArrowUp`:
|
||||
changeVolume(true, options);
|
||||
break;
|
||||
case `ArrowDown`:
|
||||
changeVolume(false, options);
|
||||
break;
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
|
||||
function changeVolume(increase, options) {
|
||||
// Need to change both the slider and the actual volume
|
||||
const videoStream = document.querySelector(".video-stream");
|
||||
|
||||
10
plugins/precise-volume/menu.js
Normal file
10
plugins/precise-volume/menu.js
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports = (win, options) => [
|
||||
{
|
||||
label: "Arrowkeys controls",
|
||||
type: "checkbox",
|
||||
checked: !!options.arrowsShortcut,
|
||||
click: (item) => {
|
||||
win.webContents.send("setArrowsShortcut", item.checked);
|
||||
}
|
||||
}
|
||||
];
|
||||
Reference in New Issue
Block a user