use std::path::{Path, PathBuf};
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=scripts/triage-notify/main.swift");
println!("cargo:rerun-if-changed=scripts/triage-notify/Info.plist");
println!("cargo:rerun-if-changed=scripts/triage-notify/build.sh");
if !cfg!(target_os = "macos") {
return;
}
let script = Path::new("scripts/triage-notify/build.sh");
if !script.exists() {
return;
}
let out_dir = std::env::var_os("OUT_DIR")
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("scripts/triage-notify"));
let built_app = out_dir.join("triage-notify.app");
match Command::new("bash").arg(script).arg(&out_dir).status() {
Ok(s) if s.success() => {
stage_to_user_config(&built_app);
}
Ok(s) => {
println!(
"cargo:warning=triage-notify build exited {} — falling back to osascript-only notifications",
s
);
}
Err(e) => {
println!(
"cargo:warning=triage-notify build skipped: {} — install Xcode CLI tools (`xcode-select --install`) for click-to-jump notifications",
e
);
}
}
}
fn stage_to_user_config(built_app: &Path) {
let Some(home) = std::env::var_os("HOME") else {
println!("cargo:warning=HOME unset; skipping notify-helper stage");
return;
};
let dest_dir: PathBuf = PathBuf::from(home).join(".config/triage");
let dest_app = dest_dir.join("triage-notify.app");
if let Err(e) = std::fs::create_dir_all(&dest_dir) {
println!("cargo:warning=could not create {}: {e}", dest_dir.display());
return;
}
if dest_app.exists()
&& let Err(e) = std::fs::remove_dir_all(&dest_app)
{
println!(
"cargo:warning=could not remove stale {}: {e}",
dest_app.display()
);
return;
}
let status = Command::new("cp")
.arg("-R")
.arg(built_app)
.arg(&dest_app)
.status();
match status {
Ok(s) if s.success() => {}
Ok(s) => println!(
"cargo:warning=cp -R {} {} exited {}",
built_app.display(),
dest_app.display(),
s
),
Err(e) => println!(
"cargo:warning=failed to stage triage-notify.app to {}: {e}",
dest_app.display()
),
}
}