add optional arrowkeys controls option

This commit is contained in:
Araxeus
2021-04-17 04:14:54 +03:00
parent 5adcc3efad
commit 94e152bb57
2 changed files with 34 additions and 0 deletions

View File

@ -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");

View 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);
}
}
];