fix(notify): own toast windows when no notification daemon answers
- DesktopNotifications::start returns at once; failed() reports an error, a dead worker or 3 s without answer - The center drops the desktop client then and places its own toast, ring and meeting windows again - Unused import and descriptive comments removed, close reason as a constant Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -1,11 +1,9 @@
1
//! Desktop notifications on Linux through `org.freedesktop.Notifications`.
2
3
1
use std::collections::HashMap;
4
use std::sync::{Mutex, OnceLock};
5
2
use std::sync::atomic::{AtomicBool, Ordering};
6
3
use std::sync::mpsc::{Receiver, Sender, TryRecvError, channel};
4
use std::sync::{Mutex, OnceLock};
7
5
use std::thread;
8
use std::time::Duration;
6
use std::time::{Duration, Instant};
9
7
10
8
use futures_util::StreamExt;
11
9
use zbus::Connection;
@@ -18,9 +16,10 @@ const SERVICE: &str = "org.freedesktop.Notifications";
18
16
const PATH: &str = "/org/freedesktop/Notifications";
19
17
const INTERFACE: &str = "org.freedesktop.Notifications";
20
18
19
const STARTUP_TIMEOUT: Duration = Duration::from_secs(3);
20
21
21
static MISSING_DAEMON_LOGGED: AtomicBool = AtomicBool::new(false);
22
22
23
/// RGBA image attached as the freedesktop `image-data` hint.
24
23
#[derive(Debug, Clone, PartialEq, Eq)]
25
24
pub struct NotificationImage {
26
25
pub width: u32,
@@ -28,7 +27,6 @@ pub struct NotificationImage {
28
27
pub rgba: Vec<u8>,
29
28
}
30
29
31
/// One notification the session bus should show.
32
30
#[derive(Debug, Clone, PartialEq, Eq)]
33
31
pub struct BusNotification {
34
32
pub logical_key: String,
@@ -44,17 +42,14 @@ pub struct BusNotification {
44
42
45
43
#[derive(Debug, Clone, PartialEq, Eq)]
46
44
pub enum NotificationEvent {
47
/// Default activation or a named action (not inline-reply text).
48
45
Action {
49
46
logical_key: String,
50
47
action_id: String,
51
48
},
52
/// Inline reply text from the shell.
53
49
Reply {
54
50
logical_key: String,
55
51
text: String,
56
52
},
57
/// User or shell closed the notification (reason 2 = dismissed by user).
58
53
Closed {
59
54
logical_key: String,
60
55
reason: u32,
@@ -75,10 +70,15 @@ struct Published {
75
70
fingerprint: u64,
76
71
}
77
72
78
/// Linux desktop notification client. Poll from the UI tick like the tray.
79
73
pub struct DesktopNotifications {
80
74
commands: Sender<Command>,
81
75
events: Mutex<Receiver<NotificationEvent>>,
76
startup: Mutex<Option<Startup>>,
77
}
78
79
struct Startup {
80
ready: Receiver<Result<(), String>>,
81
since: Instant,
82
82
}
83
83
84
84
impl DesktopNotifications {
@@ -102,20 +102,36 @@ impl DesktopNotifications {
102
102
runtime.block_on(worker(command_rx, event_tx, ready_tx));
103
103
})
104
104
.ok()?;
105
match ready_rx.recv_timeout(Duration::from_secs(3)) {
106
Ok(Ok(())) => Some(Self {
107
commands: command_tx,
108
events: Mutex::new(event_rx),
109
}),
110
Ok(Err(error)) => {
111
log_missing_once(&error);
112
None
113
}
114
Err(_) => {
115
log_missing_once("notification worker did not start");
116
None
105
Some(Self {
106
commands: command_tx,
107
events: Mutex::new(event_rx),
108
startup: Mutex::new(Some(Startup {
109
ready: ready_rx,
110
since: Instant::now(),
111
})),
112
})
113
}
114
115
/// Without a notification daemon the caller falls back to its own toast windows.
116
pub fn failed(&self) -> bool {
117
let Ok(mut startup) = self.startup.lock() else {
118
return true;
119
};
120
let Some(pending) = startup.as_ref() else {
121
return false;
122
};
123
let error = match pending.ready.try_recv() {
124
Ok(Ok(())) => {
125
*startup = None;
126
return false;
117
127
}
118
}
128
Err(TryRecvError::Empty) if pending.since.elapsed() < STARTUP_TIMEOUT => return false,
129
Ok(Err(error)) => error,
130
Err(TryRecvError::Empty) => "notification daemon did not answer".to_owned(),
131
Err(TryRecvError::Disconnected) => "notification worker did not start".to_owned(),
132
};
133
log_missing_once(&error);
134
true
119
135
}
120
136
121
137
pub fn sync(&self, visible: Vec<BusNotification>, close: Vec<String>) {
@@ -205,9 +221,7 @@ async fn worker(
205
221
let mut replied_stream = receive_signal(&connection, "NotificationReplied")
206
222
.await
207
223
.ok();
208
let mut closed_stream = receive_signal(&connection, "NotificationClosed")
209
.await
210
.ok();
224
let mut closed_stream = receive_signal(&connection, "NotificationClosed").await.ok();
211
225
212
226
loop {
213
227
tokio::select! {
@@ -287,8 +301,10 @@ async fn apply_sync(
287
301
by_replace.remove(&replace_key);
288
302
}
289
303
}
290
let visible_keys: std::collections::HashSet<_> =
291
visible.iter().map(|note| note.replace_key.clone()).collect();
304
let visible_keys: std::collections::HashSet<_> = visible
305
.iter()
306
.map(|note| note.replace_key.clone())
307
.collect();
292
308
by_replace.retain(|key, published| {
293
309
if visible_keys.contains(key) {
294
310
true
@@ -330,16 +346,13 @@ async fn apply_sync(
330
346
331
347
async fn get_capabilities(connection: &Connection) -> Result<Vec<String>, String> {
332
348
let reply = connection
333
.call_method(
334
Some(SERVICE),
335
PATH,
336
Some(INTERFACE),
337
"GetCapabilities",
338
&(),
339
)
349
.call_method(Some(SERVICE), PATH, Some(INTERFACE), "GetCapabilities", &())
340
350
.await
341
351
.map_err(|error| error.to_string())?;
342
reply.body().deserialize().map_err(|error| error.to_string())
352
reply
353
.body()
354
.deserialize()
355
.map_err(|error| error.to_string())
343
356
}
344
357
345
358
async fn close_notification(connection: &Connection, id: u32) -> Result<(), String> {
@@ -367,7 +380,6 @@ async fn notify(
367
380
actions.push(String::new());
368
381
for (id, label) in ¬e.actions {
369
382
let id = if id == "inline-reply" && !supports_inline_reply {
370
// Shell has no inline reply field; treat as open-chat.
371
383
"reply-open"
372
384
} else {
373
385
id.as_str()
@@ -416,7 +428,10 @@ async fn notify(
416
428
)
417
429
.await
418
430
.map_err(|error| error.to_string())?;
419
reply.body().deserialize().map_err(|error| error.to_string())
431
reply
432
.body()
433
.deserialize()
434
.map_err(|error| error.to_string())
420
435
}
421
436
422
437
async fn receive_signal(
@@ -491,7 +506,6 @@ fn inhibit_runtime() -> Option<&'static tokio::runtime::Runtime> {
491
506
.as_ref()
492
507
}
493
508
494
/// Reads the optional `Inhibited` property (Plasma / modern GNOME). Missing → false.
495
509
pub fn notifications_inhibited() -> bool {
496
510
let Some(runtime) = inhibit_runtime() else {
497
511
return false;
@@ -1,11 +1,9 @@1
//! Desktop notifications on Linux through `org.freedesktop.Notifications`.2
3
use std::collections::HashMap;1
use std::collections::HashMap;4
use std::sync::{Mutex, OnceLock};5
use std::sync::atomic::{AtomicBool, Ordering};2
use std::sync::atomic::{AtomicBool, Ordering};6
use std::sync::mpsc::{Receiver, Sender, TryRecvError, channel};3
use std::sync::mpsc::{Receiver, Sender, TryRecvError, channel};4
use std::sync::{Mutex, OnceLock};7
use std::thread;5
use std::thread;8
use std::time::Duration;6
use std::time::{Duration, Instant};9
7
10
use futures_util::StreamExt;8
use futures_util::StreamExt;11
use zbus::Connection;9
use zbus::Connection;@@ -18,9 +16,10 @@ const SERVICE: &str = "org.freedesktop.Notifications";18
const PATH: &str = "/org/freedesktop/Notifications";16
const PATH: &str = "/org/freedesktop/Notifications";19
const INTERFACE: &str = "org.freedesktop.Notifications";17
const INTERFACE: &str = "org.freedesktop.Notifications";20
18
19
const STARTUP_TIMEOUT: Duration = Duration::from_secs(3);20
21
static MISSING_DAEMON_LOGGED: AtomicBool = AtomicBool::new(false);21
static MISSING_DAEMON_LOGGED: AtomicBool = AtomicBool::new(false);22
22
23
/// RGBA image attached as the freedesktop `image-data` hint.24
#[derive(Debug, Clone, PartialEq, Eq)]23
#[derive(Debug, Clone, PartialEq, Eq)]25
pub struct NotificationImage {24
pub struct NotificationImage {26
pub width: u32,25
pub width: u32,@@ -28,7 +27,6 @@ pub struct NotificationImage {28
pub rgba: Vec<u8>,27
pub rgba: Vec<u8>,29
}28
}30
29
31
/// One notification the session bus should show.32
#[derive(Debug, Clone, PartialEq, Eq)]30
#[derive(Debug, Clone, PartialEq, Eq)]33
pub struct BusNotification {31
pub struct BusNotification {34
pub logical_key: String,32
pub logical_key: String,@@ -44,17 +42,14 @@ pub struct BusNotification {44
42
45
#[derive(Debug, Clone, PartialEq, Eq)]43
#[derive(Debug, Clone, PartialEq, Eq)]46
pub enum NotificationEvent {44
pub enum NotificationEvent {47
/// Default activation or a named action (not inline-reply text).48
Action {45
Action {49
logical_key: String,46
logical_key: String,50
action_id: String,47
action_id: String,51
},48
},52
/// Inline reply text from the shell.53
Reply {49
Reply {54
logical_key: String,50
logical_key: String,55
text: String,51
text: String,56
},52
},57
/// User or shell closed the notification (reason 2 = dismissed by user).58
Closed {53
Closed {59
logical_key: String,54
logical_key: String,60
reason: u32,55
reason: u32,@@ -75,10 +70,15 @@ struct Published {75
fingerprint: u64,70
fingerprint: u64,76
}71
}77
72
78
/// Linux desktop notification client. Poll from the UI tick like the tray.79
pub struct DesktopNotifications {73
pub struct DesktopNotifications {80
commands: Sender<Command>,74
commands: Sender<Command>,81
events: Mutex<Receiver<NotificationEvent>>,75
events: Mutex<Receiver<NotificationEvent>>,76
startup: Mutex<Option<Startup>>,77
}78
79
struct Startup {80
ready: Receiver<Result<(), String>>,81
since: Instant,82
}82
}83
83
84
impl DesktopNotifications {84
impl DesktopNotifications {@@ -102,20 +102,36 @@ impl DesktopNotifications {102
runtime.block_on(worker(command_rx, event_tx, ready_tx));102
runtime.block_on(worker(command_rx, event_tx, ready_tx));103
})103
})104
.ok()?;104
.ok()?;105
match ready_rx.recv_timeout(Duration::from_secs(3)) {105
Some(Self {106
Ok(Ok(())) => Some(Self {106
commands: command_tx,107
commands: command_tx,107
events: Mutex::new(event_rx),108
events: Mutex::new(event_rx),108
startup: Mutex::new(Some(Startup {109
}),109
ready: ready_rx,110
Ok(Err(error)) => {110
since: Instant::now(),111
log_missing_once(&error);111
})),112
None112
})113
}113
}114
Err(_) => {114
115
log_missing_once("notification worker did not start");115
/// Without a notification daemon the caller falls back to its own toast windows.116
None116
pub fn failed(&self) -> bool {117
let Ok(mut startup) = self.startup.lock() else {118
return true;119
};120
let Some(pending) = startup.as_ref() else {121
return false;122
};123
let error = match pending.ready.try_recv() {124
Ok(Ok(())) => {125
*startup = None;126
return false;117
}127
}118
}128
Err(TryRecvError::Empty) if pending.since.elapsed() < STARTUP_TIMEOUT => return false,129
Ok(Err(error)) => error,130
Err(TryRecvError::Empty) => "notification daemon did not answer".to_owned(),131
Err(TryRecvError::Disconnected) => "notification worker did not start".to_owned(),132
};133
log_missing_once(&error);134
true119
}135
}120
136
121
pub fn sync(&self, visible: Vec<BusNotification>, close: Vec<String>) {137
pub fn sync(&self, visible: Vec<BusNotification>, close: Vec<String>) {@@ -205,9 +221,7 @@ async fn worker(205
let mut replied_stream = receive_signal(&connection, "NotificationReplied")221
let mut replied_stream = receive_signal(&connection, "NotificationReplied")206
.await222
.await207
.ok();223
.ok();208
let mut closed_stream = receive_signal(&connection, "NotificationClosed")224
let mut closed_stream = receive_signal(&connection, "NotificationClosed").await.ok();209
.await210
.ok();211
225
212
loop {226
loop {213
tokio::select! {227
tokio::select! {@@ -287,8 +301,10 @@ async fn apply_sync(287
by_replace.remove(&replace_key);301
by_replace.remove(&replace_key);288
}302
}289
}303
}290
let visible_keys: std::collections::HashSet<_> =304
let visible_keys: std::collections::HashSet<_> = visible291
visible.iter().map(|note| note.replace_key.clone()).collect();305
.iter()306
.map(|note| note.replace_key.clone())307
.collect();292
by_replace.retain(|key, published| {308
by_replace.retain(|key, published| {293
if visible_keys.contains(key) {309
if visible_keys.contains(key) {294
true310
true@@ -330,16 +346,13 @@ async fn apply_sync(330
346
331
async fn get_capabilities(connection: &Connection) -> Result<Vec<String>, String> {347
async fn get_capabilities(connection: &Connection) -> Result<Vec<String>, String> {332
let reply = connection348
let reply = connection333
.call_method(349
.call_method(Some(SERVICE), PATH, Some(INTERFACE), "GetCapabilities", &())334
Some(SERVICE),335
PATH,336
Some(INTERFACE),337
"GetCapabilities",338
&(),339
)340
.await350
.await341
.map_err(|error| error.to_string())?;351
.map_err(|error| error.to_string())?;342
reply.body().deserialize().map_err(|error| error.to_string())352
reply353
.body()354
.deserialize()355
.map_err(|error| error.to_string())343
}356
}344
357
345
async fn close_notification(connection: &Connection, id: u32) -> Result<(), String> {358
async fn close_notification(connection: &Connection, id: u32) -> Result<(), String> {@@ -367,7 +380,6 @@ async fn notify(367
actions.push(String::new());380
actions.push(String::new());368
for (id, label) in ¬e.actions {381
for (id, label) in ¬e.actions {369
let id = if id == "inline-reply" && !supports_inline_reply {382
let id = if id == "inline-reply" && !supports_inline_reply {370
// Shell has no inline reply field; treat as open-chat.371
"reply-open"383
"reply-open"372
} else {384
} else {373
id.as_str()385
id.as_str()@@ -416,7 +428,10 @@ async fn notify(416
)428
)417
.await429
.await418
.map_err(|error| error.to_string())?;430
.map_err(|error| error.to_string())?;419
reply.body().deserialize().map_err(|error| error.to_string())431
reply432
.body()433
.deserialize()434
.map_err(|error| error.to_string())420
}435
}421
436
422
async fn receive_signal(437
async fn receive_signal(@@ -491,7 +506,6 @@ fn inhibit_runtime() -> Option<&'static tokio::runtime::Runtime> {491
.as_ref()506
.as_ref()492
}507
}493
508
494
/// Reads the optional `Inhibited` property (Plasma / modern GNOME). Missing → false.495
pub fn notifications_inhibited() -> bool {509
pub fn notifications_inhibited() -> bool {496
let Some(runtime) = inhibit_runtime() else {510
let Some(runtime) = inhibit_runtime() else {497
return false;511
return false;@@ -3,10 +3,10 @@ mod windows_impl;
3
3
#[cfg(windows)]
4
4
pub use windows_impl::*;
5
5
6
#[cfg(any(target_os = "linux", target_os = "macos"))]
7
mod linux_sound;
8
6
#[cfg(target_os = "linux")]
9
7
mod linux_notifications;
8
#[cfg(any(target_os = "linux", target_os = "macos"))]
9
mod linux_sound;
10
10
#[cfg(target_os = "linux")]
11
11
mod linux_tray;
12
12
#[cfg(not(windows))]
@@ -3,10 +3,10 @@ mod windows_impl;3
#[cfg(windows)]3
#[cfg(windows)]4
pub use windows_impl::*;4
pub use windows_impl::*;5
5
6
#[cfg(any(target_os = "linux", target_os = "macos"))]7
mod linux_sound;8
#[cfg(target_os = "linux")]6
#[cfg(target_os = "linux")]9
mod linux_notifications;7
mod linux_notifications;8
#[cfg(any(target_os = "linux", target_os = "macos"))]9
mod linux_sound;10
#[cfg(target_os = "linux")]10
#[cfg(target_os = "linux")]11
mod linux_tray;11
mod linux_tray;12
#[cfg(not(windows))]12
#[cfg(not(windows))]@@ -1,14 +1,8 @@
1
//! Pure desktop-notification payloads (no D-Bus). Linux maps these to
2
//! `org.freedesktop.Notifications`; Windows keeps the GPUI card.
3
4
use super::stack::{
5
MENTION_DURATION, MESSAGE_DURATION, ToastModel,
6
};
1
use super::stack::{MENTION_DURATION, MESSAGE_DURATION, ToastModel};
7
2
use super::text::describe;
8
use crate::call::reminder::MeetingToast;
9
3
use crate::call::ReminderPhase;
4
use crate::call::reminder::MeetingToast;
10
5
11
/// Action ids used on the bus and when dispatching back into the notification center.
12
6
pub mod action {
13
7
pub const DEFAULT: &str = "default";
14
8
pub const MARK_READ: &str = "mark-read";
@@ -53,7 +47,6 @@ pub struct DesktopAction {
53
47
#[derive(Debug, Clone, PartialEq, Eq)]
54
48
pub struct DesktopPayload {
55
49
pub key: DesktopKey,
56
/// Stable replace key across updates (conversation, ring id, meeting event).
57
50
pub replace_key: String,
58
51
pub summary: String,
59
52
pub body: String,
@@ -1,14 +1,8 @@1
//! Pure desktop-notification payloads (no D-Bus). Linux maps these to1
use super::stack::{MENTION_DURATION, MESSAGE_DURATION, ToastModel};2
//! `org.freedesktop.Notifications`; Windows keeps the GPUI card.3
4
use super::stack::{5
MENTION_DURATION, MESSAGE_DURATION, ToastModel,6
};7
use super::text::describe;2
use super::text::describe;8
use crate::call::reminder::MeetingToast;9
use crate::call::ReminderPhase;3
use crate::call::ReminderPhase;4
use crate::call::reminder::MeetingToast;10
5
11
/// Action ids used on the bus and when dispatching back into the notification center.12
pub mod action {6
pub mod action {13
pub const DEFAULT: &str = "default";7
pub const DEFAULT: &str = "default";14
pub const MARK_READ: &str = "mark-read";8
pub const MARK_READ: &str = "mark-read";@@ -53,7 +47,6 @@ pub struct DesktopAction {53
#[derive(Debug, Clone, PartialEq, Eq)]47
#[derive(Debug, Clone, PartialEq, Eq)]54
pub struct DesktopPayload {48
pub struct DesktopPayload {55
pub key: DesktopKey,49
pub key: DesktopKey,56
/// Stable replace key across updates (conversation, ring id, meeting event).57
pub replace_key: String,50
pub replace_key: String,58
pub summary: String,51
pub summary: String,59
pub body: String,52
pub body: String,@@ -8,10 +8,18 @@ use store::Sidebar;
8
8
use teams_core::{ForcedAvailability, ForcedKind};
9
9
10
10
use super::badge::{Badge, badge_for};
11
#[cfg(target_os = "linux")]
12
use super::desktop_payload::{
13
self, DesktopKey, DesktopPayload, MeetingLabels, MessageLabels, RingLabels, action,
14
};
11
15
use super::incoming::IncomingTracker;
12
16
use super::layout::{self, MEETING_HEIGHT, Slot, ring_height};
13
17
use super::meeting_view::MeetingToastView;
14
18
use super::platform::{self, NativeHandle, Tray, TrayCommand, WorkArea};
19
#[cfg(target_os = "linux")]
20
use super::platform::{
21
BusNotification, DesktopNotifications, NotificationEvent, NotificationImage,
22
};
15
23
use super::ring_view::RingView;
16
24
use super::rules::{
17
25
ChatKind, Decision, Environment, Incoming, Preview, Settings, SoundThrottle, decide,
@@ -25,16 +33,7 @@ use super::stack::{
25
33
AgentToast, AgentToastKind, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE,
26
34
ToastModel, ToastStack,
27
35
};
28
#[cfg(target_os = "linux")]
29
use super::desktop_payload::{
30
self, DesktopKey, DesktopPayload, MeetingLabels, MessageLabels, RingLabels, action,
31
};
32
#[cfg(target_os = "linux")]
33
use super::platform::{
34
BusNotification, DesktopNotifications, NotificationEvent, NotificationImage,
35
};
36
36
use super::taskbar::taskbar_badge_count;
37
#[cfg(not(target_os = "linux"))]
38
37
use super::text::describe;
39
38
use super::toast::{PillView, ToastView};
40
39
use super::urgent_repeat::UrgentRepeats;
@@ -48,7 +47,6 @@ use crate::appearance::AppIcon;
48
47
use crate::autostart::{self, StartupSettings};
49
48
use crate::call::DemoScene;
50
49
use crate::data::{self, Directory, PresenceKind};
51
use crate::own_status::{self, StatusDuration};
52
50
use crate::runtime;
53
51
use crate::settings_section::SettingsSection;
54
52
use crate::single_instance;
@@ -119,12 +117,10 @@ pub struct NotificationCenter {
119
117
tray_do_not_disturb: bool,
120
118
#[cfg(target_os = "linux")]
121
119
desktop: Option<DesktopNotifications>,
122
/// Logical keys to CloseNotification on the next desktop sync (dismiss / open / ring gone).
123
120
#[cfg(target_os = "linux")]
124
121
desktop_close: Vec<String>,
125
122
#[cfg(target_os = "linux")]
126
123
desktop_published: HashSet<String>,
127
/// Decoded 64×64 notification avatars, keyed by user id and source fingerprint.
128
124
#[cfg(target_os = "linux")]
129
125
desktop_avatar_cache: HashMap<String, (u64, NotificationImage)>,
130
126
app_icon: AppIcon,
@@ -816,63 +812,58 @@ impl NotificationCenter {
816
812
817
813
fn sync_windows(&mut self, cx: &mut Context<Self>) {
818
814
#[cfg(target_os = "linux")]
819
{
820
// `tick` polls desktop events once per frame; sync only publishes.
815
if self.desktop.is_some() {
821
816
self.sync_desktop(cx);
822
817
return;
823
818
}
824
#[cfg(not(target_os = "linux"))]
819
let visible = self.visible_ids();
820
let stale: Vec<u64> = self
821
.windows
822
.keys()
823
.filter(|id| !visible.contains(id))
824
.copied()
825
.collect();
826
for id in stale {
827
self.close_window(id, cx);
828
}
829
let call_toasts = self.call_toasts(cx);
830
let stale_call_toasts: Vec<CallToast> = self
831
.call_windows
832
.keys()
833
.filter(|key| !call_toasts.iter().any(|(toast, _)| toast == *key))
834
.copied()
835
.collect();
836
for key in stale_call_toasts {
837
self.close_call_window(key, cx);
838
}
839
let area = self.work_area(cx);
840
let mut heights: Vec<f32> = self
841
.stack
842
.visible()
843
.iter()
844
.map(|toast| {
845
let lines = match &toast.agent {
846
Some(agent) => wrapped_lines(&agent.body, layout::AGENT_BODY_WIDTH, cx),
847
None => {
848
preview_lines(&describe(toast, shows_preview(&self.settings)).preview, cx)
849
}
850
};
851
layout::toast_height(toast, lines)
852
})
853
.collect();
854
heights.extend(call_toasts.iter().map(|(_, height)| *height));
855
let with_hide_all = visible.len() > 1 || self.stack.queued_count() > 0;
856
let slots = layout::stack_slots(area, self.settings.corner, &heights, with_hide_all);
857
for (id, slot) in visible.iter().zip(slots.toasts.iter()) {
858
self.place_toast(*id, *slot, area, cx);
859
}
860
for ((key, _), slot) in call_toasts
861
.iter()
862
.zip(slots.toasts.iter().skip(visible.len()))
825
863
{
826
let visible = self.visible_ids();
827
let stale: Vec<u64> = self
828
.windows
829
.keys()
830
.filter(|id| !visible.contains(id))
831
.copied()
832
.collect();
833
for id in stale {
834
self.close_window(id, cx);
835
}
836
let call_toasts = self.call_toasts(cx);
837
let stale_call_toasts: Vec<CallToast> = self
838
.call_windows
839
.keys()
840
.filter(|key| !call_toasts.iter().any(|(toast, _)| toast == *key))
841
.copied()
842
.collect();
843
for key in stale_call_toasts {
844
self.close_call_window(key, cx);
845
}
846
let area = self.work_area(cx);
847
let mut heights: Vec<f32> = self
848
.stack
849
.visible()
850
.iter()
851
.map(|toast| {
852
let lines = match &toast.agent {
853
Some(agent) => wrapped_lines(&agent.body, layout::AGENT_BODY_WIDTH, cx),
854
None => preview_lines(
855
&describe(toast, shows_preview(&self.settings)).preview,
856
cx,
857
),
858
};
859
layout::toast_height(toast, lines)
860
})
861
.collect();
862
heights.extend(call_toasts.iter().map(|(_, height)| *height));
863
let with_hide_all = visible.len() > 1 || self.stack.queued_count() > 0;
864
let slots = layout::stack_slots(area, self.settings.corner, &heights, with_hide_all);
865
for (id, slot) in visible.iter().zip(slots.toasts.iter()) {
866
self.place_toast(*id, *slot, area, cx);
867
}
868
for ((key, _), slot) in call_toasts
869
.iter()
870
.zip(slots.toasts.iter().skip(visible.len()))
871
{
872
self.place_call_toast(*key, *slot, area, cx);
873
}
874
self.sync_pill(slots.pill, area, cx);
864
self.place_call_toast(*key, *slot, area, cx);
875
865
}
866
self.sync_pill(slots.pill, area, cx);
876
867
}
877
868
878
869
fn place_call_toast(
@@ -1176,9 +1167,17 @@ impl NotificationCenter {
1176
1167
|| self.app.read(cx).rings.is_ringing()
1177
1168
|| !self.app.read(cx).meeting_toasts.is_empty();
1178
1169
#[cfg(target_os = "linux")]
1179
let needs_sync = needs_sync
1180
|| !self.desktop_close.is_empty()
1181
|| !self.desktop_published.is_empty();
1170
let needs_sync =
1171
needs_sync || !self.desktop_close.is_empty() || !self.desktop_published.is_empty();
1172
#[cfg(target_os = "linux")]
1173
if self
1174
.desktop
1175
.as_ref()
1176
.is_some_and(DesktopNotifications::failed)
1177
{
1178
self.desktop = None;
1179
self.desktop_published.clear();
1180
}
1182
1181
// Poll desktop actions before sync so dismiss/reply land in the same tick.
1183
1182
#[cfg(target_os = "linux")]
1184
1183
if self.desktop.is_some() {
@@ -1361,7 +1360,8 @@ impl NotificationCenter {
1361
1360
if let Some(user_id) = toast.sender_id.as_deref() {
1362
1361
used_avatars.insert(user_id.to_owned());
1363
1362
}
1364
let image = self.avatar_notification_image(self.app.read(cx), toast.sender_id.as_deref());
1363
let image =
1364
self.avatar_notification_image(self.app.read(cx), toast.sender_id.as_deref());
1365
1365
let payload = desktop_payload::message_payload(toast, preview_on, &message_labels);
1366
1366
visible_logical.insert(payload.key.replace_token());
1367
1367
visible.push(Self::to_bus(payload, image));
@@ -1385,7 +1385,6 @@ impl NotificationCenter {
1385
1385
if visible_logical.contains(previous) {
1386
1386
continue;
1387
1387
}
1388
// Rings and meetings must leave the shell when the call/reminder ends.
1389
1388
if previous.starts_with("ring:") || previous.starts_with("meeting:") {
1390
1389
close.push(previous.clone());
1391
1390
}
@@ -1419,13 +1418,11 @@ impl NotificationCenter {
1419
1418
logical_key,
1420
1419
reason,
1421
1420
} => {
1422
// Reason 2 = dismissed by the user in the shell.
1423
if reason == 2
1421
if reason == CLOSED_BY_USER
1424
1422
&& let Some(DesktopKey::Meeting(toast_id)) = parse_logical_key(&logical_key)
1425
1423
{
1426
self.app.update(cx, |state, cx| {
1427
state.dismiss_meeting_toast(toast_id, cx)
1428
});
1424
self.app
1425
.update(cx, |state, cx| state.dismiss_meeting_toast(toast_id, cx));
1429
1426
}
1430
1427
}
1431
1428
}
@@ -1433,7 +1430,12 @@ impl NotificationCenter {
1433
1430
}
1434
1431
1435
1432
#[cfg(target_os = "linux")]
1436
fn handle_desktop_action(&mut self, logical_key: &str, action_id: &str, cx: &mut Context<Self>) {
1433
fn handle_desktop_action(
1434
&mut self,
1435
logical_key: &str,
1436
action_id: &str,
1437
cx: &mut Context<Self>,
1438
) {
1437
1439
let Some(key) = parse_logical_key(logical_key) else {
1438
1440
return;
1439
1441
};
@@ -1851,7 +1853,6 @@ fn own_do_not_disturb(state: &AppState) -> bool {
1851
1853
own_presence(state) == PresenceKind::DoNotDisturb
1852
1854
}
1853
1855
1854
1855
1856
fn sync_loop(handle: &mut Option<SoundHandle>, audible: bool, tone: CallTone, cx: &App) {
1856
1857
match (audible, handle.is_some()) {
1857
1858
(true, false) => *handle = Some(sound_cache::start(tone.file_name(), true, cx)),
@@ -1898,6 +1899,9 @@ fn wrapped_lines(text: &str, width: f32, cx: &App) -> usize {
1898
1899
.sum()
1899
1900
}
1900
1901
1902
#[cfg(target_os = "linux")]
1903
const CLOSED_BY_USER: u32 = 2;
1904
1901
1905
#[cfg(target_os = "linux")]
1902
1906
fn parse_logical_key(key: &str) -> Option<DesktopKey> {
1903
1907
let (kind, id) = key.split_once(':')?;
@@ -8,10 +8,18 @@ use store::Sidebar;8
use teams_core::{ForcedAvailability, ForcedKind};8
use teams_core::{ForcedAvailability, ForcedKind};9
9
10
use super::badge::{Badge, badge_for};10
use super::badge::{Badge, badge_for};11
#[cfg(target_os = "linux")]12
use super::desktop_payload::{13
self, DesktopKey, DesktopPayload, MeetingLabels, MessageLabels, RingLabels, action,14
};11
use super::incoming::IncomingTracker;15
use super::incoming::IncomingTracker;12
use super::layout::{self, MEETING_HEIGHT, Slot, ring_height};16
use super::layout::{self, MEETING_HEIGHT, Slot, ring_height};13
use super::meeting_view::MeetingToastView;17
use super::meeting_view::MeetingToastView;14
use super::platform::{self, NativeHandle, Tray, TrayCommand, WorkArea};18
use super::platform::{self, NativeHandle, Tray, TrayCommand, WorkArea};19
#[cfg(target_os = "linux")]20
use super::platform::{21
BusNotification, DesktopNotifications, NotificationEvent, NotificationImage,22
};15
use super::ring_view::RingView;23
use super::ring_view::RingView;16
use super::rules::{24
use super::rules::{17
ChatKind, Decision, Environment, Incoming, Preview, Settings, SoundThrottle, decide,25
ChatKind, Decision, Environment, Incoming, Preview, Settings, SoundThrottle, decide,@@ -25,16 +33,7 @@ use super::stack::{25
AgentToast, AgentToastKind, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE,33
AgentToast, AgentToastKind, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE,26
ToastModel, ToastStack,34
ToastModel, ToastStack,27
};35
};28
#[cfg(target_os = "linux")]29
use super::desktop_payload::{30
self, DesktopKey, DesktopPayload, MeetingLabels, MessageLabels, RingLabels, action,31
};32
#[cfg(target_os = "linux")]33
use super::platform::{34
BusNotification, DesktopNotifications, NotificationEvent, NotificationImage,35
};36
use super::taskbar::taskbar_badge_count;36
use super::taskbar::taskbar_badge_count;37
#[cfg(not(target_os = "linux"))]38
use super::text::describe;37
use super::text::describe;39
use super::toast::{PillView, ToastView};38
use super::toast::{PillView, ToastView};40
use super::urgent_repeat::UrgentRepeats;39
use super::urgent_repeat::UrgentRepeats;@@ -48,7 +47,6 @@ use crate::appearance::AppIcon;48
use crate::autostart::{self, StartupSettings};47
use crate::autostart::{self, StartupSettings};49
use crate::call::DemoScene;48
use crate::call::DemoScene;50
use crate::data::{self, Directory, PresenceKind};49
use crate::data::{self, Directory, PresenceKind};51
use crate::own_status::{self, StatusDuration};52
use crate::runtime;50
use crate::runtime;53
use crate::settings_section::SettingsSection;51
use crate::settings_section::SettingsSection;54
use crate::single_instance;52
use crate::single_instance;@@ -119,12 +117,10 @@ pub struct NotificationCenter {119
tray_do_not_disturb: bool,117
tray_do_not_disturb: bool,120
#[cfg(target_os = "linux")]118
#[cfg(target_os = "linux")]121
desktop: Option<DesktopNotifications>,119
desktop: Option<DesktopNotifications>,122
/// Logical keys to CloseNotification on the next desktop sync (dismiss / open / ring gone).123
#[cfg(target_os = "linux")]120
#[cfg(target_os = "linux")]124
desktop_close: Vec<String>,121
desktop_close: Vec<String>,125
#[cfg(target_os = "linux")]122
#[cfg(target_os = "linux")]126
desktop_published: HashSet<String>,123
desktop_published: HashSet<String>,127
/// Decoded 64×64 notification avatars, keyed by user id and source fingerprint.128
#[cfg(target_os = "linux")]124
#[cfg(target_os = "linux")]129
desktop_avatar_cache: HashMap<String, (u64, NotificationImage)>,125
desktop_avatar_cache: HashMap<String, (u64, NotificationImage)>,130
app_icon: AppIcon,126
app_icon: AppIcon,@@ -816,63 +812,58 @@ impl NotificationCenter {816
812
817
fn sync_windows(&mut self, cx: &mut Context<Self>) {813
fn sync_windows(&mut self, cx: &mut Context<Self>) {818
#[cfg(target_os = "linux")]814
#[cfg(target_os = "linux")]819
{815
if self.desktop.is_some() {820
// `tick` polls desktop events once per frame; sync only publishes.821
self.sync_desktop(cx);816
self.sync_desktop(cx);822
return;817
return;823
}818
}824
#[cfg(not(target_os = "linux"))]819
let visible = self.visible_ids();820
let stale: Vec<u64> = self821
.windows822
.keys()823
.filter(|id| !visible.contains(id))824
.copied()825
.collect();826
for id in stale {827
self.close_window(id, cx);828
}829
let call_toasts = self.call_toasts(cx);830
let stale_call_toasts: Vec<CallToast> = self831
.call_windows832
.keys()833
.filter(|key| !call_toasts.iter().any(|(toast, _)| toast == *key))834
.copied()835
.collect();836
for key in stale_call_toasts {837
self.close_call_window(key, cx);838
}839
let area = self.work_area(cx);840
let mut heights: Vec<f32> = self841
.stack842
.visible()843
.iter()844
.map(|toast| {845
let lines = match &toast.agent {846
Some(agent) => wrapped_lines(&agent.body, layout::AGENT_BODY_WIDTH, cx),847
None => {848
preview_lines(&describe(toast, shows_preview(&self.settings)).preview, cx)849
}850
};851
layout::toast_height(toast, lines)852
})853
.collect();854
heights.extend(call_toasts.iter().map(|(_, height)| *height));855
let with_hide_all = visible.len() > 1 || self.stack.queued_count() > 0;856
let slots = layout::stack_slots(area, self.settings.corner, &heights, with_hide_all);857
for (id, slot) in visible.iter().zip(slots.toasts.iter()) {858
self.place_toast(*id, *slot, area, cx);859
}860
for ((key, _), slot) in call_toasts861
.iter()862
.zip(slots.toasts.iter().skip(visible.len()))825
{863
{826
let visible = self.visible_ids();864
self.place_call_toast(*key, *slot, area, cx);827
let stale: Vec<u64> = self828
.windows829
.keys()830
.filter(|id| !visible.contains(id))831
.copied()832
.collect();833
for id in stale {834
self.close_window(id, cx);835
}836
let call_toasts = self.call_toasts(cx);837
let stale_call_toasts: Vec<CallToast> = self838
.call_windows839
.keys()840
.filter(|key| !call_toasts.iter().any(|(toast, _)| toast == *key))841
.copied()842
.collect();843
for key in stale_call_toasts {844
self.close_call_window(key, cx);845
}846
let area = self.work_area(cx);847
let mut heights: Vec<f32> = self848
.stack849
.visible()850
.iter()851
.map(|toast| {852
let lines = match &toast.agent {853
Some(agent) => wrapped_lines(&agent.body, layout::AGENT_BODY_WIDTH, cx),854
None => preview_lines(855
&describe(toast, shows_preview(&self.settings)).preview,856
cx,857
),858
};859
layout::toast_height(toast, lines)860
})861
.collect();862
heights.extend(call_toasts.iter().map(|(_, height)| *height));863
let with_hide_all = visible.len() > 1 || self.stack.queued_count() > 0;864
let slots = layout::stack_slots(area, self.settings.corner, &heights, with_hide_all);865
for (id, slot) in visible.iter().zip(slots.toasts.iter()) {866
self.place_toast(*id, *slot, area, cx);867
}868
for ((key, _), slot) in call_toasts869
.iter()870
.zip(slots.toasts.iter().skip(visible.len()))871
{872
self.place_call_toast(*key, *slot, area, cx);873
}874
self.sync_pill(slots.pill, area, cx);875
}865
}866
self.sync_pill(slots.pill, area, cx);876
}867
}877
868
878
fn place_call_toast(869
fn place_call_toast(@@ -1176,9 +1167,17 @@ impl NotificationCenter {1176
|| self.app.read(cx).rings.is_ringing()1167
|| self.app.read(cx).rings.is_ringing()1177
|| !self.app.read(cx).meeting_toasts.is_empty();1168
|| !self.app.read(cx).meeting_toasts.is_empty();1178
#[cfg(target_os = "linux")]1169
#[cfg(target_os = "linux")]1179
let needs_sync = needs_sync1170
let needs_sync =1180
|| !self.desktop_close.is_empty()1171
needs_sync || !self.desktop_close.is_empty() || !self.desktop_published.is_empty();1181
|| !self.desktop_published.is_empty();1172
#[cfg(target_os = "linux")]1173
if self1174
.desktop1175
.as_ref()1176
.is_some_and(DesktopNotifications::failed)1177
{1178
self.desktop = None;1179
self.desktop_published.clear();1180
}1182
// Poll desktop actions before sync so dismiss/reply land in the same tick.1181
// Poll desktop actions before sync so dismiss/reply land in the same tick.1183
#[cfg(target_os = "linux")]1182
#[cfg(target_os = "linux")]1184
if self.desktop.is_some() {1183
if self.desktop.is_some() {@@ -1361,7 +1360,8 @@ impl NotificationCenter {1361
if let Some(user_id) = toast.sender_id.as_deref() {1360
if let Some(user_id) = toast.sender_id.as_deref() {1362
used_avatars.insert(user_id.to_owned());1361
used_avatars.insert(user_id.to_owned());1363
}1362
}1364
let image = self.avatar_notification_image(self.app.read(cx), toast.sender_id.as_deref());1363
let image =1364
self.avatar_notification_image(self.app.read(cx), toast.sender_id.as_deref());1365
let payload = desktop_payload::message_payload(toast, preview_on, &message_labels);1365
let payload = desktop_payload::message_payload(toast, preview_on, &message_labels);1366
visible_logical.insert(payload.key.replace_token());1366
visible_logical.insert(payload.key.replace_token());1367
visible.push(Self::to_bus(payload, image));1367
visible.push(Self::to_bus(payload, image));@@ -1385,7 +1385,6 @@ impl NotificationCenter {1385
if visible_logical.contains(previous) {1385
if visible_logical.contains(previous) {1386
continue;1386
continue;1387
}1387
}1388
// Rings and meetings must leave the shell when the call/reminder ends.1389
if previous.starts_with("ring:") || previous.starts_with("meeting:") {1388
if previous.starts_with("ring:") || previous.starts_with("meeting:") {1390
close.push(previous.clone());1389
close.push(previous.clone());1391
}1390
}@@ -1419,13 +1418,11 @@ impl NotificationCenter {1419
logical_key,1418
logical_key,1420
reason,1419
reason,1421
} => {1420
} => {1422
// Reason 2 = dismissed by the user in the shell.1421
if reason == CLOSED_BY_USER1423
if reason == 21424
&& let Some(DesktopKey::Meeting(toast_id)) = parse_logical_key(&logical_key)1422
&& let Some(DesktopKey::Meeting(toast_id)) = parse_logical_key(&logical_key)1425
{1423
{1426
self.app.update(cx, |state, cx| {1424
self.app1427
state.dismiss_meeting_toast(toast_id, cx)1425
.update(cx, |state, cx| state.dismiss_meeting_toast(toast_id, cx));1428
});1429
}1426
}1430
}1427
}1431
}1428
}@@ -1433,7 +1430,12 @@ impl NotificationCenter {1433
}1430
}1434
1431
1435
#[cfg(target_os = "linux")]1432
#[cfg(target_os = "linux")]1436
fn handle_desktop_action(&mut self, logical_key: &str, action_id: &str, cx: &mut Context<Self>) {1433
fn handle_desktop_action(1434
&mut self,1435
logical_key: &str,1436
action_id: &str,1437
cx: &mut Context<Self>,1438
) {1437
let Some(key) = parse_logical_key(logical_key) else {1439
let Some(key) = parse_logical_key(logical_key) else {1438
return;1440
return;1439
};1441
};@@ -1851,7 +1853,6 @@ fn own_do_not_disturb(state: &AppState) -> bool {1851
own_presence(state) == PresenceKind::DoNotDisturb1853
own_presence(state) == PresenceKind::DoNotDisturb1852
}1854
}1853
1855
1854
1855
fn sync_loop(handle: &mut Option<SoundHandle>, audible: bool, tone: CallTone, cx: &App) {1856
fn sync_loop(handle: &mut Option<SoundHandle>, audible: bool, tone: CallTone, cx: &App) {1856
match (audible, handle.is_some()) {1857
match (audible, handle.is_some()) {1857
(true, false) => *handle = Some(sound_cache::start(tone.file_name(), true, cx)),1858
(true, false) => *handle = Some(sound_cache::start(tone.file_name(), true, cx)),@@ -1898,6 +1899,9 @@ fn wrapped_lines(text: &str, width: f32, cx: &App) -> usize {1898
.sum()1899
.sum()1899
}1900
}1900
1901
1902
#[cfg(target_os = "linux")]1903
const CLOSED_BY_USER: u32 = 2;1904
1901
#[cfg(target_os = "linux")]1905
#[cfg(target_os = "linux")]1902
fn parse_logical_key(key: &str) -> Option<DesktopKey> {1906
fn parse_logical_key(key: &str) -> Option<DesktopKey> {1903
let (kind, id) = key.split_once(':')?;1907
let (kind, id) = key.split_once(':')?;