mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 03:41:46 +00:00
fix precise-volume hud positioning
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
const { ipcRenderer } = require("electron");
|
const { ipcRenderer } = require("electron");
|
||||||
const { globalShortcut } = require('@electron/remote');
|
const { globalShortcut } = require('@electron/remote');
|
||||||
|
|
||||||
const { setOptions } = require("../../config/plugins");
|
const { setOptions, isEnabled } = require("../../config/plugins");
|
||||||
|
|
||||||
function $(selector) { return document.querySelector(selector); }
|
function $(selector) { return document.querySelector(selector); }
|
||||||
let api;
|
let api;
|
||||||
@ -13,6 +13,8 @@ module.exports = (options) => {
|
|||||||
}, { once: true, passive: true })
|
}, { once: true, passive: true })
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.moveVolumeHud = moveVolumeHud;
|
||||||
|
|
||||||
/** Restore saved volume and setup tooltip */
|
/** Restore saved volume and setup tooltip */
|
||||||
function firstRun(options) {
|
function firstRun(options) {
|
||||||
if (typeof options.savedVolume === "number") {
|
if (typeof options.savedVolume === "number") {
|
||||||
@ -34,6 +36,11 @@ function firstRun(options) {
|
|||||||
injectVolumeHud(noVid);
|
injectVolumeHud(noVid);
|
||||||
if (!noVid) {
|
if (!noVid) {
|
||||||
setupVideoPlayerOnwheel(options);
|
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
|
// 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;
|
let hudFadeTimeout;
|
||||||
|
|
||||||
function showVolumeHud(volume) {
|
function showVolumeHud(volume) {
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
const { ElementFromFile, templatePath } = require("../utils");
|
const { ElementFromFile, templatePath } = require("../utils");
|
||||||
|
|
||||||
const { setOptions } = require("../../config/plugins");
|
const { setOptions, isEnabled } = require("../../config/plugins");
|
||||||
|
|
||||||
|
const moveVolumeHud = isEnabled("precise-volume") ? require("../precise-volume/front").moveVolumeHud : ()=>{};
|
||||||
|
|
||||||
function $(selector) { return document.querySelector(selector); }
|
function $(selector) { return document.querySelector(selector); }
|
||||||
|
|
||||||
@ -89,13 +91,6 @@ function forcePlaybackMode() {
|
|||||||
playbackModeObserver.observe(player, { attributeFilter: ["playback-mode"] });
|
playbackModeObserver.observe(player, { attributeFilter: ["playback-mode"] });
|
||||||
}
|
}
|
||||||
|
|
||||||
// if precise volume plugin is enabled, move its hud to be on top of the video
|
|
||||||
function moveVolumeHud(showVideo) {
|
|
||||||
const volumeHud = $('#volumeHud');
|
|
||||||
if (volumeHud)
|
|
||||||
volumeHud.style.top = showVideo ? `${(player.clientHeight - video.clientHeight) / 2}px` : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function observeThumbnail() {
|
function observeThumbnail() {
|
||||||
const playbackModeObserver = new MutationObserver(mutations => {
|
const playbackModeObserver = new MutationObserver(mutations => {
|
||||||
if (!player.videoMode_) return;
|
if (!player.videoMode_) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user