Bug/connection mode fixes (#5998)

This commit is contained in:
EthanHealy01
2026-04-01 15:33:46 +01:00
committed by GitHub
parent ecd1d3cad3
commit 74153b6deb
10 changed files with 211 additions and 92 deletions
+22 -5
View File
@@ -72,6 +72,28 @@ pub async fn set_connection_mode(
) -> Result<(), String> {
log::info!("Setting connection mode: {:?}", mode);
let store = app_handle
.store(STORE_FILE)
.map_err(|e| format!("Failed to access store: {}", e))?;
// If the store is already locked, protect connection_mode, server_config, and the lock
// flag from being overwritten by any JS-side call.
// Only allow marking setup_completed and updating auth-related fields.
let already_locked = store
.get(LOCK_CONNECTION_KEY)
.and_then(|v| v.as_bool())
.unwrap_or(false);
if already_locked {
log::warn!("set_connection_mode called while lock_connection_mode=true — preserving connection settings, but marking setup as completed");
// Still allow setup_completed to be written so the onboarding doesn't repeat.
store.set(FIRST_LAUNCH_KEY, serde_json::json!(true));
store
.save()
.map_err(|e| format!("Failed to save store: {}", e))?;
return Ok(());
}
// Update in-memory state
if let Ok(mut conn_state) = state.0.lock() {
conn_state.mode = mode.clone();
@@ -81,11 +103,6 @@ pub async fn set_connection_mode(
}
}
// Save to store
let store = app_handle
.store(STORE_FILE)
.map_err(|e| format!("Failed to access store: {}", e))?;
store.set(
CONNECTION_MODE_KEY,
serde_json::to_value(&mode).map_err(|e| format!("Failed to serialize mode: {}", e))?,