use std::{
path::PathBuf,
process::{Child, Command, Stdio},
};
use super::LOCAL_DEV;
pub fn spawn_devtools_app() -> std::io::Result<Child> {
if option_env!("__DEVTOOLS_LOCAL_DEVELOPMENT").is_some() {
Command::new(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../target/debug/desktop")
.with_extension(if cfg!(windows) { "exe" } else { "" }),
)
} else {
devtools_production_command()
}
.arg("crabnebula-devtools://embedded")
.stdout(if LOCAL_DEV {
Stdio::inherit()
} else {
Stdio::piped()
})
.stderr(if LOCAL_DEV {
Stdio::inherit()
} else {
Stdio::piped()
})
.spawn()
}
#[cfg(windows)]
fn devtools_production_command() -> Command {
let powershell_path = std::env::var("SYSTEMROOT").map_or_else(
|_| "powershell.exe".to_string(),
|p| format!("{p}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
);
let mut cmd = Command::new(powershell_path);
cmd.arg("-NoProfile").arg("Start-Process");
cmd
}
#[cfg(not(windows))]
fn devtools_production_command() -> Command {
Command::new(if cfg!(target_os = "macos") {
"open"
} else {
"xdg-open"
})
}