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