Skip to content

Commit

Permalink
revert: remove outdated attachObserver function (#2801)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri authored Feb 2, 2024
1 parent 50835b7 commit 27f15b4
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,7 @@ Object.defineProperty(Spicetify, "TippyProps", {
Spicetify.Topbar = (() => {
let leftContainer;
let rightContainer;
let timeout;
const leftButtonsStash = new Set();
const rightButtonsStash = new Set();

Expand Down Expand Up @@ -2053,15 +2054,37 @@ Spicetify.Topbar = (() => {
}
}

(function waitForTopbarMounted() {
function waitForTopbarMounted() {
leftContainer = document.querySelector(".main-topBar-historyButtons");
rightContainer = document.querySelector(".main-noConnection");
if (!leftContainer || !rightContainer) {
setTimeout(waitForTopbarMounted, 300);
setTimeout(waitForTopbarMounted, 100);
return;
}
leftContainer.append(...leftButtonsStash);
rightContainer.after(...rightButtonsStash);
}

waitForTopbarMounted();
(function attachObserver() {
if (timeout) clearTimeout(timeout);
const topBar = document.querySelector(".main-topBar-container");
if (!topBar) {
setTimeout(attachObserver, 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 });
})();

return { Button };
Expand Down

0 comments on commit 27f15b4

Please sign in to comment.