1- import { Plugin , TFile , Notice , Editor } from "obsidian" ;
1+ import {
2+ Plugin ,
3+ TFile ,
4+ Notice ,
5+ Editor ,
6+ MarkdownSectionInformation ,
7+ ButtonComponent ,
8+ } from "obsidian" ;
29import { defaultSettings , TimeTreeSettings } from "./settings" ;
310import { TimeTreeSettingsTab } from "./settings-tab" ;
411import { FrontMatterManager } from "./front-matter-manager" ;
@@ -23,6 +30,14 @@ export default class TimeTreePlugin extends Plugin {
2330
2431 this . addSettingTab ( new TimeTreeSettingsTab ( this . app , this ) ) ;
2532
33+ this . addCommand ( {
34+ id : "start-stop" ,
35+ name : "Start/Stop Tracker" ,
36+ callback : async ( ) => {
37+ await this . startStopTracker ( ) ;
38+ } ,
39+ } ) ;
40+
2641 this . addCommand ( {
2742 id : "elapsed-time" ,
2843 name : "Update elapsed time of the current note" ,
@@ -40,9 +55,9 @@ export default class TimeTreePlugin extends Plugin {
4055 } ) ;
4156
4257 this . addCommand ( {
43- id : "new -task" ,
44- name : "Insert new task " ,
45- editorCallback : ( editor , view ) => {
58+ id : "sub -task" ,
59+ name : "Insert subtask " ,
60+ editorCallback : ( editor , _ ) => {
4661 this . insertNewTask ( editor ) ;
4762 } ,
4863 } ) ;
@@ -69,13 +84,25 @@ export default class TimeTreePlugin extends Plugin {
6984 this . scheduleComputeTimeTree ( ) ;
7085 }
7186
87+ async startStopTracker ( ) : Promise < void > {
88+ const btn = document . querySelector (
89+ ".simple-time-tracker-btn"
90+ ) as HTMLButtonElement | null ;
91+ if ( btn ) {
92+ btn . click ( ) ;
93+ } else {
94+ new Notice ( "No Start/Stop button found." ) ;
95+ }
96+ }
97+
7298 async elapsedTime ( ) : Promise < void > {
7399 const activeFile = this . app . workspace . getActiveFile ( ) ;
74100 if ( ! activeFile ) {
75101 new Notice ( "No active file found." ) ;
76102 return ;
77103 }
78- const elapsed = await this . calculator . calculateElapsedTime ( activeFile ) ;
104+ let elapsed = 0 ;
105+ elapsed = await this . calculator . calculateElapsedTime ( activeFile ) ;
79106 await this . calculator . communicateAscendants ( activeFile ) ;
80107 const rootPath = this . settings . rootNotePath ;
81108 if ( rootPath ) {
0 commit comments