From 91558179548e299696c4e6aec5227d7252c6c43d Mon Sep 17 00:00:00 2001 From: "Kritagya Bhattarai (CalfMoon)" Date: Mon, 10 Mar 2025 18:01:08 +0545 Subject: [PATCH] fix(calc): stop calcLoop if graph is closed --- src/main.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 00cdc76..688bd16 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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); }