fix(main): keep prefs.mode in sync and rAF-coalesce mutation observer
This commit is contained in:
@@ -27,6 +27,7 @@ function start() {
|
||||
},
|
||||
onModeChange: (m) => {
|
||||
store.setMode(m);
|
||||
prefs.mode = m;
|
||||
applyMode();
|
||||
},
|
||||
onPosChange: (pos) => store.setPos(pos),
|
||||
@@ -85,10 +86,16 @@ function start() {
|
||||
render();
|
||||
|
||||
// watch DOM for attribute changes
|
||||
let pending = false;
|
||||
const observer = new MutationObserver(() => {
|
||||
if (pending) return;
|
||||
pending = true;
|
||||
requestAnimationFrame(() => {
|
||||
pending = false;
|
||||
const a = currentAttribute();
|
||||
if (a && (a.attr !== lastAttr || a.current !== lastSnapshot?.current)) render();
|
||||
});
|
||||
});
|
||||
observer.observe(document.body, { childList: true, subtree: true, characterData: true });
|
||||
|
||||
// intercept train requests
|
||||
|
||||
Reference in New Issue
Block a user