Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/tailwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/wasm_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/wasm_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 22 additions & 3 deletions packages/cli/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Loading