@@ -82,6 +82,15 @@ const DEFAULT_SETTINGS: AppSettings = {
8282 chat_minimap_enabled : false ,
8383 chat_minimap_style : 'faq' ,
8484 multi_model_display_mode : 'tabs' ,
85+ // WebDAV sync settings — must be present so stale saves never omit them
86+ webdav_host : null ,
87+ webdav_username : null ,
88+ webdav_path : null ,
89+ webdav_accept_invalid_certs : false ,
90+ webdav_sync_enabled : false ,
91+ webdav_sync_interval_minutes : 60 ,
92+ webdav_max_remote_backups : 10 ,
93+ webdav_include_documents : false ,
8594} ;
8695
8796export interface GlobalShortcutDiagnostic {
@@ -104,6 +113,8 @@ export interface GlobalShortcutStatus {
104113interface SettingsState {
105114 settings : AppSettings ;
106115 loading : boolean ;
116+ /** Set once after the first successful fetchSettings; guards saveSettings from writing stale data. */
117+ _loaded : boolean ;
107118 error : string | null ;
108119 globalShortcutStatus : GlobalShortcutStatus ;
109120 fetchSettings : ( ) => Promise < void > ;
@@ -113,7 +124,8 @@ interface SettingsState {
113124
114125export const useSettingsStore = create < SettingsState > ( ( set , get ) => ( {
115126 settings : DEFAULT_SETTINGS ,
116- loading : false ,
127+ loading : true ,
128+ _loaded : false ,
117129 error : null ,
118130 globalShortcutStatus : {
119131 enabled : false ,
@@ -126,13 +138,17 @@ export const useSettingsStore = create<SettingsState>((set, get) => ({
126138 set ( { loading : true } ) ;
127139 try {
128140 const fetched = await invoke < Partial < AppSettings > > ( 'get_settings' ) ;
129- set ( { settings : { ...DEFAULT_SETTINGS , ...fetched } , loading : false , error : null } ) ;
141+ set ( { settings : { ...DEFAULT_SETTINGS , ...fetched } , loading : false , _loaded : true , error : null } ) ;
130142 } catch ( e ) {
131- set ( { error : String ( e ) , loading : false } ) ;
143+ set ( { error : String ( e ) , loading : false , _loaded : true } ) ;
132144 }
133145 } ,
134146
135147 saveSettings : async ( partial ) => {
148+ if ( ! get ( ) . _loaded ) {
149+ console . warn ( '[settingsStore] saveSettings skipped: settings not loaded yet' ) ;
150+ return ;
151+ }
136152 const merged = { ...get ( ) . settings , ...partial } ;
137153 set ( { settings : merged , error : null } ) ;
138154 try {
0 commit comments