11import type JsEnginePlugin from 'jsEngine/main' ;
22import { StartupScriptsModal } from 'jsEngine/settings/StartupScriptModal' ;
3- import type { App } from 'obsidian' ;
3+ import type { App , TFile } from 'obsidian' ;
44import { normalizePath , PluginSettingTab , Setting } from 'obsidian' ;
55
66declare module 'obsidian' {
@@ -27,9 +27,11 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
2727 this . plugin = plugin ;
2828 }
2929
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' ) ;
3335 }
3436
3537 display ( ) : void {
@@ -77,17 +79,16 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
7779
7880 void this . listJSfilesInDirectory ( settings . startupScriptsDirectory ) . then ( fileList =>
7981 fileList . forEach ( file => {
80- const fileName = file . split ( '/' ) . last ( ) ! ;
8182 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 } "` )
8485 . addToggle ( el => {
85- el . setValue ( settings . enabledStartupScripts . includes ( fileName ) )
86+ el . setValue ( settings . enabledStartupScripts . includes ( file . basename ) )
8687 . onChange ( async ( val : boolean ) => {
8788 if ( val ) {
88- settings . enabledStartupScripts . push ( fileName ) ;
89+ settings . enabledStartupScripts . push ( file . basename ) ;
8990 } else {
90- settings . enabledStartupScripts . remove ( fileName ) ;
91+ settings . enabledStartupScripts . remove ( file . basename ) ;
9192 }
9293 await this . plugin . saveSettings ( ) ;
9394 } ) ;
0 commit comments