From bfe2f84f4fc8f37517eaadfa3274eb0ff79b47ab Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Fri, 15 May 2026 01:37:57 +0300 Subject: feat: add system toast delivery --- src/client/mod.rs | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'src/client') diff --git a/src/client/mod.rs b/src/client/mod.rs index 00e1b138..50a54ef3 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -672,19 +672,21 @@ fn reload_local_sound_config(sound_config: &mut crate::config::SoundConfig) { } fn handle_notify(kind: NotifyKind, message: &str, sound_config: &crate::config::SoundConfig) { - handle_notify_with_terminal_notifier( + handle_notify_with_notifiers( kind, message, sound_config, crate::terminal_notify::show_notification, + crate::platform::show_desktop_notification, ); } -fn handle_notify_with_terminal_notifier( +fn handle_notify_with_notifiers( kind: NotifyKind, message: &str, sound_config: &crate::config::SoundConfig, mut show_terminal_notification: impl FnMut(&str, Option<&str>) -> io::Result, + mut show_system_notification: impl FnMut(&str, Option<&str>) -> io::Result, ) { match kind { NotifyKind::Sound => { @@ -700,12 +702,25 @@ fn handle_notify_with_terminal_notifier( } } NotifyKind::Toast => { - debug!(message = message, "received toast notification from server"); + debug!( + message = message, + "received terminal toast notification from server" + ); let (title, body) = crate::terminal_notify::split_message(message); if let Err(err) = show_terminal_notification(title, body) { warn!(err = %err, "failed to emit terminal notification"); } } + NotifyKind::SystemToast => { + debug!( + message = message, + "received system toast notification from server" + ); + let (title, body) = crate::terminal_notify::split_message(message); + if let Err(err) = show_system_notification(title, body) { + warn!(err = %err, "failed to emit system notification"); + } + } } } @@ -1066,7 +1081,7 @@ mod tests { let sound_config = crate::config::SoundConfig::default(); let mut emitted = None; - handle_notify_with_terminal_notifier( + handle_notify_with_notifiers( NotifyKind::Toast, "pi finished: workspace 1", &sound_config, @@ -1074,6 +1089,29 @@ mod tests { emitted = Some((title.to_string(), body.map(str::to_string))); Ok(true) }, + |_, _| Ok(false), + ); + + assert_eq!( + emitted, + Some(("pi finished".to_string(), Some("workspace 1".to_string()))) + ); + } + + #[test] + fn system_toast_notify_from_server_uses_system_notifier() { + let sound_config = crate::config::SoundConfig::default(); + let mut emitted = None; + + handle_notify_with_notifiers( + NotifyKind::SystemToast, + "pi finished: workspace 1", + &sound_config, + |_, _| Ok(false), + |title, body| { + emitted = Some((title.to_string(), body.map(str::to_string))); + Ok(true) + }, ); assert_eq!( -- cgit v1.2.3