From ba5ec28143ed662f596fc5304590b825373a2933 Mon Sep 17 00:00:00 2001 From: Zuntie Date: Sat, 22 Jun 2024 00:39:29 +0200 Subject: [PATCH] fix: Hotfix for issue #108 ._prefs isn't available anymore and is therefore returning "undefined". --- hazy.js | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/hazy.js b/hazy.js index 655ddf6..aa0078f 100644 --- a/hazy.js +++ b/hazy.js @@ -44,14 +44,18 @@ valueSet() async function fetchFadeTime() { + /* It seems that ._prefs isnt available anymore. Therefore the crossfade is being disabled for now. const response = await Spicetify.Platform.PlayerAPI._prefs.get({ key: "audio.crossfade_v2" }); const crossfadeEnabled = response.entries["audio.crossfade_v2"].bool; + */ + const crossfadeEnabled = false let FadeTime = "0.4s"; // Default value of 0.4 seconds, otherwise syncs with crossfade time if (crossfadeEnabled) { - const fadeTimeResponse = await Spicetify.Platform.PlayerAPI._prefs.get({ key: "audio.crossfade.time_v2" }); - const fadeTime = fadeTimeResponse.entries["audio.crossfade.time_v2"].number; + /*const fadeTimeResponse = await Spicetify.Platform.PlayerAPI._prefs.get({ key: "audio.crossfade.time_v2" }); + const fadeTime = fadeTimeResponse.entries["audio.crossfade.time_v2"].number;*/ + const fadeTime = FadeTime const dividedTime = fadeTime / 1000; FadeTime = dividedTime + "s"; } @@ -158,19 +162,26 @@ } function controlDimensions() { + + /* + ._prefs isn't available Spicetify.Platform.PlayerAPI._prefs.get({ key: 'app.browser.zoom-level' }).then((value) => { const zoomLevel = value.entries['app.browser.zoom-level'].number; const zoomNum = Number(zoomLevel) - const multiplier = zoomNum != 0 ? zoomNum/50 : 0; - const isGlobalNav = document.querySelector(".Root__globalNav"); - constant = 0.912872807 - - final_width = 135 * (constant**(multiplier)); - final_height = (isGlobalNav ? 64 : 40) * (constant**(multiplier)); - document.documentElement.style.setProperty("--control-width", Math.abs(final_width) + "px"); - document.documentElement.style.setProperty("--control-height", Math.abs(final_height) + "px"); - console.log("zoom adjusted") - }); + */ + + // Using natives instead of Spicetify's API + const pixelRatio = window.devicePixelRatio || 1; + const multiplier = pixelRatio !== 1 ? pixelRatio / 1 : 0; + const isGlobalNav = document.querySelector(".Root__globalNav"); + const constant = 0.912872807; + + final_width = 135 * (constant**(multiplier)); + final_height = (isGlobalNav ? 64 : 40) * (constant**(multiplier)); + document.documentElement.style.setProperty("--control-width", Math.abs(final_width) + "px"); + document.documentElement.style.setProperty("--control-height", Math.abs(final_height) + "px"); + console.log("zoom adjusted") + //}); } window.addEventListener('resize', function() {