Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat: replace Tauri dialog plugin with rfd integration (#6850)
Akarshan Biswas3825767384e6
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex 3c7fda787..51021644d 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -75,7 +75,6 @@ serde_json = "1.0"serde_yaml = "0.9.34"tar = "0.4"zip = "0.6"-tauri-plugin-dialog = "2.2.1"tauri-plugin-deep-link = { version = "2", optional = true }tauri-plugin-hardware = { path = "./plugins/tauri-plugin-hardware", optional = true }tauri-plugin-llamacpp = { path = "./plugins/tauri-plugin-llamacpp" }@@ -93,6 +92,11 @@ tokio = { version = "1", features = ["full"] }tokio-util = "0.7.14"url = "2.5"uuid = { version = "1.7", features = ["v4"] }+rfd = { version = "0.15.4", default-features = false, features = [+ "tokio",+ "xdg-portal",+ "common-controls-v6",+] }[dependencies.tauri]version = "2.8.5"diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.jsonindex 8d054b0c1..d41eabea4 100644--- a/src-tauri/capabilities/default.json+++ b/src-tauri/capabilities/default.json@@ -18,7 +18,6 @@"os:default","opener:default","log:default",- "dialog:default","core:webview:allow-create-webview-window","opener:allow-open-url","store:default",diff --git a/src-tauri/capabilities/desktop.json b/src-tauri/capabilities/desktop.jsonindex 2e2eaa109..f23b76b59 100644--- a/src-tauri/capabilities/desktop.json+++ b/src-tauri/capabilities/desktop.json@@ -21,7 +21,6 @@"os:default","opener:default","log:default",- "dialog:default","core:webview:allow-create-webview-window","opener:allow-open-url","store:default",@@ -30,7 +29,6 @@"llamacpp:default","deep-link:default","hardware:default",-{"identifier": "http:default","allow": [diff --git a/src-tauri/capabilities/mobile.json b/src-tauri/capabilities/mobile.jsonindex fdbda476a..6dc0e2b63 100644--- a/src-tauri/capabilities/mobile.json+++ b/src-tauri/capabilities/mobile.json@@ -18,7 +18,6 @@"os:default","opener:default","log:default",- "dialog:default","core:webview:allow-create-webview-window","opener:allow-open-url","store:default",@@ -55,4 +54,4 @@]}]-}\ No newline at end of file+}diff --git a/src-tauri/src/core/filesystem/commands.rs b/src-tauri/src/core/filesystem/commands.rsindex fe44052b8..bc441f083 100644--- a/src-tauri/src/core/filesystem/commands.rs+++ b/src-tauri/src/core/filesystem/commands.rs@@ -1,7 +1,8 @@// WARNING: These APIs will be deprecated soon due to removing FS API access from frontend.// It's added to ensure the legacy implementation from frontend still functions before removal.use super::helpers::resolve_path;-use super::models::FileStat;+use super::models::{DialogOpenOptions, FileStat};+use rfd::AsyncFileDialog;use std::fs;use tauri::Runtime;@@ -161,7 +162,10 @@ pub fn write_yaml(}#[tauri::command]-pub fn read_yaml<R: Runtime>(app: tauri::AppHandle<R>, path: &str) -> Result<serde_json::Value, String> {+pub fn read_yaml<R: Runtime>(+ app: tauri::AppHandle<R>,+ path: &str,+) -> Result<serde_json::Value, String> {let jan_data_folder = crate::core::app::commands::get_jan_data_folder_path(app.clone());let path = jan_utils::normalize_path(&jan_data_folder.join(path));if !path.starts_with(&jan_data_folder) {@@ -178,7 +182,11 @@ pub fn read_yaml<R: Runtime>(app: tauri::AppHandle<R>, path: &str) -> Result<ser}#[tauri::command]-pub fn decompress<R: Runtime>(app: tauri::AppHandle<R>, path: &str, output_dir: &str) -> Result<(), String> {+pub fn decompress<R: Runtime>(+ app: tauri::AppHandle<R>,+ path: &str,+ output_dir: &str,+) -> Result<(), String> {let jan_data_folder = crate::core::app::commands::get_jan_data_folder_path(app.clone());let path_buf = jan_utils::normalize_path(&jan_data_folder.join(path));@@ -252,3 +260,73 @@ pub fn decompress<R: Runtime>(app: tauri::AppHandle<R>, path: &str, output_dir:Ok(())}++// rfd native file dialog+#[tauri::command]+pub async fn open_dialog(+ options: Option<DialogOpenOptions>,+) -> Result<Option<serde_json::Value>, String> {+ let mut dialog = AsyncFileDialog::new();++ if let Some(opts) = options {+ // Set default path+ if let Some(path) = opts.default_path {+ dialog = dialog.set_directory(&path);+ }++ // Set filters+ if let Some(filters) = opts.filters {+ for filter in filters {+ let extensions: Vec<&str> = filter.extensions.iter().map(|s| s.as_str()).collect();+ dialog = dialog.add_filter(&filter.name, &extensions);+ }+ }++ // Handle directory vs file selection+ if opts.directory == Some(true) {+ let result = dialog.pick_folder().await;+ return Ok(result.map(|folder| {+ serde_json::Value::String(folder.path().to_string_lossy().to_string())+ }));+ }++ // Handle multiple file selection+ if opts.multiple == Some(true) {+ let result = dialog.pick_files().await;+ return Ok(result.map(|files| {+ let paths: Vec<String> = files+ .iter()+ .map(|f| f.path().to_string_lossy().to_string())+ .collect();+ serde_json::to_value(paths).unwrap()+ }));+ }+ }++ // Default: single file selection+ let result = dialog.pick_file().await;+ Ok(result.map(|file| serde_json::Value::String(file.path().to_string_lossy().to_string())))+}++#[tauri::command]+pub async fn save_dialog(options: Option<DialogOpenOptions>) -> Result<Option<String>, String> {+ let mut dialog = AsyncFileDialog::new();++ if let Some(opts) = options {+ // Set default path+ if let Some(path) = opts.default_path {+ dialog = dialog.set_directory(&path);+ }++ // Set filters+ if let Some(filters) = opts.filters {+ for filter in filters {+ let extensions: Vec<&str> = filter.extensions.iter().map(|s| s.as_str()).collect();+ dialog = dialog.add_filter(&filter.name, &extensions);+ }+ }+ }++ let result = dialog.save_file().await;+ Ok(result.map(|file| file.path().to_string_lossy().to_string()))+}diff --git a/src-tauri/src/core/filesystem/models.rs b/src-tauri/src/core/filesystem/models.rsindex cb345a15a..48d678d90 100644--- a/src-tauri/src/core/filesystem/models.rs+++ b/src-tauri/src/core/filesystem/models.rs@@ -4,3 +4,18 @@ pub struct FileStat {pub is_directory: bool,pub size: u64,}++#[derive(Debug, serde::Deserialize, serde::Serialize)]+pub struct DialogFilter {+ pub name: String,+ pub extensions: Vec<String>,+}++#[derive(Debug, serde::Deserialize, serde::Serialize)]+#[serde(rename_all = "camelCase")]+pub struct DialogOpenOptions {+ pub multiple: Option<bool>,+ pub directory: Option<bool>,+ pub default_path: Option<String>,+ pub filters: Option<Vec<DialogFilter>>,+}diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex 24da0e807..276c62150 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -13,7 +13,10 @@ use tauri_plugin_llamacpp::cleanup_llama_processes;use tauri_plugin_store::StoreExt;use tokio::sync::Mutex;-#[cfg_attr(all(mobile, any(target_os = "android", target_os = "ios")), tauri::mobile_entry_point)]+#[cfg_attr(+ all(mobile, any(target_os = "android", target_os = "ios")),+ tauri::mobile_entry_point+)]pub fn run() {let mut builder = tauri::Builder::default();#[cfg(desktop)]@@ -26,7 +29,6 @@ pub fn run() {let mut app_builder = builder.plugin(tauri_plugin_os::init())- .plugin(tauri_plugin_dialog::init()).plugin(tauri_plugin_opener::init()).plugin(tauri_plugin_http::init()).plugin(tauri_plugin_store::Builder::new().build())@@ -60,6 +62,8 @@ pub fn run() {core::filesystem::commands::write_yaml,core::filesystem::commands::read_yaml,core::filesystem::commands::decompress,+ core::filesystem::commands::open_dialog,+ core::filesystem::commands::save_dialog,// App configuration commandscore::app::commands::get_app_configurations,core::app::commands::get_user_home_path,@@ -136,7 +140,8 @@ pub fn run() {.build(),)?;#[cfg(not(any(target_os = "ios", target_os = "android")))]- app.handle().plugin(tauri_plugin_updater::Builder::new().build())?;+ app.handle()+ .plugin(tauri_plugin_updater::Builder::new().build())?;// Start migrationlet mut store_path = get_jan_data_folder_path(app.handle().clone());@@ -149,11 +154,7 @@ pub fn run() {.get("version").and_then(|v| v.as_str().map(String::from)).unwrap_or_default();- let app_version = app- .config()- .version- .clone()- .unwrap_or_default();+ let app_version = app.config().version.clone().unwrap_or_default();// Migrate extensionsif let Err(e) =setup::install_extensions(app.handle().clone(), stored_version != app_version)@@ -170,7 +171,7 @@ pub fn run() {store.set("version", serde_json::json!(app_version));store.save().expect("Failed to save store");// Migration completed-+#[cfg(desktop)]if option_env!("ENABLE_SYSTEM_TRAY_ICON").unwrap_or("false") == "true" {log::info!("Enabling system tray icon");@@ -212,7 +213,9 @@ pub fn run() {// Hide window immediately (not available on mobile platforms)if let Some(window) = app_handle.get_webview_window("main") {#[cfg(not(any(target_os = "ios", target_os = "android")))]- { let _ = window.hide(); }+ {+ let _ = window.hide();+ }let _ = window.emit("kill-mcp-servers", ());}diff --git a/web-app/package.json b/web-app/package.jsonindex 47bfaffb5..84132ec22 100644--- a/web-app/package.json+++ b/web-app/package.json@@ -42,7 +42,6 @@"@tanstack/react-virtual": "3.13.12","@tauri-apps/api": "2.8.0","@tauri-apps/plugin-deep-link": "2.4.3",- "@tauri-apps/plugin-dialog": "2.2.2","@tauri-apps/plugin-http": "2.5.0","@tauri-apps/plugin-opener": "2.5.2","@tauri-apps/plugin-os": "2.2.1",diff --git a/web-app/src/routes/settings/__tests__/general.test.tsx b/web-app/src/routes/settings/__tests__/general.test.tsxindex c9955ca95..083889c1b 100644--- a/web-app/src/routes/settings/__tests__/general.test.tsx+++ b/web-app/src/routes/settings/__tests__/general.test.tsx@@ -200,9 +200,10 @@ vi.mock('@/hooks/useServiceHub', () => ({}),}))-vi.mock('@tauri-apps/plugin-dialog', () => ({- open: vi.fn(),-}))+// Add tests for rfd dialog+// vi.mock('@tauri-apps/plugin-dialog', () => ({+// open: vi.fn(),+// }))vi.mock('@tauri-apps/plugin-opener', () => ({revealItemInDir: vi.fn(),diff --git a/web-app/src/services/dialog/tauri.ts b/web-app/src/services/dialog/tauri.tsindex d6d5fc2f2..2e4ff4f43 100644--- a/web-app/src/services/dialog/tauri.ts+++ b/web-app/src/services/dialog/tauri.ts@@ -2,7 +2,7 @@* Tauri Dialog Service - Desktop implementation*/-import { open, save } from '@tauri-apps/plugin-dialog'+import { invoke } from '@tauri-apps/api/core'import type { DialogOpenOptions } from './types'import { DefaultDialogService } from './default'@@ -13,10 +13,15 @@ export class TauriDialogService extends DefaultDialogService {if (options?.filters) {console.log('TauriDialogService: File filters:', options.filters)options.filters.forEach((filter, index) => {- console.log(`TauriDialogService: Filter ${index} - Name: "${filter.name}", Extensions:`, filter.extensions)+ console.log(+ `TauriDialogService: Filter ${index} - Name: "${filter.name}", Extensions:`,+ filter.extensions+ )})}- const result = await open(options)+ const result = await invoke<string | string[] | null>('open_dialog', {+ options,+ })console.log('TauriDialogService: Dialog result:', result)return result} catch (error) {@@ -27,7 +32,7 @@ export class TauriDialogService extends DefaultDialogService {async save(options?: DialogOpenOptions): Promise<string | null> {try {- return await save(options)+ return await invoke<string | null>('save_dialog', { options })} catch (error) {console.error('Error opening save dialog in Tauri:', error)return nulldiff --git a/web-app/vite.config.web.ts b/web-app/vite.config.web.tsindex 05a340329..ced5d5b32 100644--- a/web-app/vite.config.web.ts+++ b/web-app/vite.config.web.ts@@ -63,7 +63,6 @@ export default defineConfig({'@tauri-apps/plugin-fs','@tauri-apps/plugin-shell','@tauri-apps/plugin-clipboard-manager',- '@tauri-apps/plugin-dialog','@tauri-apps/plugin-os','@tauri-apps/plugin-process','@tauri-apps/plugin-updater',