diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-15 01:37:57 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-15 01:37:57 +0300 |
| commit | bfe2f84f4fc8f37517eaadfa3274eb0ff79b47ab (patch) | |
| tree | b97f7700b5e13627d273a83e41eb7f3366b65039 /src/client | |
| parent | 80d70642b7a86d1d9473ed55586412e0345d015e (diff) | |
feat: add system toast delivery
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/mod.rs | 46 |
1 files changed, 42 insertions, 4 deletions
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<bool>, + mut show_system_notification: impl FnMut(&str, Option<&str>) -> io::Result<bool>, ) { 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!( |
