Skip to content

Commit 99645b6

Browse files
committed
fix(wrapper): left topbar icons & run scroll fix on 1.2.56 and lower
1 parent e692aca commit 99645b6

File tree

1 file changed

+49
-40
lines changed

1 file changed

+49
-40
lines changed

jsHelper/spicetifyWrapper.js

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,55 @@ window.Spicetify = {
306306
Platform: {},
307307
};
308308

309+
(function waitForPlatform() {
310+
if (!Spicetify._platform) {
311+
setTimeout(waitForPlatform, 50);
312+
return;
313+
}
314+
const { _platform } = Spicetify;
315+
for (const key of Object.keys(_platform)) {
316+
if (key.startsWith("get") && typeof _platform[key] === "function") {
317+
Spicetify.Platform[key.slice(3)] = _platform[key]();
318+
} else {
319+
Spicetify.Platform[key] = _platform[key];
320+
}
321+
}
322+
})();
323+
324+
(function addMissingPlatformAPIs() {
325+
if (!Spicetify.Platform?.version && !Spicetify.Platform?.Registry) {
326+
setTimeout(addMissingPlatformAPIs, 50);
327+
return;
328+
}
329+
const version = Spicetify.Platform.version.split(".").map((i) => Number.parseInt(i));
330+
if (version[0] === 1 && version[1] === 2 && version[2] < 38) return;
331+
332+
for (const [key, _] of Spicetify.Platform.Registry._map.entries()) {
333+
if (typeof key?.description !== "string" || !key?.description.endsWith("API")) continue;
334+
const symbolName = key.description;
335+
if (Object.hasOwn(Spicetify.Platform, symbolName)) continue;
336+
const resolvedAPI = Spicetify.Platform.Registry.resolve(key);
337+
if (!resolvedAPI) {
338+
console.warn(`[spicetifyWrapper] Failed to resolve PlatformAPI from Registry: ${symbolName}`);
339+
continue;
340+
}
341+
342+
Spicetify.Platform[symbolName] = resolvedAPI;
343+
console.debug(`[spicetifyWrapper] Resolved PlatformAPI from Registry: ${symbolName}`);
344+
}
345+
})();
346+
309347
// Based on https://blog.aziz.tn/2025/01/spotify-fix-lagging-issue-on-scrolling.html
310348
function applyScrollingFix() {
349+
if (!Spicetify.Platform?.version) {
350+
setTimeout(applyScrollingFix, 50);
351+
return;
352+
}
353+
354+
// Run only for 1.2.56 and lower
355+
const version = Spicetify.Platform.version.split(".").map((i) => Number.parseInt(i));
356+
if (version[1] >= 2 && version[2] >= 57) return;
357+
311358
const scrollableElements = Array.from(document.querySelectorAll("*")).filter((el) => {
312359
if (
313360
el.id === "context-menu" ||
@@ -351,44 +398,6 @@ window.addEventListener("popstate", () => {
351398

352399
applyScrollingFix();
353400

354-
(function waitForPlatform() {
355-
if (!Spicetify._platform) {
356-
setTimeout(waitForPlatform, 50);
357-
return;
358-
}
359-
const { _platform } = Spicetify;
360-
for (const key of Object.keys(_platform)) {
361-
if (key.startsWith("get") && typeof _platform[key] === "function") {
362-
Spicetify.Platform[key.slice(3)] = _platform[key]();
363-
} else {
364-
Spicetify.Platform[key] = _platform[key];
365-
}
366-
}
367-
})();
368-
369-
(function addMissingPlatformAPIs() {
370-
if (!Spicetify.Platform?.version && !Spicetify.Platform?.Registry) {
371-
setTimeout(addMissingPlatformAPIs, 50);
372-
return;
373-
}
374-
const version = Spicetify.Platform.version.split(".").map((i) => Number.parseInt(i));
375-
if (version[0] === 1 && version[1] === 2 && version[2] < 38) return;
376-
377-
for (const [key, _] of Spicetify.Platform.Registry._map.entries()) {
378-
if (typeof key?.description !== "string" || !key?.description.endsWith("API")) continue;
379-
const symbolName = key.description;
380-
if (Object.hasOwn(Spicetify.Platform, symbolName)) continue;
381-
const resolvedAPI = Spicetify.Platform.Registry.resolve(key);
382-
if (!resolvedAPI) {
383-
console.warn(`[spicetifyWrapper] Failed to resolve PlatformAPI from Registry: ${symbolName}`);
384-
continue;
385-
}
386-
387-
Spicetify.Platform[symbolName] = resolvedAPI;
388-
console.debug(`[spicetifyWrapper] Resolved PlatformAPI from Registry: ${symbolName}`);
389-
}
390-
})();
391-
392401
(async function addProxyCosmos() {
393402
if (!Spicetify.Player.origin?._cosmos && !Spicetify.Platform?.Registry) {
394403
setTimeout(addProxyCosmos, 50);
@@ -413,7 +422,7 @@ applyScrollingFix();
413422

414423
if (typeof internalFetch !== "function" || !allowedMethodsSet.has(prop)) return internalFetch;
415424
const version = Spicetify.Platform.version.split(".").map((i) => Number.parseInt(i));
416-
if (version[0] === 1 && version[1] === 2 && version[2] < 31) return internalFetch;
425+
if (version[1] >= 2 && version[2] < 31) return internalFetch;
417426

418427
return async function (url, body) {
419428
const urlObj = new URL(url);
@@ -2247,7 +2256,7 @@ Spicetify.Topbar = (() => {
22472256
function waitForTopbarMounted() {
22482257
const globalHistoryButtons = document.querySelector(".main-globalNav-historyButtons");
22492258
leftGeneratedClassName = document.querySelector(
2250-
".main-topBar-historyButtons .main-topBar-button, .main-globalNav-historyButtons .main-globalNav-icon"
2259+
".main-topBar-historyButtons .main-topBar-button, .main-globalNav-historyButtons .main-globalNav-icon, .main-globalNav-historyButtons .e-9640-button-tertiary--condensed"
22512260
)?.className;
22522261
rightGeneratedClassName = document.querySelector(
22532262
".main-topBar-container .main-topBar-buddyFeed, .main-actionButtons .main-topBar-buddyFeed, .main-actionButtons .main-globalNav-buddyFeed"

0 commit comments

Comments
 (0)