@@ -34,9 +34,10 @@ const MANAGED_MODEL_FILES: &[&str] = &[
3434 "vocab.json" ,
3535] ;
3636const PYANNOTE_RUNNER_RELATIVE_PATH : & str = "scripts/pyannote_diarize.py" ;
37- const GENERAL_SETTINGS_FILE : & str = "general-settings.json" ;
38- const MODEL_SETTINGS_FILE : & str = "model-settings.json" ;
39- const DIARIZATION_SETTINGS_FILE : & str = "diarization-settings.json" ;
37+ const SETTINGS_CONFIG_FILE : & str = "settings.json" ;
38+ const LEGACY_GENERAL_SETTINGS_FILE : & str = "general-settings.json" ;
39+ const LEGACY_MODEL_SETTINGS_FILE : & str = "model-settings.json" ;
40+ const LEGACY_DIARIZATION_SETTINGS_FILE : & str = "diarization-settings.json" ;
4041const OPEN_SETTINGS_MENU_ID : & str = "open-settings" ;
4142const SETTINGS_WINDOW_LABEL : & str = "settings" ;
4243const PYANNOTE_PROVIDER_LABEL : & str = "pyannote.audio" ;
@@ -159,6 +160,17 @@ struct StoredGeneralSettings {
159160 timezone : String ,
160161}
161162
163+ #[ derive( Clone , Default , Deserialize , Serialize ) ]
164+ #[ serde( rename_all = "camelCase" ) ]
165+ struct StoredAppSettings {
166+ #[ serde( default ) ]
167+ general : StoredGeneralSettings ,
168+ #[ serde( default ) ]
169+ model : StoredModelSettings ,
170+ #[ serde( default ) ]
171+ diarization : StoredDiarizationSettings ,
172+ }
173+
162174#[ derive( Serialize ) ]
163175#[ serde( rename_all = "camelCase" ) ]
164176struct ModelSettingsState {
@@ -1058,93 +1070,99 @@ fn build_general_settings_state(
10581070fn load_model_settings < R : tauri:: Runtime > (
10591071 app : & tauri:: AppHandle < R > ,
10601072) -> Result < StoredModelSettings , String > {
1061- let path = model_settings_path ( app) ?;
1062- if !path. exists ( ) {
1063- return Ok ( StoredModelSettings :: default ( ) ) ;
1064- }
1065-
1066- let contents = std:: fs:: read ( & path) . map_err ( |error| error. to_string ( ) ) ?;
1067- serde_json:: from_slice ( & contents) . map_err ( |error| format ! ( "Invalid model settings: {error}" ) )
1073+ Ok ( load_app_settings ( app) ?. model )
10681074}
10691075
10701076fn load_diarization_settings < R : tauri:: Runtime > (
10711077 app : & tauri:: AppHandle < R > ,
10721078) -> Result < StoredDiarizationSettings , String > {
1073- let path = diarization_settings_path ( app) ?;
1074- if !path. exists ( ) {
1075- return Ok ( StoredDiarizationSettings :: default ( ) ) ;
1076- }
1077-
1078- let contents = std:: fs:: read ( & path) . map_err ( |error| error. to_string ( ) ) ?;
1079- serde_json:: from_slice ( & contents)
1080- . map_err ( |error| format ! ( "Invalid diarization settings: {error}" ) )
1079+ Ok ( load_app_settings ( app) ?. diarization )
10811080}
10821081
10831082fn load_general_settings < R : tauri:: Runtime > (
10841083 app : & tauri:: AppHandle < R > ,
10851084) -> Result < StoredGeneralSettings , String > {
1086- let path = general_settings_path ( app) ?;
1087- if !path. exists ( ) {
1088- return Ok ( StoredGeneralSettings :: default ( ) ) ;
1089- }
1090-
1091- let contents = std:: fs:: read ( & path) . map_err ( |error| error. to_string ( ) ) ?;
1092- serde_json:: from_slice ( & contents) . map_err ( |error| format ! ( "Invalid general settings: {error}" ) )
1085+ Ok ( load_app_settings ( app) ?. general )
10931086}
10941087
10951088fn persist_model_settings < R : tauri:: Runtime > (
10961089 app : & tauri:: AppHandle < R > ,
10971090 settings : & StoredModelSettings ,
10981091) -> Result < ( ) , String > {
1099- let path = model_settings_path ( app) ?;
1100- if let Some ( parent) = path. parent ( ) {
1101- std:: fs:: create_dir_all ( parent) . map_err ( |error| error. to_string ( ) ) ?;
1102- }
1103-
1104- let contents = serde_json:: to_vec_pretty ( settings)
1105- . map_err ( |error| format ! ( "Failed to encode settings: {error}" ) ) ?;
1106- std:: fs:: write ( path, contents) . map_err ( |error| error. to_string ( ) )
1092+ let mut app_settings = load_app_settings ( app) ?;
1093+ app_settings. model = settings. clone ( ) ;
1094+ persist_app_settings ( app, & app_settings)
11071095}
11081096
11091097fn persist_diarization_settings < R : tauri:: Runtime > (
11101098 app : & tauri:: AppHandle < R > ,
11111099 settings : & StoredDiarizationSettings ,
11121100) -> Result < ( ) , String > {
1113- let path = diarization_settings_path ( app) ?;
1114- if let Some ( parent) = path. parent ( ) {
1115- std:: fs:: create_dir_all ( parent) . map_err ( |error| error. to_string ( ) ) ?;
1116- }
1117-
1118- let contents = serde_json:: to_vec_pretty ( settings)
1119- . map_err ( |error| format ! ( "Failed to encode diarization settings: {error}" ) ) ?;
1120- std:: fs:: write ( path, contents) . map_err ( |error| error. to_string ( ) )
1101+ let mut app_settings = load_app_settings ( app) ?;
1102+ app_settings. diarization = settings. clone ( ) ;
1103+ persist_app_settings ( app, & app_settings)
11211104}
11221105
11231106fn persist_general_settings < R : tauri:: Runtime > (
11241107 app : & tauri:: AppHandle < R > ,
11251108 settings : & StoredGeneralSettings ,
11261109) -> Result < ( ) , String > {
1127- let path = general_settings_path ( app) ?;
1110+ let mut app_settings = load_app_settings ( app) ?;
1111+ app_settings. general = settings. clone ( ) ;
1112+ persist_app_settings ( app, & app_settings)
1113+ }
1114+
1115+ fn load_app_settings < R : tauri:: Runtime > (
1116+ app : & tauri:: AppHandle < R > ,
1117+ ) -> Result < StoredAppSettings , String > {
1118+ let path = settings_config_path ( app) ?;
1119+ if path. exists ( ) {
1120+ let contents = std:: fs:: read ( & path) . map_err ( |error| error. to_string ( ) ) ?;
1121+ return serde_json:: from_slice ( & contents)
1122+ . map_err ( |error| format ! ( "Invalid settings config: {error}" ) ) ;
1123+ }
1124+
1125+ Ok ( StoredAppSettings {
1126+ general : load_legacy_general_settings ( app) ?,
1127+ model : load_legacy_model_settings ( app) ?,
1128+ diarization : load_legacy_diarization_settings ( app) ?,
1129+ } )
1130+ }
1131+
1132+ fn persist_app_settings < R : tauri:: Runtime > (
1133+ app : & tauri:: AppHandle < R > ,
1134+ settings : & StoredAppSettings ,
1135+ ) -> Result < ( ) , String > {
1136+ let path = settings_config_path ( app) ?;
11281137 if let Some ( parent) = path. parent ( ) {
11291138 std:: fs:: create_dir_all ( parent) . map_err ( |error| error. to_string ( ) ) ?;
11301139 }
11311140
11321141 let contents = serde_json:: to_vec_pretty ( settings)
1133- . map_err ( |error| format ! ( "Failed to encode general settings: {error}" ) ) ?;
1134- std:: fs:: write ( path, contents) . map_err ( |error| error. to_string ( ) )
1142+ . map_err ( |error| format ! ( "Failed to encode settings config: {error}" ) ) ?;
1143+ std:: fs:: write ( path, contents) . map_err ( |error| error. to_string ( ) ) ?;
1144+ cleanup_legacy_settings_files ( app) ;
1145+ Ok ( ( ) )
1146+ }
1147+
1148+ fn settings_config_path < R : tauri:: Runtime > ( app : & tauri:: AppHandle < R > ) -> Result < PathBuf , String > {
1149+ app. path ( )
1150+ . app_config_dir ( )
1151+ . map ( |path| path. join ( SETTINGS_CONFIG_FILE ) )
1152+ . map_err ( |error| error. to_string ( ) )
11351153}
11361154
11371155fn general_settings_path < R : tauri:: Runtime > ( app : & tauri:: AppHandle < R > ) -> Result < PathBuf , String > {
11381156 app. path ( )
11391157 . app_config_dir ( )
1140- . map ( |path| path. join ( GENERAL_SETTINGS_FILE ) )
1158+ . map ( |path| path. join ( LEGACY_GENERAL_SETTINGS_FILE ) )
11411159 . map_err ( |error| error. to_string ( ) )
11421160}
11431161
11441162fn model_settings_path < R : tauri:: Runtime > ( app : & tauri:: AppHandle < R > ) -> Result < PathBuf , String > {
11451163 app. path ( )
11461164 . app_config_dir ( )
1147- . map ( |path| path. join ( MODEL_SETTINGS_FILE ) )
1165+ . map ( |path| path. join ( LEGACY_MODEL_SETTINGS_FILE ) )
11481166 . map_err ( |error| error. to_string ( ) )
11491167}
11501168
@@ -1153,10 +1171,63 @@ fn diarization_settings_path<R: tauri::Runtime>(
11531171) -> Result < PathBuf , String > {
11541172 app. path ( )
11551173 . app_config_dir ( )
1156- . map ( |path| path. join ( DIARIZATION_SETTINGS_FILE ) )
1174+ . map ( |path| path. join ( LEGACY_DIARIZATION_SETTINGS_FILE ) )
11571175 . map_err ( |error| error. to_string ( ) )
11581176}
11591177
1178+ fn load_legacy_model_settings < R : tauri:: Runtime > (
1179+ app : & tauri:: AppHandle < R > ,
1180+ ) -> Result < StoredModelSettings , String > {
1181+ let path = model_settings_path ( app) ?;
1182+ if !path. exists ( ) {
1183+ return Ok ( StoredModelSettings :: default ( ) ) ;
1184+ }
1185+
1186+ let contents = std:: fs:: read ( & path) . map_err ( |error| error. to_string ( ) ) ?;
1187+ serde_json:: from_slice ( & contents)
1188+ . map_err ( |error| format ! ( "Invalid legacy model settings: {error}" ) )
1189+ }
1190+
1191+ fn load_legacy_diarization_settings < R : tauri:: Runtime > (
1192+ app : & tauri:: AppHandle < R > ,
1193+ ) -> Result < StoredDiarizationSettings , String > {
1194+ let path = diarization_settings_path ( app) ?;
1195+ if !path. exists ( ) {
1196+ return Ok ( StoredDiarizationSettings :: default ( ) ) ;
1197+ }
1198+
1199+ let contents = std:: fs:: read ( & path) . map_err ( |error| error. to_string ( ) ) ?;
1200+ serde_json:: from_slice ( & contents)
1201+ . map_err ( |error| format ! ( "Invalid legacy diarization settings: {error}" ) )
1202+ }
1203+
1204+ fn load_legacy_general_settings < R : tauri:: Runtime > (
1205+ app : & tauri:: AppHandle < R > ,
1206+ ) -> Result < StoredGeneralSettings , String > {
1207+ let path = general_settings_path ( app) ?;
1208+ if !path. exists ( ) {
1209+ return Ok ( StoredGeneralSettings :: default ( ) ) ;
1210+ }
1211+
1212+ let contents = std:: fs:: read ( & path) . map_err ( |error| error. to_string ( ) ) ?;
1213+ serde_json:: from_slice ( & contents)
1214+ . map_err ( |error| format ! ( "Invalid legacy general settings: {error}" ) )
1215+ }
1216+
1217+ fn cleanup_legacy_settings_files < R : tauri:: Runtime > ( app : & tauri:: AppHandle < R > ) {
1218+ let paths = [
1219+ general_settings_path ( app) ,
1220+ model_settings_path ( app) ,
1221+ diarization_settings_path ( app) ,
1222+ ] ;
1223+
1224+ for path in paths. into_iter ( ) . flatten ( ) {
1225+ if path. exists ( ) {
1226+ let _ = std:: fs:: remove_file ( path) ;
1227+ }
1228+ }
1229+ }
1230+
11601231fn resolve_bundled_model_path < R : tauri:: Runtime > ( app : & tauri:: AppHandle < R > ) -> PathBuf {
11611232 let packaged_candidate = app
11621233 . path ( )
0 commit comments