diff --git a/.github/install.sh b/.github/install.sh index 56dfe22e2e..19bd8aae2e 100755 --- a/.github/install.sh +++ b/.github/install.sh @@ -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" diff --git a/packages/cli/src/cli/update.rs b/packages/cli/src/cli/update.rs index 1237c2321b..9cc2a9bcd2 100644 --- a/packages/cli/src/cli/update.rs +++ b/packages/cli/src/cli/update.rs @@ -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"); diff --git a/packages/cli/src/tailwind.rs b/packages/cli/src/tailwind.rs index 9848a22dd0..3392c063bd 100644 --- a/packages/cli/src/tailwind.rs +++ b/packages/cli/src/tailwind.rs @@ -224,7 +224,7 @@ impl TailwindCli { } fn install_dir(&self) -> Result { - let bindgen_dir = Workspace::dioxus_home_dir().join("tailwind/"); + let bindgen_dir = Workspace::dioxus_data_dir().join("tailwind/"); Ok(bindgen_dir) } diff --git a/packages/cli/src/wasm_bindgen.rs b/packages/cli/src/wasm_bindgen.rs index 2bb30e7225..f2cfa15f66 100644 --- a/packages/cli/src/wasm_bindgen.rs +++ b/packages/cli/src/wasm_bindgen.rs @@ -400,7 +400,7 @@ impl WasmBindgen { } fn install_dir(&self) -> anyhow::Result { - 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) } diff --git a/packages/cli/src/wasm_opt.rs b/packages/cli/src/wasm_opt.rs index e35b8d9f61..e8d7d5330a 100644 --- a/packages/cli/src/wasm_opt.rs +++ b/packages/cli/src/wasm_opt.rs @@ -243,7 +243,7 @@ pub fn installed_location() -> Option { } fn install_dir() -> PathBuf { - Workspace::dioxus_home_dir().join("binaryen") + Workspace::dioxus_data_dir().join("binaryen") } fn installed_bin_name() -> &'static str { diff --git a/packages/cli/src/workspace.rs b/packages/cli/src/workspace.rs index 191819e65e..3f9b2de324 100644 --- a/packages/cli/src/workspace.rs +++ b/packages/cli/src/workspace.rs @@ -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 = 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() } }