Use data dir instead of home dir for dioxus-related data (#4445)

* Use data dir instead of home dir for dioxus-related data

* merge dx dir

* make windows match the pshell

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Andrew VoynovandJonathan Kelley authored and GitHub committed 2025-08-05 12:05:19 -07:00
1 parent 58c41f8561
commit 89834bc1b3
6 files changed
+33 -8

No files matched your search

+22 -3
View File
@@ -511,9 +511,28 @@ impl Workspace {
.context("Failed to find dx")
}
/// Returns the path to the dioxus home directory, used to install tools and other things
pub(crate) fn dioxus_home_dir() -> PathBuf {
dirs::home_dir().unwrap().join(".dioxus")
/// Returns the path to the dioxus data directory, used to install tools, store configs, and other things
///
/// On macOS, we prefer to not put this dir in Application Support, but rather in the home directory.
/// On Windows, we prefer to keep it in the home directory so the `dx` install dir matches the install script.
pub(crate) fn dioxus_data_dir() -> PathBuf {
static DX_HOME: std::sync::OnceLock<PathBuf> = std::sync::OnceLock::new();
DX_HOME
.get_or_init(|| {
if let Some(path) = std::env::var_os("DX_HOME") {
return PathBuf::from(path);
}
if cfg!(target_os = "macos") || cfg!(target_os = "windows") {
dirs::home_dir().unwrap().join(".dx")
} else {
dirs::data_dir()
.or_else(dirs::home_dir)
.unwrap()
.join(".dx")
}
})
.to_path_buf()
}
}