@@ -9,6 +9,7 @@ export default class TimeTreePlugin extends Plugin {
99 public settings : TimeTreeSettings ;
1010 private frontMatterManager : FrontMatterManager ;
1111 private calculator : TimeTreeCalculator ;
12+ private computeIntervalHandle : any ;
1213
1314 async onload ( ) : Promise < void > {
1415 await this . loadSettings ( ) ;
@@ -45,6 +46,14 @@ export default class TimeTreePlugin extends Plugin {
4546 this . insertNewTask ( editor ) ;
4647 } ,
4748 } ) ;
49+
50+ this . scheduleComputeTimeTree ( ) ;
51+ }
52+
53+ onunload ( ) : void {
54+ if ( this . computeIntervalHandle ) {
55+ clearInterval ( this . computeIntervalHandle ) ;
56+ }
4857 }
4958
5059 async loadSettings ( ) : Promise < void > {
@@ -57,6 +66,7 @@ export default class TimeTreePlugin extends Plugin {
5766
5867 async saveSettings ( ) : Promise < void > {
5968 await this . saveData ( this . settings ) ;
69+ this . scheduleComputeTimeTree ( ) ;
6070 }
6171
6272 async elapsedTime ( ) : Promise < void > {
@@ -90,12 +100,17 @@ export default class TimeTreePlugin extends Plugin {
90100 new Notice ( `Root note ${ rootPath } not found.` ) ;
91101 return ;
92102 }
93- await this . calculator . calculateRecursiveElapsedTime ( rootFile ) ;
94- await this . calculator . calculateRecursiveElapsedChild ( rootFile ) ;
95- await this . calculator . updateNodeSizeFromFile ( rootFile ) ;
96- new Notice (
97- `Time Tree computed recursively from root note: ${ rootPath } `
98- ) ;
103+
104+ // Show a persistent loading notification
105+ const loadingNotice = new Notice ( "Computing Time Tree..." , 0 ) ;
106+ try {
107+ await this . calculator . calculateRecursiveElapsedTime ( rootFile ) ;
108+ await this . calculator . calculateRecursiveElapsedChild ( rootFile ) ;
109+ await this . calculator . updateNodeSizeFromFile ( rootFile ) ;
110+ new Notice ( `Time Tree computed from note: ${ rootPath } ` , 1000 ) ;
111+ } finally {
112+ loadingNotice . hide ( ) ;
113+ }
99114 }
100115
101116 async insertNewTask ( editor : Editor ) : Promise < void > {
@@ -113,4 +128,18 @@ export default class TimeTreePlugin extends Plugin {
113128 editor . replaceRange ( textToInsert , cursor ) ;
114129 editor . setCursor ( { line : cursor . line , ch : cursor . ch + 4 } ) ;
115130 }
131+
132+ scheduleComputeTimeTree ( ) : void {
133+ // Clear any existing interval
134+ if ( this . computeIntervalHandle ) {
135+ clearInterval ( this . computeIntervalHandle ) ;
136+ }
137+ // Only schedule if the compute interval is greater than 0 (enabled)
138+ if ( this . settings . computeIntervalMinutes > 0 ) {
139+ const intervalMs = this . settings . computeIntervalMinutes * 60 * 1000 ;
140+ this . computeIntervalHandle = setInterval ( async ( ) => {
141+ await this . computeTimeTree ( ) ;
142+ } , intervalMs ) ;
143+ }
144+ }
116145}
0 commit comments