Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(desktop): store portable agent runtime in data dir

t8y2c67706db5147
diff --git a/crates/dbx-core/src/connection.rs b/crates/dbx-core/src/connection.rs
index 21f0e23edc..cc38030ee0 100644
--- a/crates/dbx-core/src/connection.rs
+++ b/crates/dbx-core/src/connection.rs
@@ -102,6 +102,15 @@ impl AppState {
storage: Storage,
plugin_dir: PathBuf,
app_version: impl Into<String>,
+ ) -> Self {
+ Self::new_with_plugin_and_agent_dir_and_app_version(storage, plugin_dir, default_agent_dir(), app_version)
+ }
+
+ pub fn new_with_plugin_and_agent_dir_and_app_version(
+ storage: Storage,
+ plugin_dir: PathBuf,
+ agent_dir: PathBuf,
+ app_version: impl Into<String>,
) -> Self {
Self {
connections: RwLock::new(HashMap::new()),
@@ -112,7 +121,7 @@ impl AppState {
storage,
plugins: PluginRegistry::new(plugin_dir),
agent_manager: crate::agent_manager::AgentManager::new_with_base_dir_and_app_version(
- default_agent_dir(),
+ agent_dir,
app_version,
),
}
@@ -1206,6 +1215,24 @@ mod tests {
(AppState::new(storage), dir)
}
+ #[tokio::test]
+ async fn app_state_uses_explicit_agent_dir() {
+ let dir = std::env::temp_dir().join(format!("dbx-core-agent-dir-test-{}", uuid::Uuid::new_v4()));
+ std::fs::create_dir_all(&dir).unwrap();
+ let storage = Storage::open(&dir.join("storage.db")).await.unwrap();
+ let agent_dir = dir.join("agents");
+
+ let state = AppState::new_with_plugin_and_agent_dir_and_app_version(
+ storage,
+ dir.join("plugins"),
+ agent_dir.clone(),
+ "0.0.0-test",
+ );
+
+ assert_eq!(state.agent_manager.base_dir(), &agent_dir);
+ let _ = std::fs::remove_dir_all(dir);
+ }
+
fn live_postgres_like_config(
db_type: DatabaseType,
host: &str,
diff --git a/src-tauri/src/data_dir.rs b/src-tauri/src/data_dir.rs
index dcc704a2ab..29205ee111 100644
--- a/src-tauri/src/data_dir.rs
+++ b/src-tauri/src/data_dir.rs
@@ -18,6 +18,10 @@ pub fn resolve_data_dir(default_app_data_dir: PathBuf) -> PathBuf {
default_app_data_dir
}
+pub fn uses_custom_data_dir() -> bool {
+ std::env::var_os("DBX_DATA_DIR").filter(|value| !value.is_empty()).is_some() || is_portable_mode()
+}
+
#[cfg(target_os = "windows")]
pub fn is_portable_mode() -> bool {
current_exe_dir().is_some_and(|dir| portable_marker_exists(&dir))
@@ -60,11 +64,20 @@ fn is_portable_mode_from_inputs(exe_dir: Option<PathBuf>, portable_marker_exists
exe_dir.is_some() && portable_marker_exists
}
+#[cfg(test)]
+fn uses_custom_data_dir_from_inputs(
+ env_data_dir: Option<PathBuf>,
+ exe_dir: Option<PathBuf>,
+ portable_marker_exists: bool,
+) -> bool {
+ env_data_dir.is_some() || is_portable_mode_from_inputs(exe_dir, portable_marker_exists)
+}
+
#[cfg(test)]
mod tests {
use std::path::PathBuf;
- use super::{is_portable_mode_from_inputs, resolve_data_dir_from_inputs};
+ use super::{is_portable_mode_from_inputs, resolve_data_dir_from_inputs, uses_custom_data_dir_from_inputs};
#[test]
fn uses_portable_data_dir_when_marker_exists() {
@@ -84,4 +97,11 @@ mod tests {
assert!(!is_portable_mode_from_inputs(Some(PathBuf::from(r"D:\Apps\DBX")), false));
assert!(!is_portable_mode_from_inputs(None, true));
}
+
+ #[test]
+ fn custom_data_dir_is_used_for_env_override_or_portable_mode() {
+ assert!(uses_custom_data_dir_from_inputs(Some(PathBuf::from(r"D:\DBXData")), None, false));
+ assert!(uses_custom_data_dir_from_inputs(None, Some(PathBuf::from(r"D:\Apps\DBX")), true));
+ assert!(!uses_custom_data_dir_from_inputs(None, Some(PathBuf::from(r"D:\Apps\DBX")), false));
+ }
}
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 2d2e481b52..3aa6703bd3 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -286,11 +286,20 @@ pub fn run() {
let desktop_settings = tauri::async_runtime::block_on(storage.load_desktop_settings()).unwrap_or_default();
eprintln!("[STARTUP] storage ready in {:?}", t.elapsed());
- let state = Arc::new(AppState::new_with_plugin_dir_and_app_version(
- storage,
- data_dir.join("plugins"),
- env!("CARGO_PKG_VERSION"),
- ));
+ let state = if data_dir::uses_custom_data_dir() {
+ Arc::new(AppState::new_with_plugin_and_agent_dir_and_app_version(
+ storage,
+ data_dir.join("plugins"),
+ data_dir.join("agents"),
+ env!("CARGO_PKG_VERSION"),
+ ))
+ } else {
+ Arc::new(AppState::new_with_plugin_dir_and_app_version(
+ storage,
+ data_dir.join("plugins"),
+ env!("CARGO_PKG_VERSION"),
+ ))
+ };
app.manage(state.clone());
app.manage(commands::external_sql::ExternalSqlOpenState::default());
app.manage(commands::external_db::ExternalDbOpenState::default());