@@ -10,12 +10,12 @@ import {
1010} from "obsidian" ;
1111
1212// Define the constant for the ClockView type
13- const ClockViewType = "my-clock-view " ;
13+ const ClockViewType = "tokei " ;
1414
1515// Define the ClockView class that extends ItemView
1616class ClockView extends ItemView {
1717 private readonly plugin : ClockPlugin ;
18- private updateInterval : NodeJS . Timeout | null = null ;
18+ private updateInterval : number | null = null ;
1919 // Container elements for time, date, and timezone
2020 private timeDateContainer : HTMLElement ;
2121 private timezoneContainer : HTMLElement ;
@@ -35,13 +35,13 @@ class ClockView extends ItemView {
3535 // Called when the view is opened
3636 public async onOpen ( ) : Promise < void > {
3737 this . displayTime ( ) ;
38- this . updateInterval = setInterval ( this . displayTime . bind ( this ) , 1000 ) ;
38+ this . updateInterval = window . setInterval ( this . displayTime . bind ( this ) , 1000 ) ;
3939 }
4040
4141 // Called when the view is closed
4242 public onClose ( ) : Promise < void > {
43- if ( this . updateInterval ) {
44- clearInterval ( this . updateInterval ) ;
43+ if ( this . updateInterval !== null ) {
44+ window . clearInterval ( this . updateInterval ) ;
4545 this . updateInterval = null ;
4646 }
4747 return super . onClose ( ) ;
@@ -269,43 +269,30 @@ export default class ClockPlugin extends Plugin {
269269 DEFAULT_SETTINGS ,
270270 await this . loadData ( )
271271 ) ;
272-
272+
273273 this . registerView (
274274 ClockViewType ,
275275 ( leaf ) => ( this . view = new ClockView ( leaf , this ) )
276276 ) ;
277-
277+
278278 this . addCommand ( {
279279 id : "open" ,
280280 name : "open" ,
281281 callback : this . onShow . bind ( this ) ,
282282 } ) ;
283-
284- let isViewInitialized = false ;
285-
286- const checkLayoutInterval = setInterval ( async ( ) => {
287- if ( this . app . workspace . layoutReady && ! isViewInitialized ) {
288- await this . initView ( ) ;
289- isViewInitialized = true ;
290- clearInterval ( checkLayoutInterval ) ;
291- }
292- } , 1000 ) ;
293-
283+
294284 this . app . workspace . onLayoutReady ( async ( ) => {
295- if ( ! isViewInitialized ) {
296- await this . initView ( ) ;
297- isViewInitialized = true ;
298- clearInterval ( checkLayoutInterval ) ;
299- }
285+ await this . initView ( ) ;
300286 } ) ;
301-
287+
302288 this . addSettingTab ( new ClockSettingTab ( this . app , this ) ) ;
303289 }
290+
304291
305292 // Clear the update interval when the plugin is unloaded
306293 public onunload ( ) : void {
307- if ( this . updateInterval ) {
308- clearInterval ( this . updateInterval ) ;
294+ if ( this . updateInterval !== null ) {
295+ window . clearInterval ( this . updateInterval ) ;
309296 this . updateInterval = null ;
310297 }
311298 }
@@ -381,10 +368,9 @@ class ClockSettingTab extends PluginSettingTab {
381368 donateImage . src =
382369 "https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" ;
383370 donateImage . alt = "Buy Me A Coffee" ;
384- rotateColorRandomly ( donateImage ) ;
385- donateImage . style . height = "60px" ;
386- donateImage . style . width = "217px" ;
387371
372+ rotateColorRandomly ( donateImage ) ;
373+ donateImage . classList . add ( 'donate-img' ) ;
388374 donateLink . appendChild ( donateImage ) ;
389375 donateText . appendChild ( donateLink ) ;
390376
@@ -468,7 +454,7 @@ class ClockSettingTab extends PluginSettingTab {
468454 await this . plugin . saveSettings ( ) ;
469455
470456 const clockView = this . app . workspace
471- . getLeavesOfType ( "my-clock-view " )
457+ . getLeavesOfType ( "tokei " )
472458 . find ( ( leaf ) => leaf . view instanceof ClockView ) ;
473459 if ( clockView ) {
474460 ( clockView . view as ClockView ) . displayTime ( ) ;
@@ -674,7 +660,7 @@ class ClockSettingTab extends PluginSettingTab {
674660 await this . plugin . saveSettings ( ) ;
675661
676662 const clockView = this . app . workspace
677- . getLeavesOfType ( "my-clock-view " )
663+ . getLeavesOfType ( "tokei " )
678664 . find ( ( leaf ) => leaf . view instanceof ClockView ) ;
679665 if ( clockView ) {
680666 // Update the clock immediately
0 commit comments