Skip to content

Commit

Permalink
fix(wrapper): use History.listen event instead of the observer (#2826)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri authored Feb 14, 2024
1 parent d8adb2e commit 6f28790
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
1 change: 1 addition & 0 deletions css-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
"ATUzFKub89lzvkmvhpyE": "main-navBar-navBarLink",
"moDRd9td0KtitPDzR7OJ": "main-navBar-navBarLinkActive",
"GTAFfOA_w5vh_bDaGJAG": "main-noConnection",
"NPvLJSRWfv1Joo8dF0D8": "main-noConnection",
"WIGgdAaAzrXm7f_loaXi": "main-noConnection-button",
"vQNZsbpzoUFSW5fsFOAw": "main-notificationBubble-NotificationBubble",
"ZKFK00olAYy6LtYMjEIa": "main-notificationBubble-enter",
Expand Down
22 changes: 4 additions & 18 deletions jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,6 @@ Object.defineProperty(Spicetify, "TippyProps", {
Spicetify.Topbar = (() => {
let leftContainer;
let rightContainer;
let timeout;
const leftButtonsStash = new Set();
const rightButtonsStash = new Set();

Expand Down Expand Up @@ -1979,25 +1978,12 @@ Spicetify.Topbar = (() => {
}

waitForTopbarMounted();
(function attachObserver() {
if (timeout) clearTimeout(timeout);
const topBar = document.querySelector(".main-topBar-container");
if (!topBar) {
setTimeout(attachObserver, 100);
(function waitForPlatform() {
if (!Spicetify.Platform?.History) {
setTimeout(waitForPlatform, 100);
return;
}
const observer = new MutationObserver(mutations => {
for (const mutation of mutations) {
if (mutation.removedNodes.length > 0) {
leftContainer = null;
rightContainer = null;
waitForTopbarMounted();
observer.disconnect();
timeout = setTimeout(attachObserver, 300);
}
}
});
observer.observe(topBar, { childList: true, subtree: true });
Spicetify.Platform.History.listen(() => waitForTopbarMounted());
})();

return { Button };
Expand Down

0 comments on commit 6f28790

Please sign in to comment.