51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
fn main() {
|
|
stop_stale_sidecar();
|
|
tauri_build::build()
|
|
}
|
|
|
|
#[cfg(target_os = "windows")]
|
|
fn stop_stale_sidecar() {
|
|
if std::env::var("PROFILE").as_deref() != Ok("debug") {
|
|
return;
|
|
}
|
|
|
|
let Some(out_dir) = std::env::var_os("OUT_DIR").map(std::path::PathBuf::from) else {
|
|
return;
|
|
};
|
|
let Some(target_dir) = out_dir
|
|
.parent()
|
|
.and_then(|path| path.parent())
|
|
.and_then(|path| path.parent())
|
|
.map(|path| path.to_path_buf())
|
|
else {
|
|
return;
|
|
};
|
|
let sidecar_path = target_dir.join("agent.exe");
|
|
|
|
let script = r#"
|
|
$target = [System.IO.Path]::GetFullPath($env:TAURI_SIDECAR_AGENT)
|
|
Get-CimInstance Win32_Process -Filter "Name = 'agent.exe'" |
|
|
Where-Object {
|
|
$_.ExecutablePath -and
|
|
([System.IO.Path]::GetFullPath($_.ExecutablePath) -ieq $target)
|
|
} |
|
|
ForEach-Object {
|
|
Stop-Process -Id $_.ProcessId -Force
|
|
}
|
|
"#;
|
|
|
|
let _ = std::process::Command::new("powershell")
|
|
.args([
|
|
"-NoProfile",
|
|
"-ExecutionPolicy",
|
|
"Bypass",
|
|
"-Command",
|
|
script,
|
|
])
|
|
.env("TAURI_SIDECAR_AGENT", sidecar_path)
|
|
.status();
|
|
}
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
fn stop_stale_sidecar() {}
|