Merge branch 'master' into fix-restart-on-config-change

This commit is contained in:
Araxeus
2022-02-07 17:27:27 +02:00
committed by GitHub
9 changed files with 346 additions and 195 deletions

View File

@ -1,7 +1,7 @@
const { ipcRenderer } = require("electron");
const { globalShortcut } = require('@electron/remote');
const { setOptions, setMenuOptions } = require("../../config/plugins");
const { setOptions, setMenuOptions, isEnabled } = require("../../config/plugins");
function $(selector) { return document.querySelector(selector); }
let api;
@ -13,6 +13,8 @@ module.exports = (options) => {
}, { once: true, passive: true })
};
module.exports.moveVolumeHud = moveVolumeHud;
/** Restore saved volume and setup tooltip */
function firstRun(options) {
if (typeof options.savedVolume === "number") {
@ -34,6 +36,11 @@ function firstRun(options) {
injectVolumeHud(noVid);
if (!noVid) {
setupVideoPlayerOnwheel(options);
if (!isEnabled('video-toggle')) {
//video-toggle handles hud positioning on its own
const videoMode = () => api.getPlayerResponse().videoDetails?.musicVideoType !== 'MUSIC_VIDEO_TYPE_ATV';
$("video").addEventListener("srcChanged", () => moveVolumeHud(videoMode()));
}
}
// Change options from renderer to keep sync
@ -61,6 +68,16 @@ function injectVolumeHud(noVid) {
}
}
let hudMoveTimeout;
function moveVolumeHud(showVideo) {
clearTimeout(hudMoveTimeout);
const volumeHud = $('#volumeHud');
if (!volumeHud) return;
hudMoveTimeout = setTimeout(() => {
volumeHud.style.top = showVideo ? `${($('ytmusic-player').clientHeight - $('video').clientHeight) / 2}px` : 0;
}, 250)
}
let hudFadeTimeout;
function showVolumeHud(volume) {