11//! Configuration management module
2- //!
2+ //!
33//! Handles application configuration loading, saving, and management.
44//! Supports platform-specific configuration directories and automatic
55//! configuration file creation.
66
7- use anyhow:: { bail, Context , Result } ;
7+ use crate :: slint_generatedAppWindow:: {
8+ SettingControl as UISettingControl , SettingRecorder as UISettingRecorder ,
9+ } ;
10+ use anyhow:: { Context , Result , bail} ;
811use log:: debug;
912use once_cell:: sync:: Lazy ;
13+ use pmacro:: SlintFromConvert ;
1014use serde:: { Deserialize , Serialize } ;
1115use std:: { fs, path:: PathBuf , sync:: Mutex } ;
1216use uuid:: Uuid ;
@@ -21,7 +25,7 @@ const CARGO_TOML: &str = include_str!("../Cargo.toml");
2125static CONFIG : Lazy < Mutex < Config > > = Lazy :: new ( || Mutex :: new ( Config :: default ( ) ) ) ;
2226
2327/// Android-specific application directories structure
24- ///
28+ ///
2529/// Provides platform-specific directory paths for Android applications.
2630#[ cfg( feature = "android" ) ]
2731pub struct AppDirs {
@@ -34,11 +38,11 @@ pub struct AppDirs {
3438#[ cfg( feature = "android" ) ]
3539impl AppDirs {
3640 /// Creates new Android application directories
37- ///
41+ ///
3842 /// # Parameters
3943 /// - `name`: Application package name
4044 /// - `_`: Compatibility parameter (unused)
41- ///
45+ ///
4246 /// # Returns
4347 /// - `Some(AppDirs)` if successful, `None` otherwise
4448 pub fn new ( name : Option < & str > , _: bool ) -> Option < Self > {
@@ -53,7 +57,7 @@ impl AppDirs {
5357}
5458
5559/// Main configuration structure containing all application settings
56- ///
60+ ///
5761/// Includes paths, preferences, proxy settings, and AI model configurations.
5862#[ derive( Serialize , Deserialize , Default , Debug , Clone ) ]
5963pub struct Config {
@@ -76,17 +80,17 @@ pub struct Config {
7680 pub appid : String ,
7781
7882 pub preference : Preference ,
79- pub proxy : Proxy ,
80- pub ai_model : AiModel ,
83+ pub recorder : Recorder ,
84+ pub control : Control ,
8185}
8286
8387/// User preference settings for the application
84- ///
88+ ///
8589/// Contains window settings, font preferences, language, and UI options.
8690#[ derive( Serialize , Deserialize , Debug , Clone , Derivative ) ]
8791#[ derivative( Default ) ]
8892pub struct Preference {
89- #[ derivative( Default ( value = "1200 " ) ) ]
93+ #[ derivative( Default ( value = "1000 " ) ) ]
9094 pub win_width : u32 ,
9195
9296 #[ derivative( Default ( value = "800" ) ) ]
@@ -110,40 +114,38 @@ pub struct Preference {
110114 pub is_dark : bool ,
111115}
112116
113- /// Proxy configuration settings
114- ///
115- /// Supports both HTTP and SOCKS5 proxy configurations.
116- #[ derive( Serialize , Deserialize , Debug , Clone , Derivative ) ]
117+ #[ derive( Serialize , Deserialize , Default , Debug , Clone , SlintFromConvert ) ]
118+ #[ from( "UISettingRecorder" ) ]
119+ pub struct Recorder {
120+ pub save_dir : String ,
121+ pub remove_temporary_files : bool ,
122+ }
123+
124+ #[ derive( Serialize , Deserialize , Debug , Clone , Derivative , SlintFromConvert ) ]
117125#[ derivative( Default ) ]
118- pub struct Proxy {
119- #[ derivative( Default ( value = "\" 127.0.0.1\" .to_string()" ) ) ]
120- pub http_url : String ,
126+ #[ from( "UISettingControl" ) ]
127+ pub struct Control {
128+ pub screen : String ,
129+ pub input_audio : String ,
121130
122- #[ derivative( Default ( value = "3128 " ) ) ]
123- pub http_port : u16 ,
131+ #[ derivative( Default ( value = "100.0 " ) ) ]
132+ pub input_audio_sound : f32 ,
124133
125- #[ derivative( Default ( value = "\" 127.0.0.1 \" .to_string() " ) ) ]
126- pub socks5_url : String ,
134+ #[ derivative( Default ( value = "true " ) ) ]
135+ pub enable_input_audio : bool ,
127136
128- #[ derivative( Default ( value = "1080" ) ) ]
129- pub socks5_port : u16 ,
130- }
137+ #[ derivative( Default ( value = "100.0" ) ) ]
138+ pub desktop_speaker_sound : f32 ,
131139
132- /// AI model configuration settings
133- ///
134- /// Contains API endpoints, model names, and authentication keys for AI services.
135- #[ derive( Serialize , Deserialize , Debug , Clone , Default ) ]
136- pub struct AiModel {
137- pub api_base_url : String ,
138- pub model_name : String ,
139- pub api_key : String ,
140+ #[ derivative( Default ( value = "true" ) ) ]
141+ pub enable_desktop_speaker : bool ,
140142}
141143
142144impl Config {
143145 /// Initializes the configuration
144- ///
146+ ///
145147 /// Loads package metadata, creates directories, and loads configuration file.
146- ///
148+ ///
147149 /// # Returns
148150 /// - `Result<()>` indicating success or failure
149151 pub fn init ( & mut self ) -> Result < ( ) > {
@@ -183,10 +185,10 @@ impl Config {
183185 }
184186
185187 /// Creates application directories and sets up paths
186- ///
188+ ///
187189 /// # Parameters
188190 /// - `app_dirs`: Platform-specific application directories
189- ///
191+ ///
190192 /// # Returns
191193 /// - `Result<()>` indicating success or failure
192194 fn crate_dirs ( & mut self , app_dirs : & AppDirs ) -> Result < ( ) > {
@@ -206,7 +208,7 @@ impl Config {
206208 }
207209
208210 /// Loads configuration from file or creates default if not exists
209- ///
211+ ///
210212 /// # Returns
211213 /// - `Result<()>` indicating success or failure
212214 fn load ( & mut self ) -> Result < ( ) > {
@@ -252,7 +254,7 @@ impl Config {
252254 }
253255
254256 /// Saves the current configuration to file
255- ///
257+ ///
256258 /// # Returns
257259 /// - `Result<()>` indicating success or failure
258260 pub fn save ( & self ) -> Result < ( ) > {
@@ -265,33 +267,33 @@ impl Config {
265267}
266268
267269/// Generates a default application ID using UUID v4
268- ///
270+ ///
269271/// # Returns
270272/// - Random UUID string
271273fn appid_default ( ) -> String {
272274 Uuid :: new_v4 ( ) . to_string ( )
273275}
274276
275277/// Initializes the global configuration
276- ///
278+ ///
277279/// This should be called once at application startup.
278280pub fn init ( ) {
279281 CONFIG . lock ( ) . unwrap ( ) . init ( ) . unwrap ( ) ;
280282}
281283
282284/// Returns a clone of the current configuration
283- ///
285+ ///
284286/// # Returns
285287/// - Current configuration instance
286288pub fn all ( ) -> Config {
287289 CONFIG . lock ( ) . unwrap ( ) . clone ( )
288290}
289291
290292/// Saves a new configuration and updates the global instance
291- ///
293+ ///
292294/// # Parameters
293295/// - `conf`: New configuration to save
294- ///
296+ ///
295297/// # Returns
296298/// - `Result<()>` indicating success or failure
297299pub fn save ( conf : Config ) -> Result < ( ) > {
0 commit comments