Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
chore(release): merge main into the v0.8.8 backmerge
thinhlpg775a0bc523a8
diff --cc src-tauri/src/core/system/commands.rsindex 3fc68afc6,10af6c4d5..d5ad71cbe--- a/src-tauri/src/core/system/commands.rs+++ b/src-tauri/src/core/system/commands.rs@@@ -621,79 -426,86 +795,86 @@@ pub async fn factory_reset<R: Runtime>data_folder);- tauri::async_runtime::block_on(async {- let _ =- stop_mcp_servers_with_context(&app_handle, &state, ShutdownContext::FactoryReset).await;+ let _ = stop_mcp_servers_with_context(&app_handle, &state, ShutdownContext::FactoryReset).await;- {- let mut active_servers = state.mcp_active_servers.lock().await;- active_servers.clear();- }+ {+ let mut active_servers = state.mcp_active_servers.lock().await;+ active_servers.clear();+ }- use crate::core::mcp::lockfile::cleanup_own_locks;- if let Err(e) = cleanup_own_locks(&app_handle) {- log::warn!("Failed to cleanup lock files: {}", e);+ use crate::core::mcp::lockfile::cleanup_own_locks;+ if let Err(e) = cleanup_own_locks(&app_handle) {+ log::warn!("Failed to cleanup lock files: {}", e);+ }+ let _ = cleanup_llama_processes(app_handle.clone()).await;++ let full_wipe = !keep_app_data && !keep_models_and_configs;+ if data_folder.exists() {+ // Discard before moving: the in-memory copy would otherwise be+ // flushed back by a pending debounced write or the exit-time flush.+ if full_wipe {+ crate::core::app::settings_store::discard_settings();}- let _ = cleanup_llama_processes(app_handle.clone()).await;-- if data_folder.exists() {- if !is_safe_to_delete(&data_folder) {- log::error!(- "Refusing factory reset: path is too close to filesystem root: {}",- data_folder.display()- );- return;- }-- // Always clean common data (extensions, logs, caches)- delete_common_data(&data_folder);-- // Delete conversations (threads, assistants) unless user chose to keep it- if !keep_app_data {- delete_conversations(&data_folder);- }-- // Delete models and configs unless user chose to keep them- if !keep_models_and_configs {- delete_models_and_configs(&data_folder);- }-- // store.json spans all categories; only wipe it when nothing is kept- if !keep_app_data && !keep_models_and_configs {- delete_settings(&data_folder);+ let stamp = std::time::SystemTime::now()+ .duration_since(std::time::UNIX_EPOCH)+ .map(|d| d.as_millis())+ .unwrap_or(0);+ let trash = data_folder.join(format!("{RESET_TRASH_PREFIX}{stamp}"));+ // Record first, so a trash folder is never left that no sweep knows of.+ let recorded = pending_trash_record(&app_handle)+ .map(|record| record_pending_trash(&record, &trash))+ .transpose();+ let targets = reset_targets(keep_app_data, keep_models_and_configs);+ let folder = data_folder.clone();+ let staged = tauri::async_runtime::spawn_blocking(move || {+ stage_for_deletion(&folder, &targets, &trash);+ // Without a record the next start cannot find the trash, so it+ // has to go now, slow as that is.+ if !matches!(recorded, Ok(Some(()))) {+ log::warn!("Could not record reset trash; deleting it now");+ if trash.exists() {+ let _ = remove_path(&trash);+ }}+ })+ .await;+ if let Err(e) = staged {+ log::error!("Factory reset data deletion failed: {e}");}+ }- // Reset app configuration to defaults unless user chose to keep configs- if !keep_models_and_configs {- let default_config = AppConfiguration {- data_folder: default_data_folder_path(app_handle.clone()),- };- let _ = write_app_configuration(app_handle.clone(), default_config);- }+ // Reset app configuration to defaults unless user chose to keep configs+ if !keep_models_and_configs {+ let default_config = AppConfiguration {+ data_folder: default_data_folder_path(app_handle.clone()),+ };- let _ = update_app_configuration(app_handle.clone(), default_config);++ let _ = write_app_configuration(app_handle.clone(), default_config);+ }- // Persisted UI state (model-provider, setup flag) lives in webview- // localStorage, not the data folder. Renderer-side removal races the- // restart flush, and the on-disk localStorage location is- // platform-specific (esp. macOS WKWebView), so instead drop a sentinel- // that the frontend consumes on next startup to clear localStorage via- // the webview API before stores hydrate. File-level profile deletion- // (Linux cookies/cache) stays as a best-effort supplement.- let full_wipe = !keep_app_data && !keep_models_and_configs;- if !keep_app_data || !keep_models_and_configs || clear_web_data {- write_webdata_reset_sentinel(- &app_handle,- keep_app_data,- keep_models_and_configs,- clear_web_data,- );- }- if clear_web_data || full_wipe {- clear_webview_profile(&app_handle, &data_folder);- }+ // Persisted UI state (model-provider, setup flag) lives in webview+ // localStorage, not the data folder. Renderer-side removal races the+ // restart flush, and the on-disk localStorage location is+ // platform-specific (esp. macOS WKWebView), so instead drop a sentinel+ // that the frontend consumes on next startup to clear localStorage via+ // the webview API before stores hydrate. File-level profile deletion+ // (Linux cookies/cache) stays as a best-effort supplement.+ if !keep_app_data || !keep_models_and_configs || clear_web_data {+ write_webdata_reset_sentinel(+ &app_handle,+ keep_app_data,+ keep_models_and_configs,+ clear_web_data,+ );+ }+ if clear_web_data || full_wipe {+ clear_webview_profile(&app_handle, &data_folder);+ }- app_handle.restart();- });+ // The staged data is deleted by the next start (`sweep_reset_trash`).+ // Not `restart()`: off the main thread it parks this runtime worker+ // forever while the exit handler blocks on the same runtime for cleanup.+ app_handle.request_restart();+ Ok(())}#[tauri::command]