mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
fix precise-volume options sync
This commit is contained in:
@ -34,6 +34,14 @@ function firstRun(options) {
|
|||||||
if (!noVid) {
|
if (!noVid) {
|
||||||
setupVideoPlayerOnwheel(options);
|
setupVideoPlayerOnwheel(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change options from renderer to keep sync
|
||||||
|
ipcRenderer.on("setOptions", (_event, newOptions = {}) => {
|
||||||
|
for (option in newOptions) {
|
||||||
|
options[option] = newOptions[option];
|
||||||
|
}
|
||||||
|
setOptions("precise-volume", options);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function injectVolumeHud(noVid) {
|
function injectVolumeHud(noVid) {
|
||||||
@ -93,7 +101,7 @@ function writeOptions(options) {
|
|||||||
writeTimeout = setTimeout(() => {
|
writeTimeout = setTimeout(() => {
|
||||||
setOptions("precise-volume", options);
|
setOptions("precise-volume", options);
|
||||||
writeTimeout = null;
|
writeTimeout = null;
|
||||||
}, 1500)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add onwheel event to play bar and also track if play bar is hovered*/
|
/** Add onwheel event to play bar and also track if play bar is hovered*/
|
||||||
@ -142,7 +150,7 @@ function setupSliderObserver(options) {
|
|||||||
/** if (toIncrease = false) then volume decrease */
|
/** if (toIncrease = false) then volume decrease */
|
||||||
function changeVolume(toIncrease, options) {
|
function changeVolume(toIncrease, options) {
|
||||||
// Apply volume change if valid
|
// Apply volume change if valid
|
||||||
const steps = (options.steps || 1);
|
const steps = Number(options.steps || 1);
|
||||||
api.setVolume(toIncrease ?
|
api.setVolume(toIncrease ?
|
||||||
Math.min(api.getVolume() + steps, 100) :
|
Math.min(api.getVolume() + steps, 100) :
|
||||||
Math.max(api.getVolume() - steps, 0));
|
Math.max(api.getVolume() - steps, 0));
|
||||||
@ -211,39 +219,17 @@ function setupGlobalShortcuts(options) {
|
|||||||
|
|
||||||
function setupLocalArrowShortcuts(options) {
|
function setupLocalArrowShortcuts(options) {
|
||||||
if (options.arrowsShortcut) {
|
if (options.arrowsShortcut) {
|
||||||
addListener();
|
window.addEventListener('keydown', (event) => {
|
||||||
}
|
switch (event.code) {
|
||||||
|
case "ArrowUp":
|
||||||
// Change options from renderer to keep sync
|
event.preventDefault();
|
||||||
ipcRenderer.on("setArrowsShortcut", (_event, isEnabled) => {
|
changeVolume(true, options);
|
||||||
options.arrowsShortcut = isEnabled;
|
break;
|
||||||
setOptions("precise-volume", options);
|
case "ArrowDown":
|
||||||
// This allows changing this setting without restarting app
|
event.preventDefault();
|
||||||
if (isEnabled) {
|
changeVolume(false, options);
|
||||||
addListener();
|
break;
|
||||||
} else {
|
}
|
||||||
removeListener();
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function addListener() {
|
|
||||||
window.addEventListener('keydown', callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeListener() {
|
|
||||||
window.removeEventListener("keydown", callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
function callback(event) {
|
|
||||||
switch (event.code) {
|
|
||||||
case "ArrowUp":
|
|
||||||
event.preventDefault();
|
|
||||||
changeVolume(true, options);
|
|
||||||
break;
|
|
||||||
case "ArrowDown":
|
|
||||||
event.preventDefault();
|
|
||||||
changeVolume(false, options);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,17 @@ const { setOptions } = require("../../config/plugins");
|
|||||||
const prompt = require("custom-electron-prompt");
|
const prompt = require("custom-electron-prompt");
|
||||||
const promptOptions = require("../../providers/prompt-options");
|
const promptOptions = require("../../providers/prompt-options");
|
||||||
|
|
||||||
|
function changeOptions(changedOptions, options, win) {
|
||||||
|
for (option in changedOptions) {
|
||||||
|
options[option] = changedOptions[option];
|
||||||
|
}
|
||||||
|
// Dynamically change setting if plugin is enabled
|
||||||
|
if (enabled()) {
|
||||||
|
win.webContents.send("setOptions", changedOptions);
|
||||||
|
} else { // Fallback to usual method if disabled
|
||||||
|
setOptions("precise-volume", options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = (win, options) => [
|
module.exports = (win, options) => [
|
||||||
{
|
{
|
||||||
@ -10,13 +21,7 @@ module.exports = (win, options) => [
|
|||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: !!options.arrowsShortcut,
|
checked: !!options.arrowsShortcut,
|
||||||
click: item => {
|
click: item => {
|
||||||
// Dynamically change setting if plugin is enabled
|
changeOptions({ arrowsShortcut: item.checked }, options, win);
|
||||||
if (enabled()) {
|
|
||||||
win.webContents.send("setArrowsShortcut", item.checked);
|
|
||||||
} else { // Fallback to usual method if disabled
|
|
||||||
options.arrowsShortcut = item.checked;
|
|
||||||
setOptions("precise-volume", options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -46,8 +51,7 @@ async function promptVolumeSteps(win, options) {
|
|||||||
}, win)
|
}, win)
|
||||||
|
|
||||||
if (output || output === 0) { // 0 is somewhat valid
|
if (output || output === 0) { // 0 is somewhat valid
|
||||||
options.steps = output;
|
changeOptions({ steps: output}, options, win);
|
||||||
setOptions("precise-volume", options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,11 +68,11 @@ async function promptGlobalShortcuts(win, options, item) {
|
|||||||
}, win)
|
}, win)
|
||||||
|
|
||||||
if (output) {
|
if (output) {
|
||||||
|
let newGlobalShortcuts = {};
|
||||||
for (const { value, accelerator } of output) {
|
for (const { value, accelerator } of output) {
|
||||||
options.globalShortcuts[value] = accelerator;
|
newGlobalShortcuts[value] = accelerator;
|
||||||
}
|
}
|
||||||
|
changeOptions({ globalShortcuts: newGlobalShortcuts }, options, win);
|
||||||
setOptions("precise-volume", options);
|
|
||||||
|
|
||||||
item.checked = !!options.globalShortcuts.volumeUp || !!options.globalShortcuts.volumeDown;
|
item.checked = !!options.globalShortcuts.volumeUp || !!options.globalShortcuts.volumeDown;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user