11import { Plugin , TFile , type App , type PluginManifest } from 'obsidian' ;
22import { SETTINGS_UPDATED } from './events' ;
33import { Inbox } from './inbox' ;
4+ import debug from './log' ;
45import { OrganiserModal } from './modal' ;
56import { OrganiserNotice } from './notice' ;
67import { DEFAULT_SETTINGS , ISettings } from './settings' ;
@@ -32,8 +33,18 @@ export default class InboxOrganiser extends Plugin {
3233
3334 onLayoutReady ( ) : void {
3435 this . registerEvent ( this . app . vault . on ( 'create' , ( file ) => {
35- if ( file instanceof TFile && file . path . indexOf ( '/' ) === - 1 ) {
36- this . watcher . notify ( file ) ;
36+ if ( file instanceof TFile ) {
37+ // Root needs a special case as it will not match the start of the file path
38+ if ( this . settings . watchFolder === '/' && file . path . indexOf ( '/' ) === - 1 ) {
39+ this . watcher . notify ( file ) ;
40+ }
41+ // Ensure sub-folders are ignored correctly
42+ if (
43+ file . path . indexOf ( this . settings . watchFolder + '/' ) === 0
44+ && file . path . split ( '/' ) . length === this . settings . watchFolder . split ( '/' ) . length + 1
45+ ) {
46+ this . watcher . notify ( file ) ;
47+ }
3748 }
3849 } ) ) ;
3950
@@ -42,7 +53,7 @@ export default class InboxOrganiser extends Plugin {
4253 } , 300000 ) ) ;
4354 ( new OrganiserNotice ( this , this . modal , this . inbox ) ) . display ( ) ;
4455
45- this . addSettingTab ( new InboxOrganiserTab ( this . app , this ) ) ;
56+ this . addSettingTab ( new InboxOrganiserTab ( this . app , this , this . inbox ) ) ;
4657
4758 this . addCommand ( {
4859 id : 'inbox-organiser' ,
@@ -63,17 +74,20 @@ export default class InboxOrganiser extends Plugin {
6374 DEFAULT_SETTINGS ,
6475 await this . loadData ( )
6576 ) ;
77+ debug ( 'Loaded settings: ' + JSON . stringify ( this . settings ) ) ;
6678 }
6779
6880 async updateSettings ( settings : ISettings ) : Promise < void > {
6981 this . settings = settings ;
7082 await this . saveData ( settings ) ;
7183 this . onSettingsUpdate ( ) ;
84+ debug ( 'Saved settings: ' + JSON . stringify ( this . settings ) ) ;
7285 }
7386
7487 private onSettingsUpdate ( ) : void {
7588 const inboxFolder = this . app . vault . getFolderByPath ( INBOX_FOLDER ) ;
7689 if ( this . settings . inbox && ! inboxFolder ) {
90+ debug ( 'Creating missing inbox folder' ) ;
7791 this . app . vault . createFolder ( INBOX_FOLDER ) ;
7892 }
7993
0 commit comments