diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-06 17:41:44 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-06 17:42:38 +0300 |
| commit | 4001fd2ec8ff05a982da18744b8cbde9df3ab530 (patch) | |
| tree | f8dbf984cff9a4b025e86481d3f70c89322bd79f /src/client | |
| parent | 048d8a29195d580014b24ee3fc7e89ac6bdfee8a (diff) | |
feat: improve toast ergonomics
refs #486
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/mod.rs | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/src/client/mod.rs b/src/client/mod.rs index 0a1b9507..564b5e27 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -862,8 +862,12 @@ async fn run_client_loop( ServerMessage::ServerShutdown { reason } => { return Err(ClientError::ServerShutdown { reason }); } - ServerMessage::Notify { kind, message } => { - handle_notify(kind, &message, &state.sound_config); + ServerMessage::Notify { + kind, + message, + body, + } => { + handle_notify(kind, &message, body.as_deref(), &state.sound_config); } ServerMessage::Clipboard { data } => { forward_clipboard(&data); @@ -993,10 +997,16 @@ fn reload_local_client_config( } } -fn handle_notify(kind: NotifyKind, message: &str, sound_config: &crate::config::SoundConfig) { +fn handle_notify( + kind: NotifyKind, + message: &str, + body: Option<&str>, + sound_config: &crate::config::SoundConfig, +) { handle_notify_with_notifiers( kind, message, + body, sound_config, crate::terminal_notify::show_notification, crate::platform::show_desktop_notification, @@ -1006,6 +1016,7 @@ fn handle_notify(kind: NotifyKind, message: &str, sound_config: &crate::config:: fn handle_notify_with_notifiers( kind: NotifyKind, message: &str, + body: Option<&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>, @@ -1028,8 +1039,7 @@ fn handle_notify_with_notifiers( 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) { + if let Err(err) = show_terminal_notification(message, body) { warn!(err = %err, "failed to emit terminal notification"); } } @@ -1038,8 +1048,7 @@ fn handle_notify_with_notifiers( 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) { + if let Err(err) = show_system_notification(message, body) { warn!(err = %err, "failed to emit system notification"); } } @@ -1684,7 +1693,8 @@ mod tests { handle_notify_with_notifiers( NotifyKind::Toast, - "pi finished: workspace 1", + "pi finished", + Some("workspace 1"), &sound_config, |title, body| { emitted = Some((title.to_string(), body.map(str::to_string))); @@ -1706,7 +1716,8 @@ mod tests { handle_notify_with_notifiers( NotifyKind::SystemToast, - "pi finished: workspace 1", + "pi finished", + Some("workspace 1"), &sound_config, |_, _| Ok(false), |title, body| { @@ -1722,6 +1733,32 @@ mod tests { } #[test] + fn system_toast_notify_preserves_colon_in_title() { + let sound_config = crate::config::SoundConfig::default(); + let mut emitted = None; + + handle_notify_with_notifiers( + NotifyKind::SystemToast, + "build: failed", + Some("api workspace"), + &sound_config, + |_, _| Ok(false), + |title, body| { + emitted = Some((title.to_string(), body.map(str::to_string))); + Ok(true) + }, + ); + + assert_eq!( + emitted, + Some(( + "build: failed".to_string(), + Some("api workspace".to_string()) + )) + ); + } + + #[test] fn decode_clipboard_payload_decodes_base64() { assert_eq!(decode_clipboard_payload("dGVzdA=="), Some(b"test".to_vec())); } |
