11import type JsEnginePlugin from 'jsEngine/main' ;
22import type { App } from 'obsidian' ;
3- import { PluginSettingTab , Setting } from 'obsidian' ;
3+ import { normalizePath , PluginSettingTab , Setting } from 'obsidian' ;
44
55export interface JsEnginePluginSettings {
6- startupScripts ?: string [ ] ;
6+ startupScriptsDirectory : string | undefined ;
7+ startupScripts : string [ ] ;
78}
89
910export const JS_ENGINE_DEFAULT_SETTINGS : JsEnginePluginSettings = {
11+ startupScriptsDirectory : undefined ,
1012 startupScripts : [ ] ,
1113} ;
1214
@@ -26,5 +28,35 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
2628 if ( ! settings ) {
2729 return ;
2830 }
31+
32+ new Setting ( containerEl )
33+ . setName ( 'JS snippets (loaded on startup)' )
34+ . setHeading ( )
35+ . addExtraButton ( el => {
36+ el . setTooltip ( 'Open snippets folder' )
37+ . setIcon ( 'folder-open' )
38+ . onClick ( async ( ) => await this . openStartupScriptsDirectory ( ) ) ;
39+ } ) ;
40+
41+ new Setting ( containerEl )
42+ . setName ( 'Custom JS Snippets Folder' )
43+ . setDesc ( 'The folder to search for JavaScript files to load' )
44+ . addText ( el => {
45+ el . setPlaceholder ( 'Folder' )
46+ . setValue ( settings . startupScriptsDirectory ?? '' )
47+ . onChange ( async val => {
48+ settings . startupScriptsDirectory = val ? normalizePath ( val ) : undefined ;
49+ await this . plugin . saveSettings ( ) ;
50+ } ) ;
51+ } ) ;
52+ }
53+
54+ async openStartupScriptsDirectory ( ) : Promise < void > {
55+ const vault = this . app . vault ;
56+ const directory = this . plugin . settings . startupScriptsDirectory ?? '/' ;
57+ if ( ! ( await vault . adapter . exists ( directory ) ) ) {
58+ await vault . createFolder ( directory ) ;
59+ }
60+ this . app . openWithDefaultApp ( directory ) ;
2961 }
3062}
0 commit comments