diff --git a/Cargo.lock b/Cargo.lock index b904cb17..80fa80e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1467,9 +1467,9 @@ checksum = "f2d1aab06663bdce00d6ca5e5ed586ec8d18033a771906c993a1e3755b368d85" [[package]] name = "glob" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "gltf-derive" @@ -6346,6 +6346,7 @@ dependencies = [ "expectorate", "futures", "git_rev", + "glob", "heck", "http 1.3.1", "image", diff --git a/Cargo.toml b/Cargo.toml index 9c38ebf8..6336e839 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -93,6 +93,7 @@ uuid = { version = "1.16.0", features = ["serde", "v4"] } version-compare = "0.2.0" viuer = { version = "0.9.1", features = ["print-file"] } tempfile = "3.19.1" +glob = "0.3.3" [build-dependencies] built = "0.7" diff --git a/src/cmd_app.rs b/src/cmd_app.rs index d266f64c..16b81d23 100644 --- a/src/cmd_app.rs +++ b/src/cmd_app.rs @@ -1,10 +1,11 @@ +#[cfg(target_os = "linux")] +use glob::glob; #[cfg(not(target_os = "linux"))] use std::path::PathBuf; use anyhow::Result; use clap::Parser; -#[cfg(not(target_os = "linux"))] const NOT_INSTALLED_ERROR: &str = r#"The Zoo Design Studio is not installed. Please download it from https://zoo.dev/design-studio/download If you do have the Design Studio installed already, we were @@ -31,19 +32,48 @@ pub struct CmdApp { impl crate::cmd::Command for CmdApp { async fn run(&self, ctx: &mut crate::context::Context) -> Result<()> { let app_path = get_app_path()?; + let extra_args = get_extra_args()?; writeln!(ctx.io.out, "Opening the Zoo Design Studio at {}", app_path.display())?; - std::process::Command::new(app_path).arg(&self.path).spawn()?; + std::process::Command::new(app_path) + .arg(&self.path) + .args(&extra_args) + .spawn()?; Ok(()) } } #[cfg(target_os = "linux")] -/// Get the path to the application on linux. +/// Get the path to the application on linux, assuming .AppImage installation as +/// suggested at https://github.com/KittyCAD/modeling-app/blob/ac23d40e0bc756028d3933060c0c4377e7f6b6a3/INSTALL.md#linux. +// TODO: consider other install locations fn get_app_path() -> Result { - anyhow::bail!("We don't yet support Linux, but we are working on it!"); + match dirs::home_dir() { + Some(home) => { + let path = home + .join("Applications") + .join("Zoo Design Studio-*-arm64-linux.AppImage"); + for entry in glob(&path.to_string_lossy()).expect("Failed to read glob pattern") { + match entry { + Ok(path) => return Ok(path), + Err(e) => println!("{:?}", e), + } + } + anyhow::bail!(NOT_INSTALLED_ERROR); + } + None => { + anyhow::bail!("Could not determine home directory"); + } + } +} + +#[cfg(target_os = "linux")] +/// Get the extra args for the application on linux. +fn get_extra_args() -> Result> { + let args = vec!["--no-sandbox".into()]; + Ok(args) } #[cfg(target_os = "macos")] @@ -62,6 +92,13 @@ fn get_app_path() -> Result { anyhow::bail!(NOT_INSTALLED_ERROR); } +#[cfg(target_os = "macos")] +/// Get the extra args for the application on macos. +fn get_extra_args() -> Result> { + let args = vec![]; + Ok(args) +} + #[cfg(target_os = "windows")] /// Get the path to the application on windows. fn get_app_path() -> Result { @@ -77,3 +114,10 @@ fn get_app_path() -> Result { anyhow::bail!(NOT_INSTALLED_ERROR); } + +#[cfg(target_os = "macos")] +/// Get the extra args for the application on windows. +fn get_extra_args() -> Result> { + let args = vec![]; + Ok(args) +}