Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat: add options to preserve user data during factory reset (#7858)

dev-miro26239811ca7463
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index d0700aba7..b7e3e40c2 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -136,7 +136,7 @@ version = "2.8.5"
default-features = false
features = ["protocol-asset", "macos-private-api", "test"]
-[target.'cfg(windows)'.dev-dependencies]
+[dev-dependencies]
tempfile = "3.20.0"
[target.'cfg(unix)'.dependencies]
diff --git a/src-tauri/src/core/app/constants.rs b/src-tauri/src/core/app/constants.rs
index 920fe7597..432ca3518 100644
--- a/src-tauri/src/core/app/constants.rs
+++ b/src-tauri/src/core/app/constants.rs
@@ -1,10 +1,38 @@
// App Configuration Constants
pub const CONFIGURATION_FILE_NAME: &str = "settings.json";
+// Categorised lists of Jan data directories and files.
+// The factory-reset logic selectively deletes by category based on user choices.
+// Add new entries to the appropriate category so they are picked up automatically.
+
+/// Conversations & user data — chat threads and assistant profiles.
+/// Gated by the `keep_app_data` flag during factory reset.
+pub const JAN_DATA_DIRS_CONVERSATIONS: &[&str] = &["threads", "assistants"];
+
+/// Downloaded models and engine binaries.
+/// Gated by the `keep_models_and_configs` flag during factory reset.
+pub const JAN_DATA_DIRS_MODELS: &[&str] = &["models", "llamacpp", "mlx", "openclaw"];
+
+/// Configuration files — engine settings, MCP config, etc.
+/// Gated by the `keep_models_and_configs` flag during factory reset.
+pub const JAN_DATA_FILES_CONFIGS: &[&str] = &["mcp_config.json"];
+
+/// Extensions, logs, and caches — always cleaned during any reset.
+pub const JAN_DATA_DIRS_COMMON: &[&str] = &["extensions", "logs", ".npx", ".uvx"];
+
+/// Cross-category settings file (contains data spanning conversations, models,
+/// and UI preferences). Only deleted during a full wipe — i.e. when the user
+/// keeps neither conversations nor models/configs.
+/// After #7821, zustand stores persist to `settings.json` via @tauri-apps/plugin-store.
+pub const JAN_DATA_FILES_SETTINGS: &[&str] = &["settings.json"];
+
+/// All known data subdirectories (union of every category above).
pub const JAN_DATA_SUBDIRS: &[&str] = &[
"threads",
+ "assistants",
"extensions",
"logs",
+ "models",
"llamacpp",
"mlx",
"openclaw",
@@ -12,4 +40,9 @@ pub const JAN_DATA_SUBDIRS: &[&str] = &[
".uvx",
];
-pub const JAN_DATA_FILES: &[&str] = &["mcp_config.json"];
+/// All known data files (union of every file category above).
+pub const JAN_DATA_FILES: &[&str] = &["mcp_config.json", "settings.json"];
+
+// NOTE: when adding new entries, place them in the appropriate category above
+// so the factory-reset logic handles them automatically. Then add them to the
+// comprehensive JAN_DATA_SUBDIRS / JAN_DATA_FILES lists as well.
diff --git a/src-tauri/src/core/system/commands.rs b/src-tauri/src/core/system/commands.rs
index 3d5d38378..c4ed4e3ad 100644
--- a/src-tauri/src/core/system/commands.rs
+++ b/src-tauri/src/core/system/commands.rs
@@ -6,7 +6,10 @@ use tauri_plugin_llamacpp::cleanup_llama_processes;
use crate::core::app::commands::{
default_data_folder_path, get_jan_data_folder_path, update_app_configuration,
};
-use crate::core::app::constants::{JAN_DATA_FILES, JAN_DATA_SUBDIRS};
+use crate::core::app::constants::{
+ JAN_DATA_DIRS_COMMON, JAN_DATA_DIRS_CONVERSATIONS, JAN_DATA_DIRS_MODELS,
+ JAN_DATA_FILES_CONFIGS, JAN_DATA_FILES_SETTINGS,
+};
use crate::core::app::models::AppConfiguration;
use crate::core::mcp::helpers::{stop_mcp_servers_with_context, ShutdownContext};
use crate::core::state::AppState;
@@ -16,25 +19,63 @@ fn is_safe_to_delete(path: &std::path::Path) -> bool {
count >= 3
}
-fn remove_jan_data_contents(data_folder: &std::path::Path) {
- for subdir in JAN_DATA_SUBDIRS {
- let path = data_folder.join(subdir);
- if path.is_dir() {
- if let Err(e) = fs::remove_dir_all(&path) {
- log::warn!("Failed to remove {}: {e}", path.display());
- }
+fn remove_dir(data_folder: &std::path::Path, name: &str) {
+ let path = data_folder.join(name);
+ if path.is_dir() {
+ log::info!("Removing directory: {}", path.display());
+ if let Err(e) = fs::remove_dir_all(&path) {
+ log::warn!("Failed to remove {}: {e}", path.display());
}
}
- for file in JAN_DATA_FILES {
- let path = data_folder.join(file);
- if path.is_file() {
- if let Err(e) = fs::remove_file(&path) {
- log::warn!("Failed to remove {}: {e}", path.display());
- }
+}
+
+fn remove_file(data_folder: &std::path::Path, name: &str) {
+ let path = data_folder.join(name);
+ if path.is_file() {
+ log::info!("Removing file: {}", path.display());
+ if let Err(e) = fs::remove_file(&path) {
+ log::warn!("Failed to remove {}: {e}", path.display());
}
}
}
+/// Delete conversations and user data (threads, assistants).
+fn delete_conversations(data_folder: &std::path::Path) {
+ log::info!("Deleting conversations (threads, assistants)");
+ for dir in JAN_DATA_DIRS_CONVERSATIONS {
+ remove_dir(data_folder, dir);
+ }
+}
+
+/// Delete downloaded models, engine binaries, and configuration files
+/// (engine settings, MCP config, etc.).
+fn delete_models_and_configs(data_folder: &std::path::Path) {
+ log::info!("Deleting models, engines, and configurations");
+ for dir in JAN_DATA_DIRS_MODELS {
+ remove_dir(data_folder, dir);
+ }
+ for file in JAN_DATA_FILES_CONFIGS {
+ remove_file(data_folder, file);
+ }
+}
+
+/// Delete extensions, logs, caches — always cleaned during any reset.
+fn delete_common_data(data_folder: &std::path::Path) {
+ log::info!("Deleting common data (extensions, logs, caches)");
+ for dir in JAN_DATA_DIRS_COMMON {
+ remove_dir(data_folder, dir);
+ }
+}
+
+/// Delete cross-category settings (store.json) — only during a full wipe
+/// when the user is not keeping any data.
+fn delete_settings(data_folder: &std::path::Path) {
+ log::info!("Deleting cross-category settings (store.json)");
+ for file in JAN_DATA_FILES_SETTINGS {
+ remove_file(data_folder, file);
+ }
+}
+
/// Detect the user's default shell and return the appropriate env file path.
/// Returns (shell_name, env_file_path).
fn detect_shell_env_file(home_dir: &str, is_macos: bool) -> (&'static str, String) {
@@ -81,8 +122,15 @@ fn write_env_to_shell(env_file_path: &str, env_vars: &[(String, String)]) -> Res
}
#[tauri::command]
-pub fn factory_reset<R: Runtime>(app_handle: tauri::AppHandle<R>, state: State<'_, AppState>) {
- // close window (not available on mobile platforms)
+pub fn factory_reset<R: Runtime>(
+ app_handle: tauri::AppHandle<R>,
+ state: State<'_, AppState>,
+ keep_app_data: Option<bool>,
+ keep_models_and_configs: Option<bool>,
+) {
+ let keep_app_data = keep_app_data.unwrap_or(false);
+ let keep_models_and_configs = keep_models_and_configs.unwrap_or(false);
+
#[cfg(not(any(target_os = "ios", target_os = "android")))]
{
let windows = app_handle.webview_windows();
@@ -93,7 +141,12 @@ pub fn factory_reset<R: Runtime>(app_handle: tauri::AppHandle<R>, state: State<'
}
}
let data_folder = get_jan_data_folder_path(app_handle.clone());
- log::info!("Factory reset, removing data folder: {data_folder:?}");
+ log::info!(
+ "Factory reset (keep_app_data={}, keep_models_and_configs={}), data folder: {:?}",
+ keep_app_data,
+ keep_models_and_configs,
+ data_folder
+ );
tauri::async_runtime::block_on(async {
let _ =
@@ -118,13 +171,32 @@ pub fn factory_reset<R: Runtime>(app_handle: tauri::AppHandle<R>, state: State<'
);
return;
}
- remove_jan_data_contents(&data_folder);
+
+ // 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);
+ }
}
- // Reset the configuration
- let mut default_config = AppConfiguration::default();
- default_config.data_folder = default_data_folder_path(app_handle.clone());
- let _ = update_app_configuration(app_handle.clone(), default_config);
+ // Reset app configuration to defaults unless user chose to keep configs
+ if !keep_models_and_configs {
+ let mut default_config = AppConfiguration::default();
+ default_config.data_folder = default_data_folder_path(app_handle.clone());
+ let _ = update_app_configuration(app_handle.clone(), default_config);
+ }
app_handle.restart();
});
@@ -790,3 +862,149 @@ fn remove_from_path_windows(dir: &PathBuf) -> Result<(), String> {
}
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::core::app::constants::*;
+ use std::fs;
+ use tempfile::tempdir;
+
+ fn create_all_data(dir: &std::path::Path) {
+ for subdir in JAN_DATA_SUBDIRS {
+ fs::create_dir_all(dir.join(subdir)).unwrap();
+ fs::write(dir.join(subdir).join("dummy.txt"), "data").unwrap();
+ }
+ for file in JAN_DATA_FILES {
+ fs::write(dir.join(file), "data").unwrap();
+ }
+ }
+
+ fn exists_any(dir: &std::path::Path, names: &[&str]) -> bool {
+ names.iter().any(|n| dir.join(n).exists())
+ }
+
+ fn exists_all(dir: &std::path::Path, names: &[&str]) -> bool {
+ names.iter().all(|n| dir.join(n).exists())
+ }
+
+ #[test]
+ fn test_delete_conversations_only_removes_conversation_dirs() {
+ let tmp = tempdir().unwrap();
+ let d = tmp.path();
+ create_all_data(d);
+
+ delete_conversations(d);
+
+ assert!(!exists_any(d, JAN_DATA_DIRS_CONVERSATIONS));
+ assert!(exists_all(d, JAN_DATA_DIRS_MODELS));
+ assert!(exists_all(d, JAN_DATA_DIRS_COMMON));
+ assert!(d.join("settings.json").exists());
+ assert!(d.join("mcp_config.json").exists());
+ }
+
+ #[test]
+ fn test_delete_models_and_configs_only_removes_model_dirs_and_config_files() {
+ let tmp = tempdir().unwrap();
+ let d = tmp.path();
+ create_all_data(d);
+
+ delete_models_and_configs(d);
+
+ assert!(!exists_any(d, JAN_DATA_DIRS_MODELS));
+ assert!(!exists_any(d, JAN_DATA_FILES_CONFIGS));
+ assert!(exists_all(d, JAN_DATA_DIRS_CONVERSATIONS));
+ assert!(exists_all(d, JAN_DATA_DIRS_COMMON));
+ assert!(d.join("settings.json").exists());
+ }
+
+ #[test]
+ fn test_delete_common_data_only_removes_common_dirs() {
+ let tmp = tempdir().unwrap();
+ let d = tmp.path();
+ create_all_data(d);
+
+ delete_common_data(d);
+
+ assert!(!exists_any(d, JAN_DATA_DIRS_COMMON));
+ assert!(exists_all(d, JAN_DATA_DIRS_CONVERSATIONS));
+ assert!(exists_all(d, JAN_DATA_DIRS_MODELS));
+ assert!(d.join("settings.json").exists());
+ assert!(d.join("mcp_config.json").exists());
+ }
+
+ #[test]
+ fn test_delete_settings_only_removes_settings_json() {
+ let tmp = tempdir().unwrap();
+ let d = tmp.path();
+ create_all_data(d);
+
+ delete_settings(d);
+
+ assert!(!d.join("settings.json").exists());
+ assert!(exists_all(d, JAN_DATA_DIRS_CONVERSATIONS));
+ assert!(exists_all(d, JAN_DATA_DIRS_MODELS));
+ assert!(exists_all(d, JAN_DATA_DIRS_COMMON));
+ assert!(d.join("mcp_config.json").exists());
+ }
+
+ #[test]
+ fn test_settings_json_survives_when_keeping_any_category() {
+ // Simulate: keep_app_data=true, keep_models_and_configs=false
+ let tmp = tempdir().unwrap();
+ let d = tmp.path();
+ create_all_data(d);
+
+ delete_common_data(d);
+ delete_models_and_configs(d);
+ // settings.json should NOT be deleted because keep_app_data=true
+ assert!(d.join("settings.json").exists());
+
+ // Simulate: keep_app_data=false, keep_models_and_configs=true
+ let tmp2 = tempdir().unwrap();
+ let d2 = tmp2.path();
+ create_all_data(d2);
+
+ delete_common_data(d2);
+ delete_conversations(d2);
+ // settings.json should NOT be deleted because keep_models_and_configs=true
+ assert!(d2.join("settings.json").exists());
+ }
+
+ #[test]
+ fn test_full_wipe_deletes_settings_json() {
+ let tmp = tempdir().unwrap();
+ let d = tmp.path();
+ create_all_data(d);
+
+ delete_common_data(d);
+ delete_conversations(d);
+ delete_models_and_configs(d);
+ delete_settings(d);
+
+ assert!(!d.join("settings.json").exists());
+ assert!(!exists_any(d, JAN_DATA_SUBDIRS));
+ assert!(!exists_any(d, JAN_DATA_FILES));
+ }
+
+ #[test]
+ fn test_delete_on_nonexistent_dirs_does_not_panic() {
+ let tmp = tempdir().unwrap();
+ let d = tmp.path();
+ // Nothing created — should not panic
+ delete_conversations(d);
+ delete_models_and_configs(d);
+ delete_common_data(d);
+ delete_settings(d);
+ }
+
+ #[test]
+ fn test_is_safe_to_delete() {
+ assert!(!is_safe_to_delete(std::path::Path::new("/")));
+ assert!(!is_safe_to_delete(std::path::Path::new("/home")));
+ assert!(is_safe_to_delete(std::path::Path::new("/home/user/jan")));
+ assert!(is_safe_to_delete(std::path::Path::new(
+ "/home/user/.local/share/jan"
+ )));
+ }
+}
diff --git a/web-app/src/containers/dialogs/FactoryResetDialog.tsx b/web-app/src/containers/dialogs/FactoryResetDialog.tsx
index 57d62d363..3642e6fd0 100644
--- a/web-app/src/containers/dialogs/FactoryResetDialog.tsx
+++ b/web-app/src/containers/dialogs/FactoryResetDialog.tsx
@@ -1,4 +1,4 @@
-import { useRef } from 'react'
+import { useRef, useState } from 'react'
import { useTranslation } from '@/i18n/react-i18next-compat'
import {
Dialog,
@@ -11,9 +11,10 @@ import {
DialogHeader,
} from '@/components/ui/dialog'
import { Button } from '@/components/ui/button'
+import type { FactoryResetOptions } from '@/services/app/types'
interface FactoryResetDialogProps {
- onReset: () => void
+ onReset: (options: FactoryResetOptions) => void
children: React.ReactNode
}
@@ -23,9 +24,11 @@ export function FactoryResetDialog({
}: FactoryResetDialogProps) {
const { t } = useTranslation()
const resetButtonRef = useRef<HTMLButtonElement>(null)
+ const [keepAppData, setKeepAppData] = useState(true)
+ const [keepModelsAndConfigs, setKeepModelsAndConfigs] = useState(true)
const handleReset = () => {
- onReset()
+ onReset({ keepAppData, keepModelsAndConfigs })
}
const handleKeyDown = (e: React.KeyboardEvent) => {
@@ -49,6 +52,40 @@ export function FactoryResetDialog({
<DialogDescription>
{t('settings:general.factoryResetDesc')}
</DialogDescription>
+ <div className="flex flex-col gap-3 pt-2">
+ <label className="flex items-start gap-2 cursor-pointer">
+ <input
+ type="checkbox"
+ checked={keepAppData}
+ onChange={(e) => setKeepAppData(e.target.checked)}
+ className="mt-0.5 h-4 w-4 rounded border-border accent-primary cursor-pointer"
+ />
+ <div className="flex flex-col">
+ <span className="text-sm font-medium text-foreground">
+ {t('settings:general.keepAppData')}
+ </span>
+ <span className="text-xs text-muted-foreground">
+ {t('settings:general.keepAppDataDesc')}
+ </span>
+ </div>
+ </label>
+ <label className="flex items-start gap-2 cursor-pointer">
+ <input
+ type="checkbox"
+ checked={keepModelsAndConfigs}
+ onChange={(e) => setKeepModelsAndConfigs(e.target.checked)}
+ className="mt-0.5 h-4 w-4 rounded border-border accent-primary cursor-pointer"
+ />
+ <div className="flex flex-col">
+ <span className="text-sm font-medium text-foreground">
+ {t('settings:general.keepModelsAndConfigs')}
+ </span>
+ <span className="text-xs text-muted-foreground">
+ {t('settings:general.keepModelsAndConfigsDesc')}
+ </span>
+ </div>
+ </label>
+ </div>
<DialogFooter className="flex flex-col-reverse sm:flex-row sm:justify-end gap-2">
<DialogClose asChild>
<Button
diff --git a/web-app/src/locales/ca/settings.json b/web-app/src/locales/ca/settings.json
index fb7a2d5e9..177bd1d65 100644
--- a/web-app/src/locales/ca/settings.json
+++ b/web-app/src/locales/ca/settings.json
@@ -235,6 +235,10 @@
"revealLogs": "Mostra els registres",
"factoryResetTitle": "Restableix als valors d’origen",
"factoryResetDesc": "Això restablirà tots els paràmetres de l’app als valors per defecte. No es pot desfer. Només ho recomanem si l’aplicació està malmesa.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Cancel·la",
"reset": "Restableix",
"huggingfaceToken": "Token de HuggingFace",
diff --git a/web-app/src/locales/cs/settings.json b/web-app/src/locales/cs/settings.json
index 8a289b04f..7cec50757 100644
--- a/web-app/src/locales/cs/settings.json
+++ b/web-app/src/locales/cs/settings.json
@@ -233,6 +233,10 @@
"revealLogs": "Zobrazit záznamy",
"factoryResetTitle": "Obnovit tovární nastavení",
"factoryResetDesc": "Tím obnovíte všechna nastavení aplikace na výchozí hodnoty. Tuto akci nelze vrátit zpět. Doporučujeme to pouze v případě, že je aplikace poškozena.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Zrušit",
"reset": "Obnovit",
"huggingfaceToken": "HuggingFace token",
diff --git a/web-app/src/locales/de-DE/settings.json b/web-app/src/locales/de-DE/settings.json
index c16bfc89f..2a61fa8ff 100644
--- a/web-app/src/locales/de-DE/settings.json
+++ b/web-app/src/locales/de-DE/settings.json
@@ -227,6 +227,10 @@
"revealLogs": "Logs anzeigen",
"factoryResetTitle": "Auf Werkseinstellungen zurücksetzen",
"factoryResetDesc": "Dadurch werden alle App-Einstellungen auf die Standardeinstellungen zurückgesetzt. Dieser Vorgang kann nicht rückgängig gemacht werden. Wir empfehlen dies nur, wenn die App beschädigt ist.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Abbrechen",
"reset": "Zurücksetzen",
"huggingfaceToken": "HuggingFace Token",
diff --git a/web-app/src/locales/en/settings.json b/web-app/src/locales/en/settings.json
index 321e598b9..3023600c6 100644
--- a/web-app/src/locales/en/settings.json
+++ b/web-app/src/locales/en/settings.json
@@ -246,6 +246,10 @@
"revealLogs": "Reveal Logs",
"factoryResetTitle": "Reset to Factory Settings",
"factoryResetDesc": "This will reset all app settings to their defaults. This can't be undone. We only recommend this if the app is corrupted.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Cancel",
"reset": "Reset",
"huggingfaceToken": "HuggingFace Token",
diff --git a/web-app/src/locales/es/settings.json b/web-app/src/locales/es/settings.json
index b9ab8d23a..b4becd998 100644
--- a/web-app/src/locales/es/settings.json
+++ b/web-app/src/locales/es/settings.json
@@ -240,6 +240,10 @@
"revealLogs": "Revelar registros",
"factoryResetTitle": "Restablecer a configuración de fábrica",
"factoryResetDesc": "Esto restablecerá toda la configuración de la aplicación a sus valores predeterminados. Esta acción no se puede deshacer. Solo recomendamos esto si la aplicación está corrupta.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Cancelar",
"reset": "Restablecer",
"huggingfaceToken": "Token de HuggingFace",
diff --git a/web-app/src/locales/fr/settings.json b/web-app/src/locales/fr/settings.json
index b4689638b..fe1f90c02 100644
--- a/web-app/src/locales/fr/settings.json
+++ b/web-app/src/locales/fr/settings.json
@@ -233,6 +233,10 @@
"revealLogs": "Afficher les journaux",
"factoryResetTitle": "Réinitialiser aux paramètres d'usine",
"factoryResetDesc": "Cela réinitialisera tous les paramètres de l'application à leurs valeurs par défaut. Cette action ne peut pas être annulée. Nous ne le recommandons que si l'application est corrompue.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Annuler",
"reset": "Réinitialiser",
"huggingfaceToken": "Jeton HuggingFace",
diff --git a/web-app/src/locales/id/settings.json b/web-app/src/locales/id/settings.json
index 3f02b3fed..2a189541d 100644
--- a/web-app/src/locales/id/settings.json
+++ b/web-app/src/locales/id/settings.json
@@ -227,6 +227,10 @@
"revealLogs": "Tampilkan Log",
"factoryResetTitle": "Setel Ulang ke Pengaturan Pabrik",
"factoryResetDesc": "Ini akan mengatur ulang semua pengaturan aplikasi ke default. Tindakan ini tidak dapat dibatalkan. Kami hanya merekomendasikan ini jika aplikasi rusak.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Batal",
"reset": "Setel Ulang",
"huggingfaceToken": "Token HuggingFace",
diff --git a/web-app/src/locales/ja/settings.json b/web-app/src/locales/ja/settings.json
index 83d85ed48..cc6619513 100644
--- a/web-app/src/locales/ja/settings.json
+++ b/web-app/src/locales/ja/settings.json
@@ -224,6 +224,10 @@
"revealLogs": "ログを表示",
"factoryResetTitle": "工場出荷時の設定にリセット",
"factoryResetDesc": "これにより、すべてのアプリ設定がデフォルトにリセットされます。この操作は元に戻せません。アプリが破損している場合にのみ、この操作をお勧めします。",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "キャンセル",
"reset": "リセット",
"huggingfaceToken": "HuggingFaceトークン",
diff --git a/web-app/src/locales/ko/settings.json b/web-app/src/locales/ko/settings.json
index 34c30e6c4..63d929974 100644
--- a/web-app/src/locales/ko/settings.json
+++ b/web-app/src/locales/ko/settings.json
@@ -240,6 +240,10 @@
"revealLogs": "로그 표시",
"factoryResetTitle": "초기 설정으로 재설정",
"factoryResetDesc": "모든 앱 설정이 기본값으로 재설정됩니다. 이 작업은 실행 취소할 수 없습니다. 앱이 손상된 경우에만 권장합니다.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "취소",
"reset": "재설정",
"huggingfaceToken": "HuggingFace 토큰",
diff --git a/web-app/src/locales/pl/settings.json b/web-app/src/locales/pl/settings.json
index 9aa738d8c..45c659b02 100644
--- a/web-app/src/locales/pl/settings.json
+++ b/web-app/src/locales/pl/settings.json
@@ -227,6 +227,10 @@
"revealLogs": "Wyświetl Dzienniki",
"factoryResetTitle": "Przywróć Ustawienia Fabryczne",
"factoryResetDesc": "Przywraca domyślne ustawienia aplikacji. Tej operacji nie można cofnąć. Zalecane przy uszkodzeniu danych aplikacji.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Anuluj",
"reset": "Przywróć",
"huggingfaceToken": "Token HuggingFace",
diff --git a/web-app/src/locales/pt-BR/settings.json b/web-app/src/locales/pt-BR/settings.json
index da715a18f..33395a14b 100644
--- a/web-app/src/locales/pt-BR/settings.json
+++ b/web-app/src/locales/pt-BR/settings.json
@@ -227,6 +227,10 @@
"revealLogs": "Mostrar Logs",
"factoryResetTitle": "Redefinir para Configurações de Fábrica",
"factoryResetDesc": "Isso redefinirá todas as configurações do app para os padrões. Isso não pode ser desfeito. Recomendamos isso apenas se o app estiver corrompido.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Cancelar",
"reset": "Redefinir",
"huggingfaceToken": "Token HuggingFace",
diff --git a/web-app/src/locales/ru/settings.json b/web-app/src/locales/ru/settings.json
index 4e8aeff17..bf298c787 100644
--- a/web-app/src/locales/ru/settings.json
+++ b/web-app/src/locales/ru/settings.json
@@ -233,6 +233,10 @@
"revealLogs": "Показать журналы",
"factoryResetTitle": "Сброс к заводским настройкам",
"factoryResetDesc": "Это сбросит все настройки приложения к значениям по умолчанию. Это действие нельзя отменить. Мы рекомендуем это только в случае, если приложение повреждено.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Отмена",
"reset": "Сбросить",
"huggingfaceToken": "Токен HuggingFace",
diff --git a/web-app/src/locales/vn/settings.json b/web-app/src/locales/vn/settings.json
index 9a965d2a6..19a1de3f6 100644
--- a/web-app/src/locales/vn/settings.json
+++ b/web-app/src/locales/vn/settings.json
@@ -227,6 +227,10 @@
"revealLogs": "Hiển thị Nhật ký",
"factoryResetTitle": "Đặt lại về Cài đặt Gốc",
"factoryResetDesc": "Điều này sẽ đặt lại tất cả cài đặt ứng dụng về mặc định. Không thể hoàn tác. Chúng tôi chỉ khuyến nghị điều này nếu ứng dụng bị hỏng.",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "Hủy",
"reset": "Đặt lại",
"resources": "Tài nguyên",
diff --git a/web-app/src/locales/zh-CN/settings.json b/web-app/src/locales/zh-CN/settings.json
index 384213e29..26f12cbf8 100644
--- a/web-app/src/locales/zh-CN/settings.json
+++ b/web-app/src/locales/zh-CN/settings.json
@@ -227,6 +227,10 @@
"revealLogs": "显示日志",
"factoryResetTitle": "重置为出厂设置",
"factoryResetDesc": "这将重置所有应用设置为默认值。此操作无法撤销。我们只建议在应用损坏时使用。",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "取消",
"reset": "重置",
"resources": "资源",
diff --git a/web-app/src/locales/zh-TW/settings.json b/web-app/src/locales/zh-TW/settings.json
index f2d52dcae..4923b525e 100644
--- a/web-app/src/locales/zh-TW/settings.json
+++ b/web-app/src/locales/zh-TW/settings.json
@@ -227,6 +227,10 @@
"revealLogs": "顯示日誌",
"factoryResetTitle": "重置為出廠設定",
"factoryResetDesc": "這將重置所有應用程式設定為預設值。此操作無法撤銷。我們只建議在應用程式損壞時使用。",
+ "keepAppData": "Keep application data",
+ "keepAppDataDesc": "Your chat history and conversations will be preserved.",
+ "keepModelsAndConfigs": "Keep all models and configurations",
+ "keepModelsAndConfigsDesc": "Downloaded models, engine settings, and MCP configurations will be preserved.",
"cancel": "取消",
"reset": "重置",
"resources": "資源",
diff --git a/web-app/src/routes/settings/general.tsx b/web-app/src/routes/settings/general.tsx
index 15e499084..ccea665b1 100644
--- a/web-app/src/routes/settings/general.tsx
+++ b/web-app/src/routes/settings/general.tsx
@@ -12,6 +12,7 @@ import { useAppUpdater } from '@/hooks/useAppUpdater'
import { useEffect, useState, useCallback } from 'react'
import ChangeDataFolderLocation from '@/containers/dialogs/ChangeDataFolderLocation'
import { FactoryResetDialog } from '@/containers/dialogs'
+import type { FactoryResetOptions } from '@/services/app/types'
import { useServiceHub } from '@/hooks/useServiceHub'
import {
IconBrandDiscord,
@@ -111,15 +112,13 @@ function General() {
}
}
- const resetApp = async () => {
- // Prevent resetting if data folder is root directory
+ const resetApp = async (options: FactoryResetOptions) => {
if (isRootDir(janDataFolder ?? '/')) {
toast.error(t('settings:general.couldNotResetRootDirectory'))
return
}
pausePolling()
- // TODO: Loading indicator
- await serviceHub.app().factoryReset()
+ await serviceHub.app().factoryReset(options)
}
const handleOpenLogs = async () => {
diff --git a/web-app/src/services/app/default.ts b/web-app/src/services/app/default.ts
index 68fe1f0ea..40a8e15c5 100644
--- a/web-app/src/services/app/default.ts
+++ b/web-app/src/services/app/default.ts
@@ -2,10 +2,11 @@
* Default App Service - Generic implementation with minimal returns
*/
-import type { AppService, LogEntry } from './types'
+import type { AppService, FactoryResetOptions, LogEntry } from './types'
export class DefaultAppService implements AppService {
- async factoryReset(): Promise<void> {
+ async factoryReset(options?: FactoryResetOptions): Promise<void> {
+ console.log('factoryReset called with options:', options)
// No-op
}
diff --git a/web-app/src/services/app/tauri.ts b/web-app/src/services/app/tauri.ts
index af770e93d..739ac6b49 100644
--- a/web-app/src/services/app/tauri.ts
+++ b/web-app/src/services/app/tauri.ts
@@ -4,14 +4,20 @@
import { invoke } from '@tauri-apps/api/core'
import { AppConfiguration } from '@janhq/core'
-import type { LogEntry } from './types'
+import type { FactoryResetOptions, LogEntry } from './types'
import { DefaultAppService } from './default'
export class TauriAppService extends DefaultAppService {
- async factoryReset(): Promise<void> {
- // Kill background processes and remove data folder
- // Note: We can't import stopAllModels directly to avoid circular dependency
- // Instead we'll use the engine manager directly
+ /**
+ * Factory reset with optional data preservation.
+ *
+ * User settings are persisted to `settings.json` via @tauri-apps/plugin-store
+ * (see #7821). The Rust `factory_reset` command conditionally deletes
+ * directories, config files, and `settings.json` based on the keep flags.
+ * No frontend snapshot/restore is needed — the file store is preserved or
+ * wiped on disk by the Rust side.
+ */
+ async factoryReset(options?: FactoryResetOptions): Promise<void> {
const { EngineManager } = await import('@janhq/core')
for (const [, engine] of EngineManager.instance().engines) {
const activeModels = await engine.getLoadedModels()
@@ -19,8 +25,15 @@ export class TauriAppService extends DefaultAppService {
await Promise.all(activeModels.map((model: string) => engine.unload(model)))
}
}
- window.localStorage.clear()
- await invoke('factory_reset')
+
+ const keepAppData = options?.keepAppData ?? false
+ const keepModelsAndConfigs = options?.keepModelsAndConfigs ?? false
+
+ if (!keepAppData && !keepModelsAndConfigs) {
+ await invoke('factory_reset')
+ } else {
+ await invoke('factory_reset', { keepAppData, keepModelsAndConfigs })
+ }
}
async readLogs(): Promise<LogEntry[]> {
diff --git a/web-app/src/services/app/types.ts b/web-app/src/services/app/types.ts
index 4be49c584..426354722 100644
--- a/web-app/src/services/app/types.ts
+++ b/web-app/src/services/app/types.ts
@@ -9,8 +9,13 @@ export interface LogEntry {
message: string
}
+export interface FactoryResetOptions {
+ keepAppData: boolean
+ keepModelsAndConfigs: boolean
+}
+
export interface AppService {
- factoryReset(): Promise<void>
+ factoryReset(options?: FactoryResetOptions): Promise<void>
readLogs(): Promise<LogEntry[]>
parseLogLine(line: string): LogEntry
getJanDataFolder(): Promise<string | undefined>