@@ -3,20 +3,29 @@ use crate::plugin::PluginManagerState;
33use crate :: plugins:: PluginConfig ;
44use log:: { info, warn} ;
55use serde:: { Deserialize , Serialize } ;
6+ use serde_json:: Value :: Bool ;
67use std:: fs;
78use std:: path:: PathBuf ;
89use std:: sync:: Mutex ;
910use tauri:: { AppHandle , Manager , command} ;
1011
1112static CONFIG_MANAGER : Mutex < Option < ConfigManager > > = Mutex :: new ( None ) ;
1213
14+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
15+ pub struct EditorConfig {
16+ pub indent_with_tab : Option < bool > , // 是否使用 tab 缩进
17+ pub tab_size : Option < u32 > , // tab 缩进, 空格数,默认为 2
18+ pub theme : Option < String > , // 编辑器主题
19+ }
20+
1321#[ derive( Debug , Clone , Serialize , Deserialize ) ]
1422pub struct AppConfig {
1523 pub log_directory : Option < String > ,
1624 pub auto_clear_logs : Option < bool > ,
1725 pub keep_log_days : Option < u32 > ,
1826 pub theme : Option < String > ,
1927 pub plugins : Option < Vec < PluginConfig > > ,
28+ pub editor : Option < EditorConfig > ,
2029}
2130
2231impl Default for AppConfig {
@@ -27,6 +36,11 @@ impl Default for AppConfig {
2736 keep_log_days : Some ( 30 ) ,
2837 theme : Some ( "system" . to_string ( ) ) ,
2938 plugins : Some ( vec ! [ ] ) ,
39+ editor : Some ( EditorConfig {
40+ indent_with_tab : Some ( true ) ,
41+ tab_size : Some ( 2 ) ,
42+ theme : Some ( "githubLight" . to_string ( ) ) ,
43+ } ) ,
3044 }
3145 }
3246}
@@ -75,6 +89,16 @@ impl ConfigManager {
7589 // 合并插件配置(现有配置 + 默认配置中缺失的插件)
7690 config. plugins = Self :: merge_plugins_config ( config. plugins , app_handle) ;
7791
92+ // 检查并设置 editor 默认配置
93+ if config. editor . is_none ( ) {
94+ config. editor = Some ( EditorConfig {
95+ indent_with_tab : Some ( true ) ,
96+ tab_size : Some ( 2 ) ,
97+ theme : Some ( "githubLight" . to_string ( ) ) ,
98+ } ) ;
99+ println ! ( "读取配置 -> 添加默认 editor 配置" ) ;
100+ }
101+
78102 Ok ( config)
79103 }
80104 Err ( e) => {
@@ -170,6 +194,11 @@ impl ConfigManager {
170194 keep_log_days : Some ( 30 ) ,
171195 theme : Some ( "system" . to_string ( ) ) ,
172196 plugins : Self :: get_default_plugins_config ( app_handle) ,
197+ editor : Some ( EditorConfig {
198+ indent_with_tab : Some ( true ) ,
199+ tab_size : Some ( 2 ) ,
200+ theme : Some ( "githubLight" . to_string ( ) ) ,
201+ } ) ,
173202 }
174203 }
175204
0 commit comments