1
- import { App , TAbstractFile , TFile } from "obsidian" ;
2
1
import type { Moment } from "moment" ;
3
- import { get , Writable , writable } from "svelte/store " ;
2
+ import { App , Plugin , TAbstractFile , TFile } from "obsidian " ;
4
3
import {
5
4
getAllDailyNotes ,
6
5
getAllMonthlyNotes ,
@@ -10,6 +9,7 @@ import {
10
9
getDateUID ,
11
10
IGranularity ,
12
11
} from "obsidian-daily-notes-interface" ;
12
+ import { get , Writable , writable } from "svelte/store" ;
13
13
14
14
import type { ICalendarSource , IDayMetadata , ISourceSettings } from "./types" ;
15
15
@@ -46,24 +46,28 @@ export default class PeriodicNotesCache {
46
46
public store : Writable < Record < PeriodicNoteID , TFile > > ;
47
47
private sources : ICalendarSource [ ] ;
48
48
49
- constructor ( app : App , sources : ICalendarSource [ ] ) {
50
- this . app = app ;
49
+ constructor ( plugin : Plugin , sources : ICalendarSource [ ] ) {
50
+ this . app = plugin . app ;
51
51
this . sources = sources ;
52
52
this . store = writable < Record < PeriodicNoteID , TFile > > ( { } ) ;
53
53
54
- // TODO register this to plugin
55
- app . workspace . onLayoutReady ( ( ) => {
56
- app . vault . on ( "create" , this . onFileCreated . bind ( this ) ) ;
57
- app . vault . on ( "delete" , this . onFileDeleted . bind ( this ) ) ;
58
- app . vault . on ( "rename" , this . onFileRenamed . bind ( this ) ) ;
59
- app . vault . on ( "modify" , this . onFileModified . bind ( this ) ) ;
54
+ plugin . app . workspace . onLayoutReady ( ( ) => {
55
+ const { vault } = this . app ;
56
+ plugin . registerEvent ( vault . on ( "create" , this . onFileCreated , this ) ) ;
57
+ plugin . registerEvent ( vault . on ( "delete" , this . onFileDeleted , this ) ) ;
58
+ plugin . registerEvent ( vault . on ( "rename" , this . onFileRenamed , this ) ) ;
59
+ plugin . registerEvent ( vault . on ( "modify" , this . onFileModified , this ) ) ;
60
60
this . initialize ( ) ;
61
61
} ) ;
62
62
63
63
// eslint-disable-next-line @typescript-eslint/no-explicit-any
64
- const workspace = app . workspace as any ;
65
- workspace . on ( "periodic-notes:settings-updated" , this . initialize , this ) ;
66
- workspace . on ( "calendar:metadata-updated" , this . initialize , this ) ;
64
+ const workspace = this . app . workspace as any ;
65
+ plugin . registerEvent (
66
+ workspace . on ( "periodic-notes:settings-updated" , this . initialize , this )
67
+ ) ;
68
+ plugin . registerEvent (
69
+ workspace . on ( "calendar:metadata-updated" , this . initialize , this )
70
+ ) ;
67
71
}
68
72
69
73
public onFileCreated ( file : TAbstractFile ) : void {
0 commit comments