tauri-plugin-devtools-app 3.0.0-alpha.1

Connect with the Devtools for Tauri application
Documentation
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() {
        // built by `setup_desktop_app_dev` into the root workspace's target directory
        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"
    })
}