1
1
import type JsEnginePlugin from 'jsEngine/main' ;
2
2
import { StartupScriptsModal } from 'jsEngine/settings/StartupScriptModal' ;
3
- import type { App } from 'obsidian' ;
3
+ import type { App , TFile } from 'obsidian' ;
4
4
import { normalizePath , PluginSettingTab , Setting } from 'obsidian' ;
5
5
6
6
declare module 'obsidian' {
@@ -27,9 +27,11 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
27
27
this . plugin = plugin ;
28
28
}
29
29
30
- private async listJSfilesInDirectory ( directory : string ) : Promise < string [ ] > {
31
- const { adapter } = this . app . vault ;
32
- return ( await adapter . list ( directory ) ) . files . filter ( file => file . endsWith ( '.js' ) ) ;
30
+ private async listJSfilesInDirectory ( directory : string ) : Promise < TFile [ ] > {
31
+ const { vault } = this . app ;
32
+ return ( await vault . adapter . list ( directory ) ) . files
33
+ . map ( file => vault . getFileByPath ( file ) ! )
34
+ . filter ( file => file . extension == 'js' ) ;
33
35
}
34
36
35
37
display ( ) : void {
@@ -77,17 +79,16 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
77
79
78
80
void this . listJSfilesInDirectory ( settings . startupScriptsDirectory ) . then ( fileList =>
79
81
fileList . forEach ( file => {
80
- const fileName = file . split ( '/' ) . last ( ) ! ;
81
82
new Setting ( containerEl )
82
- . setName ( fileName )
83
- . setDesc ( `Apply JS snippet from "vault/${ file } "` )
83
+ . setName ( file . basename )
84
+ . setDesc ( `Apply JS snippet from "vault/${ file . path } "` )
84
85
. addToggle ( el => {
85
- el . setValue ( settings . enabledStartupScripts . includes ( fileName ) )
86
+ el . setValue ( settings . enabledStartupScripts . includes ( file . basename ) )
86
87
. onChange ( async ( val : boolean ) => {
87
88
if ( val ) {
88
- settings . enabledStartupScripts . push ( fileName ) ;
89
+ settings . enabledStartupScripts . push ( file . basename ) ;
89
90
} else {
90
- settings . enabledStartupScripts . remove ( fileName ) ;
91
+ settings . enabledStartupScripts . remove ( file . basename ) ;
91
92
}
92
93
await this . plugin . saveSettings ( ) ;
93
94
} ) ;
0 commit comments