fix(calc): stop calcLoop if graph is closed

This commit is contained in:
Kritagya Bhattarai (CalfMoon) 2025-03-10 18:01:08 +05:45
parent bdf1a746b2
commit 9155817954

View file

@ -5,6 +5,7 @@ import SampleSettingTab from "./settings";
export default class NodeFactor extends Plugin {
settings: NodeFactorSettings;
updateLoop: boolean;
async onload() {
await this.loadSettings();
@ -15,7 +16,11 @@ export default class NodeFactor extends Plugin {
const leaf = this.app.workspace
.getLeavesOfType("graph")
.first();
if (!leaf) return;
if (!leaf) {
this.updateLoop = false;
return;
}
this.updateLoop = true;
// @ts-ignore
const nodes: ObsidianNode[] = leaf.view.renderer.nodes;
@ -43,7 +48,7 @@ export default class NodeFactor extends Plugin {
const weight = this.calcNodeWeight(node, treeOptimizeMap);
node.weight = weight;
});
this.calcLoop(nodes);
if (this.updateLoop) this.calcLoop(nodes);
}, 10);
}