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:
1 parent
58c41f8561
commit
89834bc1b3
6 files changed
+33
-8
No files matched your search
+7
-1
@@ -84,7 +84,13 @@ else
|
||||
dx_uri=$github_repo/releases/download/$1/dx-$target.zip
|
||||
fi
|
||||
|
||||
dx_install="${DX_INSTALL:-$HOME/.dx}"
|
||||
if [ -n "$DX_INSTALL" ]; then
|
||||
dx_install="$DX_INSTALL"
|
||||
elif [ -n "$XDG_DATA_HOME" ]; then
|
||||
dx_install="$XDG_DATA_HOME/dx"
|
||||
else
|
||||
dx_install="$HOME/.dx"
|
||||
fi
|
||||
bin_dir="$dx_install/bin"
|
||||
exe="$bin_dir/dx"
|
||||
cargo_bin_dir="$HOME/.cargo/bin"
|
||||
|
||||
@@ -120,7 +120,7 @@ impl SelfUpdate {
|
||||
})
|
||||
.context("No suitable asset found")?;
|
||||
|
||||
let install_dir = Workspace::dioxus_home_dir().join("self-update");
|
||||
let install_dir = Workspace::dioxus_data_dir().join("self-update");
|
||||
std::fs::create_dir_all(&install_dir).context("Failed to create install directory")?;
|
||||
|
||||
tracing::info!("Downloading update from Github");
|
||||
|
||||
@@ -224,7 +224,7 @@ impl TailwindCli {
|
||||
}
|
||||
|
||||
fn install_dir(&self) -> Result<PathBuf> {
|
||||
let bindgen_dir = Workspace::dioxus_home_dir().join("tailwind/");
|
||||
let bindgen_dir = Workspace::dioxus_data_dir().join("tailwind/");
|
||||
Ok(bindgen_dir)
|
||||
}
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ impl WasmBindgen {
|
||||
}
|
||||
|
||||
fn install_dir(&self) -> anyhow::Result<PathBuf> {
|
||||
let bindgen_dir = Workspace::dioxus_home_dir().join("wasm-bindgen/");
|
||||
let bindgen_dir = Workspace::dioxus_data_dir().join("wasm-bindgen/");
|
||||
std::fs::create_dir_all(&bindgen_dir)?;
|
||||
Ok(bindgen_dir)
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ pub fn installed_location() -> Option<PathBuf> {
|
||||
}
|
||||
|
||||
fn install_dir() -> PathBuf {
|
||||
Workspace::dioxus_home_dir().join("binaryen")
|
||||
Workspace::dioxus_data_dir().join("binaryen")
|
||||
}
|
||||
|
||||
fn installed_bin_name() -> &'static str {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user