mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-18 05:32:06 +00:00
enable global volume shortcuts in advanced config
This commit is contained in:
@ -50,6 +50,11 @@ const defaultConfig = {
|
|||||||
enabled: false,
|
enabled: false,
|
||||||
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: {
|
||||||
|
enabled: false, // enable global shortcuts
|
||||||
|
volumeUp: "Shift+PageUp", // Keybind default can be changed
|
||||||
|
volumeDown: "Shift+PageDown"
|
||||||
|
},
|
||||||
savedVolume: undefined //plugin save volume between session here
|
savedVolume: undefined //plugin save volume between session here
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,20 +1,30 @@
|
|||||||
const { ipcRenderer } = require("electron");
|
const { ipcRenderer, remote } = require("electron");
|
||||||
|
|
||||||
const { setOptions } = require("../../config/plugins");
|
const { setOptions } = require("../../config/plugins");
|
||||||
|
|
||||||
function $(selector) { return document.querySelector(selector); }
|
function $(selector) { return document.querySelector(selector); }
|
||||||
|
|
||||||
module.exports = (options) => {
|
module.exports = (options) => {
|
||||||
|
|
||||||
setupPlaybar(options);
|
setupPlaybar(options);
|
||||||
|
|
||||||
setupSliderObserver(options);
|
setupSliderObserver(options);
|
||||||
setupArrowShortcuts(options);
|
|
||||||
|
setupLocalArrowShortcuts(options);
|
||||||
|
|
||||||
|
if (options.globalShortcuts?.enabled) {
|
||||||
|
setupGlobalShortcuts(options);
|
||||||
|
}
|
||||||
|
|
||||||
firstRun(options);
|
firstRun(options);
|
||||||
|
// This way the ipc listener gets cleared either way
|
||||||
ipcRenderer.once("setupVideoPlayerVolumeMousewheel", (_event, toEnable) => {
|
ipcRenderer.once("setupVideoPlayerVolumeMousewheel", (_event, toEnable) => {
|
||||||
if (toEnable)
|
if (toEnable)
|
||||||
setupVideoPlayerOnwheel(options);
|
setupVideoPlayerOnwheel(options);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function setupVideoPlayerOnwheel(options){
|
function setupVideoPlayerOnwheel(options) {
|
||||||
// Add onwheel event to video player
|
// Add onwheel event to video player
|
||||||
$("#main-panel").addEventListener("wheel", event => {
|
$("#main-panel").addEventListener("wheel", event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -73,13 +83,13 @@ function setupPlaybar(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// (increase = false) means volume decrease
|
// (increase = false) means volume decrease
|
||||||
function changeVolume(increase, options) {
|
function changeVolume(toIncrease, options) {
|
||||||
// Need to change both the actual volume and the slider
|
// Need to change both the actual volume and the slider
|
||||||
const videoStream = $(".video-stream");
|
const videoStream = $(".video-stream");
|
||||||
const slider = $("#volume-slider");
|
const slider = $("#volume-slider");
|
||||||
// Apply volume change if valid
|
// Apply volume change if valid
|
||||||
const steps = options.steps / 100;
|
const steps = options.steps / 100;
|
||||||
videoStream.volume = increase ?
|
videoStream.volume = toIncrease ?
|
||||||
Math.min(videoStream.volume + steps, 1) :
|
Math.min(videoStream.volume + steps, 1) :
|
||||||
Math.max(videoStream.volume - steps, 0);
|
Math.max(videoStream.volume - steps, 0);
|
||||||
|
|
||||||
@ -98,7 +108,7 @@ let volumeHoverTimeoutID;
|
|||||||
function showVolumeSlider(slider) {
|
function showVolumeSlider(slider) {
|
||||||
// This class display the volume slider if not in minimized mode
|
// This class display the volume slider if not in minimized mode
|
||||||
slider.classList.add("on-hover");
|
slider.classList.add("on-hover");
|
||||||
// Reset timeout if previous one hasn't completed
|
// Reset timeout if previous one hasn't completed
|
||||||
if (volumeHoverTimeoutID) {
|
if (volumeHoverTimeoutID) {
|
||||||
clearTimeout(volumeHoverTimeoutID);
|
clearTimeout(volumeHoverTimeoutID);
|
||||||
}
|
}
|
||||||
@ -146,7 +156,16 @@ function setTooltip(volume) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupArrowShortcuts(options) {
|
function setupGlobalShortcuts(options) {
|
||||||
|
if (options.globalShortcuts.volumeUp) {
|
||||||
|
remote.globalShortcut.register((options.globalShortcuts.volumeUp), () => changeVolume(true, options));
|
||||||
|
}
|
||||||
|
if (options.globalShortcuts.volumeDown) {
|
||||||
|
remote.globalShortcut.register((options.globalShortcuts.volumeDown), () => changeVolume(false, options));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupLocalArrowShortcuts(options) {
|
||||||
// Register shortcuts if enabled
|
// Register shortcuts if enabled
|
||||||
if (options.arrowsShortcut) {
|
if (options.arrowsShortcut) {
|
||||||
addListener();
|
addListener();
|
||||||
|
|||||||
Reference in New Issue
Block a user