aboutsummaryrefslogtreecommitdiff
path: root/crates/dinggerd/src/notify.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/dinggerd/src/notify.rs')
-rw-r--r--crates/dinggerd/src/notify.rs31
1 files changed, 22 insertions, 9 deletions
diff --git a/crates/dinggerd/src/notify.rs b/crates/dinggerd/src/notify.rs
index 9fcfcde..e619d6d 100644
--- a/crates/dinggerd/src/notify.rs
+++ b/crates/dinggerd/src/notify.rs
@@ -3,7 +3,7 @@
use std::process::{Command, Stdio};
use std::sync::atomic::{AtomicU64, Ordering};
-use tracing::{debug, warn};
+use tracing::{info, warn};
pub enum NotificationKind {
NeedsAttention,
@@ -63,14 +63,27 @@ pub fn play_sound(kind: &NotificationKind) {
}
}
+/// Deliver a macOS notification without blocking the caller: the delivery
+/// call waits on Notification Center for seconds, and the watcher must keep
+/// updating the UI meanwhile.
pub fn send_notification(agent_label: &str, kind: &NotificationKind, context: &str) {
- debug!(agent = agent_label, kind = kind.title(), context, "notifying");
+ info!(agent = agent_label, kind = kind.title(), context, "notifying");
let title = format!("{agent_label} {}", kind.title());
- let notification = mac_notification_sys::Notification::new()
- .title(title.as_str())
- .message(context)
- .send();
- if let Err(err) = notification {
- warn!(%err, "failed to deliver macOS notification");
- }
+ let context = context.to_string();
+ std::thread::spawn(move || {
+ // Test seam: deliver through a command instead (tests/e2e.sh).
+ if let Ok(command) = std::env::var("DINGGER_NOTIFIER") {
+ let _ = std::process::Command::new("sh")
+ .args(["-c", &command, &title, &context])
+ .status();
+ return;
+ }
+ let notification = mac_notification_sys::Notification::new()
+ .title(title.as_str())
+ .message(context.as_str())
+ .send();
+ if let Err(err) = notification {
+ warn!(%err, "failed to deliver macOS notification");
+ }
+ });
}