11import type JsEnginePlugin from 'jsEngine/main' ;
22import { StartupScriptsModal } from 'jsEngine/settings/StartupScriptModal' ;
33import type { App } from 'obsidian' ;
4- import { normalizePath , PluginSettingTab , Setting } from 'obsidian' ;
4+ import { normalizePath , PluginSettingTab , Setting , TFile } from 'obsidian' ;
55
66declare module 'obsidian' {
77 interface App {
@@ -27,9 +27,12 @@ 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+ const { adapter } = vault ;
33+ return ( await adapter . list ( directory ) ) . files
34+ . map ( file => vault . getFileByPath ( file ) ! )
35+ . filter ( file => file . extension == 'js' ) ;
3336 }
3437
3538 display ( ) : void {
@@ -77,20 +80,18 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
7780
7881 void this . listJSfilesInDirectory ( settings . startupScriptsDirectory ) . then ( fileList =>
7982 fileList . forEach ( file => {
80- const fileName = file . split ( '/' ) . last ( ) ! ;
8183 new Setting ( containerEl )
82- . setName ( fileName )
83- . setDesc ( `Apply JS snippet from "vault/${ file } "` )
84+ . setName ( file . basename )
85+ . setDesc ( `Apply JS snippet from "vault/${ file . path } "` )
8486 . addToggle ( el => {
85- el . setValue ( settings . enabledStartupScripts . includes ( fileName ) )
86- . onChange ( async ( val : boolean ) => {
87- if ( val ) {
88- settings . enabledStartupScripts . push ( fileName ) ;
89- } else {
90- settings . enabledStartupScripts . remove ( fileName ) ;
91- }
92- await this . plugin . saveSettings ( ) ;
93- } ) ;
87+ el . setValue ( settings . enabledStartupScripts . includes ( file . basename ) ) . onChange ( async ( val : boolean ) => {
88+ if ( val ) {
89+ settings . enabledStartupScripts . push ( file . basename ) ;
90+ } else {
91+ settings . enabledStartupScripts . remove ( file . basename ) ;
92+ }
93+ await this . plugin . saveSettings ( ) ;
94+ } ) ;
9495 } ) ;
9596 } ) ,
9697 ) ;
0 commit comments