BlueGit

ict rusty-teams

fix(tray): do not disturb sets the published status, notifications opens its settings

- tray "Do not disturb" forces and resets the own presence like the status menu
- checkbox follows the own presence, also when it changes elsewhere
- "Notifications" opens Settings on the Notifications section
- local do_not_disturb flag removed, it had no other switch

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-14 · 2 weeks ago

Hash
0e3132f86faa53fb178cd89bc514fae50120d7f2
Parent
0318f862
3 files changed +31 −40
crates/app-state/src/notify/rules.rs +0 −21
@@ -76,7 +76,6 @@ pub struct Settings {
76 76 pub corner: Corner,
77 77 pub flash: bool,
78 78 pub close_to_tray: bool,
79 pub do_not_disturb: bool,
80 79 pub mute_in_calls: bool,
81 80 pub sounds: SoundSettings,
82 81 }
@@ -88,7 +87,6 @@ impl Default for Settings {
88 87 corner: Corner::BottomRight,
89 88 flash: true,
90 89 close_to_tray: true,
91 do_not_disturb: false,
92 90 mute_in_calls: false,
93 91 sounds: SoundSettings::default(),
94 92 }
@@ -262,7 +260,6 @@ pub fn decide(settings: &Settings, incoming: &Incoming, environment: Environment
262 260 || environment.system_quiet
263 261 || (environment.own_do_not_disturb && !urgent)
264 262 || environment.paused
265 || settings.do_not_disturb
266 263 || (settings.mute_in_calls && environment.in_call)
267 264 || (!urgent && !account_toasts(&settings.account, incoming));
268 265 if suppressed {
@@ -287,7 +284,6 @@ pub fn decide_proposal(
287 284 || environment.system_quiet
288 285 || environment.own_do_not_disturb
289 286 || environment.paused
290 || settings.do_not_disturb
291 287 || (settings.mute_in_calls && environment.in_call);
292 288 if suppressed {
293 289 return SILENT;
@@ -431,18 +427,6 @@ mod tests {
431 427 decide_proposal(&settings, DesktopNotifications::Off, Environment::default()),
432 428 SILENT
433 429 );
434 let quiet = Settings {
435 do_not_disturb: true,
436 ..Default::default()
437 };
438 assert_eq!(
439 decide_proposal(
440 &quiet,
441 DesktopNotifications::default(),
442 Environment::default()
443 ),
444 SILENT
445 );
446 430 }
447 431
448 432 #[test]
@@ -468,11 +452,6 @@ mod tests {
468 452 ] {
469 453 assert_eq!(decide(&Settings::default(), &group(), environment), SILENT);
470 454 }
471 let settings = Settings {
472 do_not_disturb: true,
473 ..Default::default()
474 };
475 assert_eq!(decide(&settings, &group(), Environment::default()), SILENT);
476 455 }
477 456
478 457 fn urgent() -> Incoming {
@@ -76,7 +76,6 @@ pub struct Settings {
76 pub corner: Corner,
76 pub corner: Corner,
77 pub flash: bool,
77 pub flash: bool,
78 pub close_to_tray: bool,
78 pub close_to_tray: bool,
79 pub do_not_disturb: bool,
80 pub mute_in_calls: bool,
79 pub mute_in_calls: bool,
81 pub sounds: SoundSettings,
80 pub sounds: SoundSettings,
82}
81}
@@ -88,7 +87,6 @@ impl Default for Settings {
88 corner: Corner::BottomRight,
87 corner: Corner::BottomRight,
89 flash: true,
88 flash: true,
90 close_to_tray: true,
89 close_to_tray: true,
91 do_not_disturb: false,
92 mute_in_calls: false,
90 mute_in_calls: false,
93 sounds: SoundSettings::default(),
91 sounds: SoundSettings::default(),
94 }
92 }
@@ -262,7 +260,6 @@ pub fn decide(settings: &Settings, incoming: &Incoming, environment: Environment
262 || environment.system_quiet
260 || environment.system_quiet
263 || (environment.own_do_not_disturb && !urgent)
261 || (environment.own_do_not_disturb && !urgent)
264 || environment.paused
262 || environment.paused
265 || settings.do_not_disturb
266 || (settings.mute_in_calls && environment.in_call)
263 || (settings.mute_in_calls && environment.in_call)
267 || (!urgent && !account_toasts(&settings.account, incoming));
264 || (!urgent && !account_toasts(&settings.account, incoming));
268 if suppressed {
265 if suppressed {
@@ -287,7 +284,6 @@ pub fn decide_proposal(
287 || environment.system_quiet
284 || environment.system_quiet
288 || environment.own_do_not_disturb
285 || environment.own_do_not_disturb
289 || environment.paused
286 || environment.paused
290 || settings.do_not_disturb
291 || (settings.mute_in_calls && environment.in_call);
287 || (settings.mute_in_calls && environment.in_call);
292 if suppressed {
288 if suppressed {
293 return SILENT;
289 return SILENT;
@@ -431,18 +427,6 @@ mod tests {
431 decide_proposal(&settings, DesktopNotifications::Off, Environment::default()),
427 decide_proposal(&settings, DesktopNotifications::Off, Environment::default()),
432 SILENT
428 SILENT
433 );
429 );
434 let quiet = Settings {
435 do_not_disturb: true,
436 ..Default::default()
437 };
438 assert_eq!(
439 decide_proposal(
440 &quiet,
441 DesktopNotifications::default(),
442 Environment::default()
443 ),
444 SILENT
445 );
446 }
430 }
447
431
448 #[test]
432 #[test]
@@ -468,11 +452,6 @@ mod tests {
468 ] {
452 ] {
469 assert_eq!(decide(&Settings::default(), &group(), environment), SILENT);
453 assert_eq!(decide(&Settings::default(), &group(), environment), SILENT);
470 }
454 }
471 let settings = Settings {
472 do_not_disturb: true,
473 ..Default::default()
474 };
475 assert_eq!(decide(&settings, &group(), Environment::default()), SILENT);
476 }
455 }
477
456
478 fn urgent() -> Incoming {
457 fn urgent() -> Incoming {
crates/app-state/src/notify/settings.rs +0 −6
@@ -52,10 +52,6 @@ fn serialize(settings: &Settings) -> String {
52 52 "close_to_tray".to_owned(),
53 53 settings.close_to_tray.to_string(),
54 54 ),
55 (
56 "do_not_disturb".to_owned(),
57 settings.do_not_disturb.to_string(),
58 ),
59 55 (
60 56 "mute_in_calls".to_owned(),
61 57 settings.mute_in_calls.to_string(),
@@ -86,7 +82,6 @@ fn parse(text: &str) -> Settings {
86 82 "corner" => settings.corner = Corner::from_key(value).unwrap_or_default(),
87 83 "taskbar_flash" => settings.flash = flag,
88 84 "close_to_tray" => settings.close_to_tray = flag,
89 "do_not_disturb" => settings.do_not_disturb = flag,
90 85 "mute_in_calls" => settings.mute_in_calls = flag,
91 86 _ => set_ringtone(&mut sounds.ringtones, key, value),
92 87 }
@@ -121,7 +116,6 @@ mod tests {
121 116 corner: Corner::TopLeft,
122 117 flash: false,
123 118 close_to_tray: false,
124 do_not_disturb: true,
125 119 mute_in_calls: true,
126 120 sounds: SoundSettings {
127 121 notification_sound: false,
@@ -52,10 +52,6 @@ fn serialize(settings: &Settings) -> String {
52 "close_to_tray".to_owned(),
52 "close_to_tray".to_owned(),
53 settings.close_to_tray.to_string(),
53 settings.close_to_tray.to_string(),
54 ),
54 ),
55 (
56 "do_not_disturb".to_owned(),
57 settings.do_not_disturb.to_string(),
58 ),
59 (
55 (
60 "mute_in_calls".to_owned(),
56 "mute_in_calls".to_owned(),
61 settings.mute_in_calls.to_string(),
57 settings.mute_in_calls.to_string(),
@@ -86,7 +82,6 @@ fn parse(text: &str) -> Settings {
86 "corner" => settings.corner = Corner::from_key(value).unwrap_or_default(),
82 "corner" => settings.corner = Corner::from_key(value).unwrap_or_default(),
87 "taskbar_flash" => settings.flash = flag,
83 "taskbar_flash" => settings.flash = flag,
88 "close_to_tray" => settings.close_to_tray = flag,
84 "close_to_tray" => settings.close_to_tray = flag,
89 "do_not_disturb" => settings.do_not_disturb = flag,
90 "mute_in_calls" => settings.mute_in_calls = flag,
85 "mute_in_calls" => settings.mute_in_calls = flag,
91 _ => set_ringtone(&mut sounds.ringtones, key, value),
86 _ => set_ringtone(&mut sounds.ringtones, key, value),
92 }
87 }
@@ -121,7 +116,6 @@ mod tests {
121 corner: Corner::TopLeft,
116 corner: Corner::TopLeft,
122 flash: false,
117 flash: false,
123 close_to_tray: false,
118 close_to_tray: false,
124 do_not_disturb: true,
125 mute_in_calls: true,
119 mute_in_calls: true,
126 sounds: SoundSettings {
120 sounds: SoundSettings {
127 notification_sound: false,
121 notification_sound: false,
crates/app/src/notify/center.rs +31 −13
@@ -5,6 +5,7 @@ use std::time::{Duration, Instant};
5 5 use chrono::{DateTime, Utc};
6 6 use gpui_kit::*;
7 7 use store::Sidebar;
8 use teams_core::{ForcedAvailability, ForcedKind};
8 9
9 10 use super::badge::{Badge, badge_for};
10 11 use super::incoming::IncomingTracker;
@@ -105,6 +106,7 @@ pub struct NotificationCenter {
105 106 hover_hold: bool,
106 107 unread_mentions: HashSet<String>,
107 108 tray: Option<Tray>,
109 tray_do_not_disturb: bool,
108 110 app_icon: AppIcon,
109 111 shown_badge: Option<Badge>,
110 112 shown_mention_dot: bool,
@@ -129,12 +131,13 @@ impl NotificationCenter {
129 131 let mut settings = settings::load(&app.read(cx).store);
130 132 settings.account = app.read(cx).account_chat_settings().notifications;
131 133 let app_icon = active_appearance::current(cx).app_icon;
134 let tray_do_not_disturb = own_do_not_disturb(app.read(cx));
132 135 let tray = if app.read(cx).mode.demo {
133 136 None
134 137 } else {
135 138 Tray::new(
136 139 settings.sounds.notification_sound,
137 settings.do_not_disturb,
140 tray_do_not_disturb,
138 141 app_icon.png(),
139 142 )
140 143 };
@@ -186,6 +189,7 @@ impl NotificationCenter {
186 189 hover_hold: false,
187 190 unread_mentions: HashSet::new(),
188 191 tray,
192 tray_do_not_disturb,
189 193 app_icon,
190 194 shown_badge: None,
191 195 shown_mention_dot: false,
@@ -356,7 +360,7 @@ impl NotificationCenter {
356 360 let previous = self.settings.sounds.clone();
357 361 change(&mut self.settings);
358 362 settings::save(&self.app.read(cx).store, &self.settings);
359 self.sync_tray();
363 self.sync_tray(cx);
360 364 if self.settings.sounds != previous {
361 365 let updated = self.settings.sounds.clone();
362 366 self.app.update(cx, |state, cx| {
@@ -381,7 +385,7 @@ impl NotificationCenter {
381 385 }
382 386 self.settings.sounds = account;
383 387 settings::save(&self.app.read(cx).store, &self.settings);
384 self.sync_tray();
388 self.sync_tray(cx);
385 389 if !self.demo_mode {
386 390 self.prefetch_sounds(cx);
387 391 }
@@ -420,6 +424,7 @@ impl NotificationCenter {
420 424 AppEvent::Messages(conversation_id) => self.on_messages(conversation_id, cx),
421 425 AppEvent::Selection => self.on_selection(cx),
422 426 AppEvent::Sidebar => self.refresh_badge(cx),
427 AppEvent::Directory => self.sync_tray_presence(cx),
423 428 AppEvent::Ring => self.on_rings_changed(cx),
424 429 AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
425 430 AppEvent::MeetingChime => self.on_meeting_chime(cx),
@@ -920,9 +925,7 @@ impl NotificationCenter {
920 925 }
921 926
922 927 fn reminders_quiet(&self, cx: &App) -> bool {
923 self.settings.do_not_disturb
924 || platform::system_quiet()
925 || own_do_not_disturb(self.app.read(cx))
928 platform::system_quiet() || own_do_not_disturb(self.app.read(cx))
926 929 }
927 930
928 931 fn on_rings_changed(&mut self, cx: &mut Context<Self>) {
@@ -1176,13 +1179,11 @@ impl NotificationCenter {
1176 1179 TrayCommand::ToggleSound => self.update_settings(cx, |settings| {
1177 1180 settings.sounds.notification_sound = !settings.sounds.notification_sound
1178 1181 }),
1179 TrayCommand::ToggleDoNotDisturb => self.update_settings(cx, |settings| {
1180 settings.do_not_disturb = !settings.do_not_disturb
1181 }),
1182 TrayCommand::ToggleDoNotDisturb => self.toggle_own_do_not_disturb(cx),
1182 1183 TrayCommand::Settings => {
1183 1184 self.raise_main_window(cx);
1184 1185 self.app.update(cx, |state, cx| {
1185 state.open_settings(SettingsSection::General, cx)
1186 state.open_settings(SettingsSection::Notifications, cx)
1186 1187 });
1187 1188 }
1188 1189 TrayCommand::Quit => cx.quit(),
@@ -1190,6 +1191,22 @@ impl NotificationCenter {
1190 1191 }
1191 1192 }
1192 1193
1194 fn toggle_own_do_not_disturb(&mut self, cx: &mut Context<Self>) {
1195 let forced = (!own_do_not_disturb(self.app.read(cx))).then_some(ForcedAvailability {
1196 kind: ForcedKind::DoNotDisturb,
1197 expires_at: None,
1198 });
1199 self.app
1200 .update(cx, |state, cx| state.set_own_availability(forced, cx));
1201 self.sync_tray(cx);
1202 }
1203
1204 fn sync_tray_presence(&mut self, cx: &App) {
1205 if self.tray_do_not_disturb != own_do_not_disturb(self.app.read(cx)) {
1206 self.sync_tray(cx);
1207 }
1208 }
1209
1193 1210 fn toggle_main_window(&mut self, cx: &mut Context<Self>) {
1194 1211 if self.main_window_active(cx) {
1195 1212 if let Some(native) = self.main_native {
@@ -1246,11 +1263,12 @@ impl NotificationCenter {
1246 1263 }
1247 1264 }
1248 1265
1249 fn sync_tray(&self) {
1266 fn sync_tray(&mut self, cx: &App) {
1267 self.tray_do_not_disturb = own_do_not_disturb(self.app.read(cx));
1250 1268 if let Some(tray) = &self.tray {
1251 1269 tray.sync(
1252 1270 self.settings.sounds.notification_sound,
1253 self.settings.do_not_disturb,
1271 self.tray_do_not_disturb,
1254 1272 !self.unread_mentions.is_empty(),
1255 1273 );
1256 1274 }
@@ -1281,7 +1299,7 @@ impl NotificationCenter {
1281 1299 }
1282 1300 }
1283 1301 self.shown_badge = badge;
1284 self.sync_tray();
1302 self.sync_tray(cx);
1285 1303 }
1286 1304
1287 1305 pub fn set_hover(&mut self, id: u64, hovered: bool, cx: &mut Context<Self>) {
@@ -5,6 +5,7 @@ use std::time::{Duration, Instant};
5use chrono::{DateTime, Utc};
5use chrono::{DateTime, Utc};
6use gpui_kit::*;
6use gpui_kit::*;
7use store::Sidebar;
7use store::Sidebar;
8use teams_core::{ForcedAvailability, ForcedKind};
8
9
9use super::badge::{Badge, badge_for};
10use super::badge::{Badge, badge_for};
10use super::incoming::IncomingTracker;
11use super::incoming::IncomingTracker;
@@ -105,6 +106,7 @@ pub struct NotificationCenter {
105 hover_hold: bool,
106 hover_hold: bool,
106 unread_mentions: HashSet<String>,
107 unread_mentions: HashSet<String>,
107 tray: Option<Tray>,
108 tray: Option<Tray>,
109 tray_do_not_disturb: bool,
108 app_icon: AppIcon,
110 app_icon: AppIcon,
109 shown_badge: Option<Badge>,
111 shown_badge: Option<Badge>,
110 shown_mention_dot: bool,
112 shown_mention_dot: bool,
@@ -129,12 +131,13 @@ impl NotificationCenter {
129 let mut settings = settings::load(&app.read(cx).store);
131 let mut settings = settings::load(&app.read(cx).store);
130 settings.account = app.read(cx).account_chat_settings().notifications;
132 settings.account = app.read(cx).account_chat_settings().notifications;
131 let app_icon = active_appearance::current(cx).app_icon;
133 let app_icon = active_appearance::current(cx).app_icon;
134 let tray_do_not_disturb = own_do_not_disturb(app.read(cx));
132 let tray = if app.read(cx).mode.demo {
135 let tray = if app.read(cx).mode.demo {
133 None
136 None
134 } else {
137 } else {
135 Tray::new(
138 Tray::new(
136 settings.sounds.notification_sound,
139 settings.sounds.notification_sound,
137 settings.do_not_disturb,
140 tray_do_not_disturb,
138 app_icon.png(),
141 app_icon.png(),
139 )
142 )
140 };
143 };
@@ -186,6 +189,7 @@ impl NotificationCenter {
186 hover_hold: false,
189 hover_hold: false,
187 unread_mentions: HashSet::new(),
190 unread_mentions: HashSet::new(),
188 tray,
191 tray,
192 tray_do_not_disturb,
189 app_icon,
193 app_icon,
190 shown_badge: None,
194 shown_badge: None,
191 shown_mention_dot: false,
195 shown_mention_dot: false,
@@ -356,7 +360,7 @@ impl NotificationCenter {
356 let previous = self.settings.sounds.clone();
360 let previous = self.settings.sounds.clone();
357 change(&mut self.settings);
361 change(&mut self.settings);
358 settings::save(&self.app.read(cx).store, &self.settings);
362 settings::save(&self.app.read(cx).store, &self.settings);
359 self.sync_tray();
363 self.sync_tray(cx);
360 if self.settings.sounds != previous {
364 if self.settings.sounds != previous {
361 let updated = self.settings.sounds.clone();
365 let updated = self.settings.sounds.clone();
362 self.app.update(cx, |state, cx| {
366 self.app.update(cx, |state, cx| {
@@ -381,7 +385,7 @@ impl NotificationCenter {
381 }
385 }
382 self.settings.sounds = account;
386 self.settings.sounds = account;
383 settings::save(&self.app.read(cx).store, &self.settings);
387 settings::save(&self.app.read(cx).store, &self.settings);
384 self.sync_tray();
388 self.sync_tray(cx);
385 if !self.demo_mode {
389 if !self.demo_mode {
386 self.prefetch_sounds(cx);
390 self.prefetch_sounds(cx);
387 }
391 }
@@ -420,6 +424,7 @@ impl NotificationCenter {
420 AppEvent::Messages(conversation_id) => self.on_messages(conversation_id, cx),
424 AppEvent::Messages(conversation_id) => self.on_messages(conversation_id, cx),
421 AppEvent::Selection => self.on_selection(cx),
425 AppEvent::Selection => self.on_selection(cx),
422 AppEvent::Sidebar => self.refresh_badge(cx),
426 AppEvent::Sidebar => self.refresh_badge(cx),
427 AppEvent::Directory => self.sync_tray_presence(cx),
423 AppEvent::Ring => self.on_rings_changed(cx),
428 AppEvent::Ring => self.on_rings_changed(cx),
424 AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
429 AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
425 AppEvent::MeetingChime => self.on_meeting_chime(cx),
430 AppEvent::MeetingChime => self.on_meeting_chime(cx),
@@ -920,9 +925,7 @@ impl NotificationCenter {
920 }
925 }
921
926
922 fn reminders_quiet(&self, cx: &App) -> bool {
927 fn reminders_quiet(&self, cx: &App) -> bool {
923 self.settings.do_not_disturb
928 platform::system_quiet() || own_do_not_disturb(self.app.read(cx))
924 || platform::system_quiet()
925 || own_do_not_disturb(self.app.read(cx))
926 }
929 }
927
930
928 fn on_rings_changed(&mut self, cx: &mut Context<Self>) {
931 fn on_rings_changed(&mut self, cx: &mut Context<Self>) {
@@ -1176,13 +1179,11 @@ impl NotificationCenter {
1176 TrayCommand::ToggleSound => self.update_settings(cx, |settings| {
1179 TrayCommand::ToggleSound => self.update_settings(cx, |settings| {
1177 settings.sounds.notification_sound = !settings.sounds.notification_sound
1180 settings.sounds.notification_sound = !settings.sounds.notification_sound
1178 }),
1181 }),
1179 TrayCommand::ToggleDoNotDisturb => self.update_settings(cx, |settings| {
1182 TrayCommand::ToggleDoNotDisturb => self.toggle_own_do_not_disturb(cx),
1180 settings.do_not_disturb = !settings.do_not_disturb
1181 }),
1182 TrayCommand::Settings => {
1183 TrayCommand::Settings => {
1183 self.raise_main_window(cx);
1184 self.raise_main_window(cx);
1184 self.app.update(cx, |state, cx| {
1185 self.app.update(cx, |state, cx| {
1185 state.open_settings(SettingsSection::General, cx)
1186 state.open_settings(SettingsSection::Notifications, cx)
1186 });
1187 });
1187 }
1188 }
1188 TrayCommand::Quit => cx.quit(),
1189 TrayCommand::Quit => cx.quit(),
@@ -1190,6 +1191,22 @@ impl NotificationCenter {
1190 }
1191 }
1191 }
1192 }
1192
1193
1194 fn toggle_own_do_not_disturb(&mut self, cx: &mut Context<Self>) {
1195 let forced = (!own_do_not_disturb(self.app.read(cx))).then_some(ForcedAvailability {
1196 kind: ForcedKind::DoNotDisturb,
1197 expires_at: None,
1198 });
1199 self.app
1200 .update(cx, |state, cx| state.set_own_availability(forced, cx));
1201 self.sync_tray(cx);
1202 }
1203
1204 fn sync_tray_presence(&mut self, cx: &App) {
1205 if self.tray_do_not_disturb != own_do_not_disturb(self.app.read(cx)) {
1206 self.sync_tray(cx);
1207 }
1208 }
1209
1193 fn toggle_main_window(&mut self, cx: &mut Context<Self>) {
1210 fn toggle_main_window(&mut self, cx: &mut Context<Self>) {
1194 if self.main_window_active(cx) {
1211 if self.main_window_active(cx) {
1195 if let Some(native) = self.main_native {
1212 if let Some(native) = self.main_native {
@@ -1246,11 +1263,12 @@ impl NotificationCenter {
1246 }
1263 }
1247 }
1264 }
1248
1265
1249 fn sync_tray(&self) {
1266 fn sync_tray(&mut self, cx: &App) {
1267 self.tray_do_not_disturb = own_do_not_disturb(self.app.read(cx));
1250 if let Some(tray) = &self.tray {
1268 if let Some(tray) = &self.tray {
1251 tray.sync(
1269 tray.sync(
1252 self.settings.sounds.notification_sound,
1270 self.settings.sounds.notification_sound,
1253 self.settings.do_not_disturb,
1271 self.tray_do_not_disturb,
1254 !self.unread_mentions.is_empty(),
1272 !self.unread_mentions.is_empty(),
1255 );
1273 );
1256 }
1274 }
@@ -1281,7 +1299,7 @@ impl NotificationCenter {
1281 }
1299 }
1282 }
1300 }
1283 self.shown_badge = badge;
1301 self.shown_badge = badge;
1284 self.sync_tray();
1302 self.sync_tray(cx);
1285 }
1303 }
1286
1304
1287 pub fn set_hover(&mut self, id: u64, hovered: bool, cx: &mut Context<Self>) {
1305 pub fn set_hover(&mut self, id: u64, hovered: bool, cx: &mut Context<Self>) {