BlueGit

ict rusty-teams

fix(tray): match Teams presence menu, drop local mute

The tray now sets published presence through the same status choices as
the profile menu. Mute sound is removed: it only flipped a local sound
flag and did not match Teams.

metis Joachim Mild · pushed by metis

Authored 2026-11-14 · 2 weeks ago

Hash
03f5ca73dbd2ced15f643f128af1549142a78dff
Parent
0e3132f8
8 files changed +471 −120
crates/app-base/src/notify/mod.rs +1 −0
@@ -3,5 +3,6 @@ pub mod badge;
3 3 #[cfg_attr(not(windows), allow(dead_code))]
4 4 pub mod platform;
5 5 pub mod sound_cache;
6 pub mod tray_status;
6 7
7 8 pub use chatsvc::sounds;
@@ -3,5 +3,6 @@ pub mod badge;
3#[cfg_attr(not(windows), allow(dead_code))]
3#[cfg_attr(not(windows), allow(dead_code))]
4pub mod platform;
4pub mod platform;
5pub mod sound_cache;
5pub mod sound_cache;
6pub mod tray_status;
6
7
7pub use chatsvc::sounds;
8pub use chatsvc::sounds;
crates/app-base/src/notify/platform/linux_tray.rs +110 −31
@@ -4,12 +4,14 @@
4 4 use std::sync::Mutex;
5 5 use std::sync::mpsc::{Receiver, Sender, channel};
6 6
7 use chatsvc::ForcedKind;
7 8 use ksni::blocking::{Handle, TrayMethods as _};
8 use ksni::menu::{CheckmarkItem, StandardItem};
9 use ksni::menu::{CheckmarkItem, StandardItem, SubMenu};
9 10 use ksni::{Category, Icon, MenuItem, ToolTip};
10 11
11 use super::TrayCommand;
12 use super::{TrayCommand, TrayPresence};
12 13 use crate::linux_desktop::DESKTOP_ID;
14 use crate::notify::tray_status;
13 15
14 16 const TRAY_ICON_SIZES: [u32; 3] = [22, 32, 64];
15 17 const DOT_COLOR: [u8; 4] = [0xef, 0x44, 0x44, 0xff];
@@ -17,10 +19,10 @@ const DOT_COLOR: [u8; 4] = [0xef, 0x44, 0x44, 0xff];
17 19 #[derive(Clone)]
18 20 struct Labels {
19 21 open: String,
20 mute_sound: String,
21 do_not_disturb: String,
22 22 notifications: String,
23 23 quit: String,
24 duration: String,
25 reset: String,
24 26 }
25 27
26 28 impl Labels {
@@ -28,10 +30,10 @@ impl Labels {
28 30 let tr = crate::ui_locale::tr;
29 31 Labels {
30 32 open: tr("tray.open"),
31 mute_sound: tr("tray.mute_sound"),
32 do_not_disturb: tr("tray.do_not_disturb"),
33 33 notifications: tr("tray.notifications"),
34 34 quit: tr("tray.quit"),
35 duration: tray_status::duration_menu_label().to_owned(),
36 reset: tray_status::reset_label().to_owned(),
35 37 }
36 38 }
37 39 }
@@ -39,8 +41,8 @@ impl Labels {
39 41 struct Item {
40 42 commands: Sender<TrayCommand>,
41 43 labels: Labels,
42 sound_on: bool,
43 do_not_disturb: bool,
44 title: String,
45 forced: Option<ForcedKind>,
44 46 mention: bool,
45 47 plain: Vec<Icon>,
46 48 dotted: Vec<Icon>,
@@ -57,6 +59,63 @@ fn menu_label(text: &str) -> String {
57 59 text.replace('_', "__")
58 60 }
59 61
62 fn status_submenu(item: &Item) -> MenuItem<Item> {
63 let mut entries = Vec::new();
64 for kind in tray_status::STATUS_CHOICES {
65 let label = tray_status::choice_label(kind);
66 entries.push(
67 CheckmarkItem {
68 label: menu_label(label),
69 checked: item.forced == Some(kind),
70 activate: Box::new(move |item: &mut Item| {
71 item.send(TrayCommand::SetStatus(kind))
72 }),
73 ..Default::default()
74 }
75 .into(),
76 );
77 }
78 entries.push(MenuItem::Separator);
79 let duration_enabled = tray_status::duration_target(item.forced).is_some();
80 let mut duration_items = Vec::new();
81 for duration in tray_status::STATUS_DURATIONS {
82 duration_items.push(
83 StandardItem {
84 label: menu_label(tray_status::duration_label(duration)),
85 enabled: duration_enabled,
86 activate: Box::new(move |item: &mut Item| {
87 item.send(TrayCommand::SetStatusDuration(duration))
88 }),
89 ..Default::default()
90 }
91 .into(),
92 );
93 }
94 entries.push(
95 SubMenu {
96 label: menu_label(&item.labels.duration),
97 enabled: duration_enabled,
98 submenu: duration_items,
99 ..Default::default()
100 }
101 .into(),
102 );
103 entries.push(
104 StandardItem {
105 label: menu_label(&item.labels.reset),
106 activate: Box::new(|item: &mut Item| item.send(TrayCommand::ResetStatus)),
107 ..Default::default()
108 }
109 .into(),
110 );
111 SubMenu {
112 label: menu_label(&item.title),
113 submenu: entries,
114 ..Default::default()
115 }
116 .into()
117 }
118
60 119 impl ksni::Tray for Item {
61 120 fn id(&self) -> String {
62 121 DESKTOP_ID.to_owned()
@@ -98,23 +157,10 @@ impl ksni::Tray for Item {
98 157 }
99 158 .into(),
100 159 MenuItem::Separator,
101 CheckmarkItem {
102 label: menu_label(&self.labels.mute_sound),
103 checked: !self.sound_on,
104 activate: Box::new(|item: &mut Self| item.send(TrayCommand::ToggleSound)),
105 ..Default::default()
106 }
107 .into(),
108 CheckmarkItem {
109 label: menu_label(&self.labels.do_not_disturb),
110 checked: self.do_not_disturb,
111 activate: Box::new(|item: &mut Self| item.send(TrayCommand::ToggleDoNotDisturb)),
112 ..Default::default()
113 }
114 .into(),
160 status_submenu(self),
115 161 StandardItem {
116 162 label: menu_label(&self.labels.notifications),
117 activate: Box::new(|item: &mut Self| item.send(TrayCommand::Settings)),
163 activate: Box::new(|item: &mut Self| item.send(TrayCommand::Notifications)),
118 164 ..Default::default()
119 165 }
120 166 .into(),
@@ -137,15 +183,15 @@ pub struct Tray {
137 183
138 184 impl Tray {
139 185 /// `None` when there is no session bus or no tray host (no StatusNotifierWatcher).
140 pub fn new(sound_on: bool, do_not_disturb: bool, icon_png: &[u8]) -> Option<Self> {
186 pub fn new(presence: TrayPresence, icon_png: &[u8]) -> Option<Self> {
141 187 let (plain, dotted) = tray_icons(icon_png)?;
142 188 let (sender, receiver) = channel();
143 189 let item = Item {
144 190 commands: sender,
145 191 labels: Labels::current(),
146 sound_on,
147 do_not_disturb,
148 mention: false,
192 title: presence.title,
193 forced: presence.forced,
194 mention: presence.mention,
149 195 plain,
150 196 dotted,
151 197 };
@@ -185,13 +231,13 @@ impl Tray {
185 231 });
186 232 }
187 233
188 pub fn sync(&self, sound_on: bool, do_not_disturb: bool, mention: bool) {
234 pub fn sync(&self, presence: TrayPresence) {
189 235 let labels = Labels::current();
190 236 self.handle.update(move |item| {
191 237 item.labels = labels;
192 item.sound_on = sound_on;
193 item.do_not_disturb = do_not_disturb;
194 item.mention = mention;
238 item.title = presence.title;
239 item.forced = presence.forced;
240 item.mention = presence.mention;
195 241 });
196 242 }
197 243 }
@@ -272,4 +318,37 @@ mod tests {
272 318 fn underscores_stay_visible_in_menu_labels() {
273 319 assert_eq!(menu_label("Do_not_disturb"), "Do__not__disturb");
274 320 }
321
322 #[test]
323 fn status_submenu_lists_every_choice_and_reset() {
324 let (sender, _receiver) = channel();
325 let item = Item {
326 commands: sender,
327 labels: Labels::current(),
328 title: "Available".into(),
329 forced: Some(ForcedKind::Busy),
330 mention: false,
331 plain: Vec::new(),
332 dotted: Vec::new(),
333 };
334 let MenuItem::SubMenu(menu) = status_submenu(&item) else {
335 panic!("expected status submenu");
336 };
337 assert_eq!(menu.label, "Available");
338 let labels: Vec<_> = menu
339 .submenu
340 .iter()
341 .filter_map(|entry| match entry {
342 MenuItem::Checkmark(item) => Some(item.label.as_str()),
343 MenuItem::Standard(item) => Some(item.label.as_str()),
344 MenuItem::SubMenu(item) => Some(item.label.as_str()),
345 _ => None,
346 })
347 .collect();
348 for kind in tray_status::STATUS_CHOICES {
349 assert!(labels.contains(&tray_status::choice_label(kind)));
350 }
351 assert!(labels.contains(&tray_status::reset_label()));
352 assert!(labels.contains(&tray_status::duration_menu_label()));
353 }
275 354 }
@@ -4,12 +4,14 @@
4use std::sync::Mutex;
4use std::sync::Mutex;
5use std::sync::mpsc::{Receiver, Sender, channel};
5use std::sync::mpsc::{Receiver, Sender, channel};
6
6
7use chatsvc::ForcedKind;
7use ksni::blocking::{Handle, TrayMethods as _};
8use ksni::blocking::{Handle, TrayMethods as _};
8use ksni::menu::{CheckmarkItem, StandardItem};
9use ksni::menu::{CheckmarkItem, StandardItem, SubMenu};
9use ksni::{Category, Icon, MenuItem, ToolTip};
10use ksni::{Category, Icon, MenuItem, ToolTip};
10
11
11use super::TrayCommand;
12use super::{TrayCommand, TrayPresence};
12use crate::linux_desktop::DESKTOP_ID;
13use crate::linux_desktop::DESKTOP_ID;
14use crate::notify::tray_status;
13
15
14const TRAY_ICON_SIZES: [u32; 3] = [22, 32, 64];
16const TRAY_ICON_SIZES: [u32; 3] = [22, 32, 64];
15const DOT_COLOR: [u8; 4] = [0xef, 0x44, 0x44, 0xff];
17const DOT_COLOR: [u8; 4] = [0xef, 0x44, 0x44, 0xff];
@@ -17,10 +19,10 @@ const DOT_COLOR: [u8; 4] = [0xef, 0x44, 0x44, 0xff];
17#[derive(Clone)]
19#[derive(Clone)]
18struct Labels {
20struct Labels {
19 open: String,
21 open: String,
20 mute_sound: String,
21 do_not_disturb: String,
22 notifications: String,
22 notifications: String,
23 quit: String,
23 quit: String,
24 duration: String,
25 reset: String,
24}
26}
25
27
26impl Labels {
28impl Labels {
@@ -28,10 +30,10 @@ impl Labels {
28 let tr = crate::ui_locale::tr;
30 let tr = crate::ui_locale::tr;
29 Labels {
31 Labels {
30 open: tr("tray.open"),
32 open: tr("tray.open"),
31 mute_sound: tr("tray.mute_sound"),
32 do_not_disturb: tr("tray.do_not_disturb"),
33 notifications: tr("tray.notifications"),
33 notifications: tr("tray.notifications"),
34 quit: tr("tray.quit"),
34 quit: tr("tray.quit"),
35 duration: tray_status::duration_menu_label().to_owned(),
36 reset: tray_status::reset_label().to_owned(),
35 }
37 }
36 }
38 }
37}
39}
@@ -39,8 +41,8 @@ impl Labels {
39struct Item {
41struct Item {
40 commands: Sender<TrayCommand>,
42 commands: Sender<TrayCommand>,
41 labels: Labels,
43 labels: Labels,
42 sound_on: bool,
44 title: String,
43 do_not_disturb: bool,
45 forced: Option<ForcedKind>,
44 mention: bool,
46 mention: bool,
45 plain: Vec<Icon>,
47 plain: Vec<Icon>,
46 dotted: Vec<Icon>,
48 dotted: Vec<Icon>,
@@ -57,6 +59,63 @@ fn menu_label(text: &str) -> String {
57 text.replace('_', "__")
59 text.replace('_', "__")
58}
60}
59
61
62fn status_submenu(item: &Item) -> MenuItem<Item> {
63 let mut entries = Vec::new();
64 for kind in tray_status::STATUS_CHOICES {
65 let label = tray_status::choice_label(kind);
66 entries.push(
67 CheckmarkItem {
68 label: menu_label(label),
69 checked: item.forced == Some(kind),
70 activate: Box::new(move |item: &mut Item| {
71 item.send(TrayCommand::SetStatus(kind))
72 }),
73 ..Default::default()
74 }
75 .into(),
76 );
77 }
78 entries.push(MenuItem::Separator);
79 let duration_enabled = tray_status::duration_target(item.forced).is_some();
80 let mut duration_items = Vec::new();
81 for duration in tray_status::STATUS_DURATIONS {
82 duration_items.push(
83 StandardItem {
84 label: menu_label(tray_status::duration_label(duration)),
85 enabled: duration_enabled,
86 activate: Box::new(move |item: &mut Item| {
87 item.send(TrayCommand::SetStatusDuration(duration))
88 }),
89 ..Default::default()
90 }
91 .into(),
92 );
93 }
94 entries.push(
95 SubMenu {
96 label: menu_label(&item.labels.duration),
97 enabled: duration_enabled,
98 submenu: duration_items,
99 ..Default::default()
100 }
101 .into(),
102 );
103 entries.push(
104 StandardItem {
105 label: menu_label(&item.labels.reset),
106 activate: Box::new(|item: &mut Item| item.send(TrayCommand::ResetStatus)),
107 ..Default::default()
108 }
109 .into(),
110 );
111 SubMenu {
112 label: menu_label(&item.title),
113 submenu: entries,
114 ..Default::default()
115 }
116 .into()
117}
118
60impl ksni::Tray for Item {
119impl ksni::Tray for Item {
61 fn id(&self) -> String {
120 fn id(&self) -> String {
62 DESKTOP_ID.to_owned()
121 DESKTOP_ID.to_owned()
@@ -98,23 +157,10 @@ impl ksni::Tray for Item {
98 }
157 }
99 .into(),
158 .into(),
100 MenuItem::Separator,
159 MenuItem::Separator,
101 CheckmarkItem {
160 status_submenu(self),
102 label: menu_label(&self.labels.mute_sound),
103 checked: !self.sound_on,
104 activate: Box::new(|item: &mut Self| item.send(TrayCommand::ToggleSound)),
105 ..Default::default()
106 }
107 .into(),
108 CheckmarkItem {
109 label: menu_label(&self.labels.do_not_disturb),
110 checked: self.do_not_disturb,
111 activate: Box::new(|item: &mut Self| item.send(TrayCommand::ToggleDoNotDisturb)),
112 ..Default::default()
113 }
114 .into(),
115 StandardItem {
161 StandardItem {
116 label: menu_label(&self.labels.notifications),
162 label: menu_label(&self.labels.notifications),
117 activate: Box::new(|item: &mut Self| item.send(TrayCommand::Settings)),
163 activate: Box::new(|item: &mut Self| item.send(TrayCommand::Notifications)),
118 ..Default::default()
164 ..Default::default()
119 }
165 }
120 .into(),
166 .into(),
@@ -137,15 +183,15 @@ pub struct Tray {
137
183
138impl Tray {
184impl Tray {
139 /// `None` when there is no session bus or no tray host (no StatusNotifierWatcher).
185 /// `None` when there is no session bus or no tray host (no StatusNotifierWatcher).
140 pub fn new(sound_on: bool, do_not_disturb: bool, icon_png: &[u8]) -> Option<Self> {
186 pub fn new(presence: TrayPresence, icon_png: &[u8]) -> Option<Self> {
141 let (plain, dotted) = tray_icons(icon_png)?;
187 let (plain, dotted) = tray_icons(icon_png)?;
142 let (sender, receiver) = channel();
188 let (sender, receiver) = channel();
143 let item = Item {
189 let item = Item {
144 commands: sender,
190 commands: sender,
145 labels: Labels::current(),
191 labels: Labels::current(),
146 sound_on,
192 title: presence.title,
147 do_not_disturb,
193 forced: presence.forced,
148 mention: false,
194 mention: presence.mention,
149 plain,
195 plain,
150 dotted,
196 dotted,
151 };
197 };
@@ -185,13 +231,13 @@ impl Tray {
185 });
231 });
186 }
232 }
187
233
188 pub fn sync(&self, sound_on: bool, do_not_disturb: bool, mention: bool) {
234 pub fn sync(&self, presence: TrayPresence) {
189 let labels = Labels::current();
235 let labels = Labels::current();
190 self.handle.update(move |item| {
236 self.handle.update(move |item| {
191 item.labels = labels;
237 item.labels = labels;
192 item.sound_on = sound_on;
238 item.title = presence.title;
193 item.do_not_disturb = do_not_disturb;
239 item.forced = presence.forced;
194 item.mention = mention;
240 item.mention = presence.mention;
195 });
241 });
196 }
242 }
197}
243}
@@ -272,4 +318,37 @@ mod tests {
272 fn underscores_stay_visible_in_menu_labels() {
318 fn underscores_stay_visible_in_menu_labels() {
273 assert_eq!(menu_label("Do_not_disturb"), "Do__not__disturb");
319 assert_eq!(menu_label("Do_not_disturb"), "Do__not__disturb");
274 }
320 }
321
322 #[test]
323 fn status_submenu_lists_every_choice_and_reset() {
324 let (sender, _receiver) = channel();
325 let item = Item {
326 commands: sender,
327 labels: Labels::current(),
328 title: "Available".into(),
329 forced: Some(ForcedKind::Busy),
330 mention: false,
331 plain: Vec::new(),
332 dotted: Vec::new(),
333 };
334 let MenuItem::SubMenu(menu) = status_submenu(&item) else {
335 panic!("expected status submenu");
336 };
337 assert_eq!(menu.label, "Available");
338 let labels: Vec<_> = menu
339 .submenu
340 .iter()
341 .filter_map(|entry| match entry {
342 MenuItem::Checkmark(item) => Some(item.label.as_str()),
343 MenuItem::Standard(item) => Some(item.label.as_str()),
344 MenuItem::SubMenu(item) => Some(item.label.as_str()),
345 _ => None,
346 })
347 .collect();
348 for kind in tray_status::STATUS_CHOICES {
349 assert!(labels.contains(&tray_status::choice_label(kind)));
350 }
351 assert!(labels.contains(&tray_status::reset_label()));
352 assert!(labels.contains(&tray_status::duration_menu_label()));
353 }
275}
354}
crates/app-base/src/notify/platform/mod.rs +37 −3
@@ -54,12 +54,46 @@ pub struct ShareGeometry {
54 54 pub work: WorkArea,
55 55 }
56 56
57 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
58 pub enum TrayStatusDuration {
59 HalfHour,
60 OneHour,
61 TwoHours,
62 Today,
63 ThisWeek,
64 }
65
57 66 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
58 67 pub enum TrayCommand {
59 68 Toggle,
60 69 Open,
61 ToggleSound,
62 ToggleDoNotDisturb,
63 Settings,
70 /// Publish a forced status with no expiry (same as the profile menu).
71 SetStatus(chatsvc::ForcedKind),
72 /// Apply a duration to the currently forced status (ignored when none / Available).
73 SetStatusDuration(TrayStatusDuration),
74 ResetStatus,
75 Notifications,
64 76 Quit,
65 77 }
78
79 /// Snapshot the tray menu needs to show presence correctly.
80 #[derive(Debug, Clone, PartialEq, Eq)]
81 pub struct TrayPresence {
82 pub title: String,
83 pub forced: Option<chatsvc::ForcedKind>,
84 pub mention: bool,
85 }
86
87 impl TrayPresence {
88 pub fn new(
89 title: impl Into<String>,
90 forced: Option<chatsvc::ForcedKind>,
91 mention: bool,
92 ) -> Self {
93 Self {
94 title: title.into(),
95 forced,
96 mention,
97 }
98 }
99 }
@@ -54,12 +54,46 @@ pub struct ShareGeometry {
54 pub work: WorkArea,
54 pub work: WorkArea,
55}
55}
56
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub enum TrayStatusDuration {
59 HalfHour,
60 OneHour,
61 TwoHours,
62 Today,
63 ThisWeek,
64}
65
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub enum TrayCommand {
67pub enum TrayCommand {
59 Toggle,
68 Toggle,
60 Open,
69 Open,
61 ToggleSound,
70 /// Publish a forced status with no expiry (same as the profile menu).
62 ToggleDoNotDisturb,
71 SetStatus(chatsvc::ForcedKind),
63 Settings,
72 /// Apply a duration to the currently forced status (ignored when none / Available).
73 SetStatusDuration(TrayStatusDuration),
74 ResetStatus,
75 Notifications,
64 Quit,
76 Quit,
65}
77}
78
79/// Snapshot the tray menu needs to show presence correctly.
80#[derive(Debug, Clone, PartialEq, Eq)]
81pub struct TrayPresence {
82 pub title: String,
83 pub forced: Option<chatsvc::ForcedKind>,
84 pub mention: bool,
85}
86
87impl TrayPresence {
88 pub fn new(
89 title: impl Into<String>,
90 forced: Option<chatsvc::ForcedKind>,
91 mention: bool,
92 ) -> Self {
93 Self {
94 title: title.into(),
95 forced,
96 mention,
97 }
98 }
99}
crates/app-base/src/notify/platform/stub.rs +2 −2
@@ -110,7 +110,7 @@ pub struct Tray;
110 110
111 111 #[cfg(not(target_os = "linux"))]
112 112 impl Tray {
113 pub fn new(_sound_on: bool, _do_not_disturb: bool, _icon_png: &[u8]) -> Option<Self> {
113 pub fn new(_presence: super::TrayPresence, _icon_png: &[u8]) -> Option<Self> {
114 114 None
115 115 }
116 116
@@ -120,7 +120,7 @@ impl Tray {
120 120 Vec::new()
121 121 }
122 122
123 pub fn sync(&self, _sound_on: bool, _do_not_disturb: bool, _mention: bool) {}
123 pub fn sync(&self, _presence: super::TrayPresence) {}
124 124
125 125 pub fn relocalize(&self) {}
126 126 }
@@ -110,7 +110,7 @@ pub struct Tray;
110
110
111#[cfg(not(target_os = "linux"))]
111#[cfg(not(target_os = "linux"))]
112impl Tray {
112impl Tray {
113 pub fn new(_sound_on: bool, _do_not_disturb: bool, _icon_png: &[u8]) -> Option<Self> {
113 pub fn new(_presence: super::TrayPresence, _icon_png: &[u8]) -> Option<Self> {
114 None
114 None
115 }
115 }
116
116
@@ -120,7 +120,7 @@ impl Tray {
120 Vec::new()
120 Vec::new()
121 }
121 }
122
122
123 pub fn sync(&self, _sound_on: bool, _do_not_disturb: bool, _mention: bool) {}
123 pub fn sync(&self, _presence: super::TrayPresence) {}
124
124
125 pub fn relocalize(&self) {}
125 pub fn relocalize(&self) {}
126}
126}
crates/app-base/src/notify/platform/windows_impl.rs +117 −45
@@ -7,7 +7,7 @@ use std::time::Duration;
7 7 use calling::ShareKind;
8 8 use gpui_kit::Window;
9 9 use raw_window_handle::{HasWindowHandle, RawWindowHandle};
10 use tray_icon::menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem};
10 use tray_icon::menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem, Submenu};
11 11 use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};
12 12 use windows::Win32::Foundation::{COLORREF, HWND, LPARAM, POINT, RECT, WPARAM};
13 13 use windows::Win32::Graphics::Dwm::{
@@ -43,8 +43,9 @@ use windows::Win32::UI::WindowsAndMessaging::{
43 43 use windows::core::{BOOL, PCWSTR, w};
44 44
45 45 use super::stack_plan::{StackPlan, stack_plan};
46 use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};
46 use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, TrayPresence, WorkArea};
47 47 use crate::notify::badge::{Badge, render_badge};
48 use crate::notify::tray_status;
48 49
49 50 const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");
50 51 const TRAY_ICON_SIZE: u32 = 32;
@@ -652,17 +653,19 @@ pub fn play_sound() {
652 653 }
653 654
654 655 const ID_OPEN: &str = "open";
655 const ID_SOUND: &str = "sound";
656 const ID_DO_NOT_DISTURB: &str = "do_not_disturb";
657 const ID_SETTINGS: &str = "settings";
656 const ID_NOTIFICATIONS: &str = "notifications";
658 657 const ID_QUIT: &str = "quit";
658 const ID_RESET_STATUS: &str = "status:reset";
659 659
660 660 pub struct Tray {
661 661 icon: TrayIcon,
662 662 open: MenuItem,
663 sound: CheckMenuItem,
664 do_not_disturb: CheckMenuItem,
665 settings: MenuItem,
663 status: Submenu,
664 status_items: Vec<CheckMenuItem>,
665 duration_items: Vec<MenuItem>,
666 duration_menu: Submenu,
667 reset: MenuItem,
668 notifications: MenuItem,
666 669 quit: MenuItem,
667 670 plain: Icon,
668 671 with_dot: Icon,
@@ -673,25 +676,55 @@ fn tray_menu_label(key: &str) -> String {
673 676 }
674 677
675 678 impl Tray {
676 pub fn new(sound_on: bool, do_not_disturb: bool, icon_png: &[u8]) -> Option<Self> {
679 pub fn new(presence: TrayPresence, icon_png: &[u8]) -> Option<Self> {
677 680 let (plain, with_dot) = tray_icons(icon_png)?;
678 681 let open = MenuItem::with_id(ID_OPEN, tray_menu_label("tray.open"), true, None);
679 let sound = CheckMenuItem::with_id(
680 ID_SOUND,
681 tray_menu_label("tray.mute_sound"),
682 true,
683 !sound_on,
684 None,
685 );
686 let dnd = CheckMenuItem::with_id(
687 ID_DO_NOT_DISTURB,
688 tray_menu_label("tray.do_not_disturb"),
689 true,
690 do_not_disturb,
691 None,
692 );
693 let settings = MenuItem::with_id(
694 ID_SETTINGS,
682 let status_items: Vec<CheckMenuItem> = tray_status::STATUS_CHOICES
683 .into_iter()
684 .map(|kind| {
685 CheckMenuItem::with_id(
686 tray_status::kind_id(kind),
687 tray_status::choice_label(kind),
688 true,
689 presence.forced == Some(kind),
690 None,
691 )
692 })
693 .collect();
694 let duration_enabled = tray_status::duration_target(presence.forced).is_some();
695 let duration_items: Vec<MenuItem> = tray_status::STATUS_DURATIONS
696 .into_iter()
697 .map(|duration| {
698 MenuItem::with_id(
699 tray_status::duration_id(duration),
700 tray_status::duration_label(duration),
701 duration_enabled,
702 None,
703 )
704 })
705 .collect();
706 let duration_refs: Vec<&dyn tray_icon::menu::IsMenuItem> = duration_items
707 .iter()
708 .map(|item| item as &dyn tray_icon::menu::IsMenuItem)
709 .collect();
710 let duration_menu = Submenu::with_items(
711 tray_status::duration_menu_label(),
712 duration_enabled,
713 &duration_refs,
714 )
715 .ok()?;
716 let reset = MenuItem::with_id(ID_RESET_STATUS, tray_status::reset_label(), true, None);
717 let mut status_entry_refs: Vec<&dyn tray_icon::menu::IsMenuItem> = status_items
718 .iter()
719 .map(|item| item as &dyn tray_icon::menu::IsMenuItem)
720 .collect();
721 let separator = PredefinedMenuItem::separator();
722 status_entry_refs.push(&separator);
723 status_entry_refs.push(&duration_menu);
724 status_entry_refs.push(&reset);
725 let status = Submenu::with_items(&presence.title, true, &status_entry_refs).ok()?;
726 let notifications = MenuItem::with_id(
727 ID_NOTIFICATIONS,
695 728 tray_menu_label("tray.notifications"),
696 729 true,
697 730 None,
@@ -701,9 +734,8 @@ impl Tray {
701 734 menu.append_items(&[
702 735 &open,
703 736 &PredefinedMenuItem::separator(),
704 &sound,
705 &dnd,
706 &settings,
737 &status,
738 &notifications,
707 739 &PredefinedMenuItem::separator(),
708 740 &quit,
709 741 ])
@@ -718,9 +750,12 @@ impl Tray {
718 750 Some(Tray {
719 751 icon,
720 752 open,
721 sound,
722 do_not_disturb: dnd,
723 settings,
753 status,
754 status_items,
755 duration_items,
756 duration_menu,
757 reset,
758 notifications,
724 759 quit,
725 760 plain,
726 761 with_dot,
@@ -729,26 +764,48 @@ impl Tray {
729 764
730 765 pub fn relocalize(&self) {
731 766 let _ = self.open.set_text(tray_menu_label("tray.open"));
732 let _ = self.sound.set_text(tray_menu_label("tray.mute_sound"));
733 let _ = self
734 .do_not_disturb
735 .set_text(tray_menu_label("tray.do_not_disturb"));
736 767 let _ = self
737 .settings
768 .notifications
738 769 .set_text(tray_menu_label("tray.notifications"));
739 770 let _ = self.quit.set_text(tray_menu_label("tray.quit"));
771 let _ = self.reset.set_text(tray_status::reset_label());
772 let _ = self
773 .duration_menu
774 .set_text(tray_status::duration_menu_label());
775 for (item, kind) in self
776 .status_items
777 .iter()
778 .zip(tray_status::STATUS_CHOICES.into_iter())
779 {
780 let _ = item.set_text(tray_status::choice_label(kind));
781 }
782 for (item, duration) in self
783 .duration_items
784 .iter()
785 .zip(tray_status::STATUS_DURATIONS.into_iter())
786 {
787 let _ = item.set_text(tray_status::duration_label(duration));
788 }
740 789 }
741 790
742 791 pub fn poll(&self) -> Vec<TrayCommand> {
743 792 let mut commands = Vec::new();
744 793 while let Ok(event) = MenuEvent::receiver().try_recv() {
745 let command = match event.id.0.as_str() {
794 let id = event.id.0.as_str();
795 let command = match id {
746 796 ID_OPEN => TrayCommand::Open,
747 ID_SOUND => TrayCommand::ToggleSound,
748 ID_DO_NOT_DISTURB => TrayCommand::ToggleDoNotDisturb,
749 ID_SETTINGS => TrayCommand::Settings,
797 ID_NOTIFICATIONS => TrayCommand::Notifications,
750 798 ID_QUIT => TrayCommand::Quit,
751 _ => continue,
799 ID_RESET_STATUS => TrayCommand::ResetStatus,
800 other => {
801 if let Some(kind) = tray_status::parse_kind_id(other) {
802 TrayCommand::SetStatus(kind)
803 } else if let Some(duration) = tray_status::parse_duration_id(other) {
804 TrayCommand::SetStatusDuration(duration)
805 } else {
806 continue;
807 }
808 }
752 809 };
753 810 commands.push(command);
754 811 }
@@ -775,11 +832,26 @@ impl Tray {
775 832 let _ = self.icon.set_icon(Some(icon.clone()));
776 833 }
777 834
778 pub fn sync(&self, sound_on: bool, do_not_disturb: bool, mention: bool) {
835 pub fn sync(&self, presence: TrayPresence) {
779 836 self.relocalize();
780 self.sound.set_checked(!sound_on);
781 self.do_not_disturb.set_checked(do_not_disturb);
782 let icon = if mention { &self.with_dot } else { &self.plain };
837 let _ = self.status.set_text(&presence.title);
838 for (item, kind) in self
839 .status_items
840 .iter()
841 .zip(tray_status::STATUS_CHOICES.into_iter())
842 {
843 item.set_checked(presence.forced == Some(kind));
844 }
845 let duration_enabled = tray_status::duration_target(presence.forced).is_some();
846 let _ = self.duration_menu.set_enabled(duration_enabled);
847 for item in &self.duration_items {
848 let _ = item.set_enabled(duration_enabled);
849 }
850 let icon = if presence.mention {
851 &self.with_dot
852 } else {
853 &self.plain
854 };
783 855 let _ = self.icon.set_icon(Some(icon.clone()));
784 856 }
785 857 }
@@ -7,7 +7,7 @@ use std::time::Duration;
7use calling::ShareKind;
7use calling::ShareKind;
8use gpui_kit::Window;
8use gpui_kit::Window;
9use raw_window_handle::{HasWindowHandle, RawWindowHandle};
9use raw_window_handle::{HasWindowHandle, RawWindowHandle};
10use tray_icon::menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem};
10use tray_icon::menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem, Submenu};
11use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};
11use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};
12use windows::Win32::Foundation::{COLORREF, HWND, LPARAM, POINT, RECT, WPARAM};
12use windows::Win32::Foundation::{COLORREF, HWND, LPARAM, POINT, RECT, WPARAM};
13use windows::Win32::Graphics::Dwm::{
13use windows::Win32::Graphics::Dwm::{
@@ -43,8 +43,9 @@ use windows::Win32::UI::WindowsAndMessaging::{
43use windows::core::{BOOL, PCWSTR, w};
43use windows::core::{BOOL, PCWSTR, w};
44
44
45use super::stack_plan::{StackPlan, stack_plan};
45use super::stack_plan::{StackPlan, stack_plan};
46use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};
46use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, TrayPresence, WorkArea};
47use crate::notify::badge::{Badge, render_badge};
47use crate::notify::badge::{Badge, render_badge};
48use crate::notify::tray_status;
48
49
49const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");
50const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");
50const TRAY_ICON_SIZE: u32 = 32;
51const TRAY_ICON_SIZE: u32 = 32;
@@ -652,17 +653,19 @@ pub fn play_sound() {
652}
653}
653
654
654const ID_OPEN: &str = "open";
655const ID_OPEN: &str = "open";
655const ID_SOUND: &str = "sound";
656const ID_NOTIFICATIONS: &str = "notifications";
656const ID_DO_NOT_DISTURB: &str = "do_not_disturb";
657const ID_SETTINGS: &str = "settings";
658const ID_QUIT: &str = "quit";
657const ID_QUIT: &str = "quit";
658const ID_RESET_STATUS: &str = "status:reset";
659
659
660pub struct Tray {
660pub struct Tray {
661 icon: TrayIcon,
661 icon: TrayIcon,
662 open: MenuItem,
662 open: MenuItem,
663 sound: CheckMenuItem,
663 status: Submenu,
664 do_not_disturb: CheckMenuItem,
664 status_items: Vec<CheckMenuItem>,
665 settings: MenuItem,
665 duration_items: Vec<MenuItem>,
666 duration_menu: Submenu,
667 reset: MenuItem,
668 notifications: MenuItem,
666 quit: MenuItem,
669 quit: MenuItem,
667 plain: Icon,
670 plain: Icon,
668 with_dot: Icon,
671 with_dot: Icon,
@@ -673,25 +676,55 @@ fn tray_menu_label(key: &str) -> String {
673}
676}
674
677
675impl Tray {
678impl Tray {
676 pub fn new(sound_on: bool, do_not_disturb: bool, icon_png: &[u8]) -> Option<Self> {
679 pub fn new(presence: TrayPresence, icon_png: &[u8]) -> Option<Self> {
677 let (plain, with_dot) = tray_icons(icon_png)?;
680 let (plain, with_dot) = tray_icons(icon_png)?;
678 let open = MenuItem::with_id(ID_OPEN, tray_menu_label("tray.open"), true, None);
681 let open = MenuItem::with_id(ID_OPEN, tray_menu_label("tray.open"), true, None);
679 let sound = CheckMenuItem::with_id(
682 let status_items: Vec<CheckMenuItem> = tray_status::STATUS_CHOICES
680 ID_SOUND,
683 .into_iter()
681 tray_menu_label("tray.mute_sound"),
684 .map(|kind| {
682 true,
685 CheckMenuItem::with_id(
683 !sound_on,
686 tray_status::kind_id(kind),
684 None,
687 tray_status::choice_label(kind),
685 );
688 true,
686 let dnd = CheckMenuItem::with_id(
689 presence.forced == Some(kind),
687 ID_DO_NOT_DISTURB,
690 None,
688 tray_menu_label("tray.do_not_disturb"),
691 )
689 true,
692 })
690 do_not_disturb,
693 .collect();
691 None,
694 let duration_enabled = tray_status::duration_target(presence.forced).is_some();
692 );
695 let duration_items: Vec<MenuItem> = tray_status::STATUS_DURATIONS
693 let settings = MenuItem::with_id(
696 .into_iter()
694 ID_SETTINGS,
697 .map(|duration| {
698 MenuItem::with_id(
699 tray_status::duration_id(duration),
700 tray_status::duration_label(duration),
701 duration_enabled,
702 None,
703 )
704 })
705 .collect();
706 let duration_refs: Vec<&dyn tray_icon::menu::IsMenuItem> = duration_items
707 .iter()
708 .map(|item| item as &dyn tray_icon::menu::IsMenuItem)
709 .collect();
710 let duration_menu = Submenu::with_items(
711 tray_status::duration_menu_label(),
712 duration_enabled,
713 &duration_refs,
714 )
715 .ok()?;
716 let reset = MenuItem::with_id(ID_RESET_STATUS, tray_status::reset_label(), true, None);
717 let mut status_entry_refs: Vec<&dyn tray_icon::menu::IsMenuItem> = status_items
718 .iter()
719 .map(|item| item as &dyn tray_icon::menu::IsMenuItem)
720 .collect();
721 let separator = PredefinedMenuItem::separator();
722 status_entry_refs.push(&separator);
723 status_entry_refs.push(&duration_menu);
724 status_entry_refs.push(&reset);
725 let status = Submenu::with_items(&presence.title, true, &status_entry_refs).ok()?;
726 let notifications = MenuItem::with_id(
727 ID_NOTIFICATIONS,
695 tray_menu_label("tray.notifications"),
728 tray_menu_label("tray.notifications"),
696 true,
729 true,
697 None,
730 None,
@@ -701,9 +734,8 @@ impl Tray {
701 menu.append_items(&[
734 menu.append_items(&[
702 &open,
735 &open,
703 &PredefinedMenuItem::separator(),
736 &PredefinedMenuItem::separator(),
704 &sound,
737 &status,
705 &dnd,
738 &notifications,
706 &settings,
707 &PredefinedMenuItem::separator(),
739 &PredefinedMenuItem::separator(),
708 &quit,
740 &quit,
709 ])
741 ])
@@ -718,9 +750,12 @@ impl Tray {
718 Some(Tray {
750 Some(Tray {
719 icon,
751 icon,
720 open,
752 open,
721 sound,
753 status,
722 do_not_disturb: dnd,
754 status_items,
723 settings,
755 duration_items,
756 duration_menu,
757 reset,
758 notifications,
724 quit,
759 quit,
725 plain,
760 plain,
726 with_dot,
761 with_dot,
@@ -729,26 +764,48 @@ impl Tray {
729
764
730 pub fn relocalize(&self) {
765 pub fn relocalize(&self) {
731 let _ = self.open.set_text(tray_menu_label("tray.open"));
766 let _ = self.open.set_text(tray_menu_label("tray.open"));
732 let _ = self.sound.set_text(tray_menu_label("tray.mute_sound"));
733 let _ = self
734 .do_not_disturb
735 .set_text(tray_menu_label("tray.do_not_disturb"));
736 let _ = self
767 let _ = self
737 .settings
768 .notifications
738 .set_text(tray_menu_label("tray.notifications"));
769 .set_text(tray_menu_label("tray.notifications"));
739 let _ = self.quit.set_text(tray_menu_label("tray.quit"));
770 let _ = self.quit.set_text(tray_menu_label("tray.quit"));
771 let _ = self.reset.set_text(tray_status::reset_label());
772 let _ = self
773 .duration_menu
774 .set_text(tray_status::duration_menu_label());
775 for (item, kind) in self
776 .status_items
777 .iter()
778 .zip(tray_status::STATUS_CHOICES.into_iter())
779 {
780 let _ = item.set_text(tray_status::choice_label(kind));
781 }
782 for (item, duration) in self
783 .duration_items
784 .iter()
785 .zip(tray_status::STATUS_DURATIONS.into_iter())
786 {
787 let _ = item.set_text(tray_status::duration_label(duration));
788 }
740 }
789 }
741
790
742 pub fn poll(&self) -> Vec<TrayCommand> {
791 pub fn poll(&self) -> Vec<TrayCommand> {
743 let mut commands = Vec::new();
792 let mut commands = Vec::new();
744 while let Ok(event) = MenuEvent::receiver().try_recv() {
793 while let Ok(event) = MenuEvent::receiver().try_recv() {
745 let command = match event.id.0.as_str() {
794 let id = event.id.0.as_str();
795 let command = match id {
746 ID_OPEN => TrayCommand::Open,
796 ID_OPEN => TrayCommand::Open,
747 ID_SOUND => TrayCommand::ToggleSound,
797 ID_NOTIFICATIONS => TrayCommand::Notifications,
748 ID_DO_NOT_DISTURB => TrayCommand::ToggleDoNotDisturb,
749 ID_SETTINGS => TrayCommand::Settings,
750 ID_QUIT => TrayCommand::Quit,
798 ID_QUIT => TrayCommand::Quit,
751 _ => continue,
799 ID_RESET_STATUS => TrayCommand::ResetStatus,
800 other => {
801 if let Some(kind) = tray_status::parse_kind_id(other) {
802 TrayCommand::SetStatus(kind)
803 } else if let Some(duration) = tray_status::parse_duration_id(other) {
804 TrayCommand::SetStatusDuration(duration)
805 } else {
806 continue;
807 }
808 }
752 };
809 };
753 commands.push(command);
810 commands.push(command);
754 }
811 }
@@ -775,11 +832,26 @@ impl Tray {
775 let _ = self.icon.set_icon(Some(icon.clone()));
832 let _ = self.icon.set_icon(Some(icon.clone()));
776 }
833 }
777
834
778 pub fn sync(&self, sound_on: bool, do_not_disturb: bool, mention: bool) {
835 pub fn sync(&self, presence: TrayPresence) {
779 self.relocalize();
836 self.relocalize();
780 self.sound.set_checked(!sound_on);
837 let _ = self.status.set_text(&presence.title);
781 self.do_not_disturb.set_checked(do_not_disturb);
838 for (item, kind) in self
782 let icon = if mention { &self.with_dot } else { &self.plain };
839 .status_items
840 .iter()
841 .zip(tray_status::STATUS_CHOICES.into_iter())
842 {
843 item.set_checked(presence.forced == Some(kind));
844 }
845 let duration_enabled = tray_status::duration_target(presence.forced).is_some();
846 let _ = self.duration_menu.set_enabled(duration_enabled);
847 for item in &self.duration_items {
848 let _ = item.set_enabled(duration_enabled);
849 }
850 let icon = if presence.mention {
851 &self.with_dot
852 } else {
853 &self.plain
854 };
783 let _ = self.icon.set_icon(Some(icon.clone()));
855 let _ = self.icon.set_icon(Some(icon.clone()));
784 }
856 }
785}
857}
crates/app-base/src/notify/tray_status.rs added +136 −0
@@ -0,0 +1,136 @@
1 //! Shared status labels for the tray menu. Keep in sync with
2 //! `app-state::own_status::{choice_label, state_label, STATUS_CHOICES, STATUS_DURATIONS}`.
3
4 use chatsvc::ForcedKind;
5
6 use super::platform::TrayStatusDuration;
7
8 pub const STATUS_CHOICES: [ForcedKind; 6] = [
9 ForcedKind::Available,
10 ForcedKind::Busy,
11 ForcedKind::DoNotDisturb,
12 ForcedKind::BeRightBack,
13 ForcedKind::Away,
14 ForcedKind::Offline,
15 ];
16
17 pub const STATUS_DURATIONS: [TrayStatusDuration; 5] = [
18 TrayStatusDuration::HalfHour,
19 TrayStatusDuration::OneHour,
20 TrayStatusDuration::TwoHours,
21 TrayStatusDuration::Today,
22 TrayStatusDuration::ThisWeek,
23 ];
24
25 pub fn choice_label(kind: ForcedKind) -> &'static str {
26 match kind {
27 ForcedKind::Away => "Appear away",
28 ForcedKind::Offline => "Appear offline",
29 other => state_label(other),
30 }
31 }
32
33 pub fn state_label(kind: ForcedKind) -> &'static str {
34 match kind {
35 ForcedKind::Available => "Available",
36 ForcedKind::Busy => "Busy",
37 ForcedKind::DoNotDisturb => "Do not disturb",
38 ForcedKind::BeRightBack => "Be right back",
39 ForcedKind::Away => "Away",
40 ForcedKind::Offline => "Offline",
41 }
42 }
43
44 pub fn duration_label(duration: TrayStatusDuration) -> &'static str {
45 match duration {
46 TrayStatusDuration::HalfHour => "30 minutes",
47 TrayStatusDuration::OneHour => "1 hour",
48 TrayStatusDuration::TwoHours => "2 hours",
49 TrayStatusDuration::Today => "Today",
50 TrayStatusDuration::ThisWeek => "This week",
51 }
52 }
53
54 pub fn duration_target(forced: Option<ForcedKind>) -> Option<ForcedKind> {
55 forced.filter(|kind| *kind != ForcedKind::Available)
56 }
57
58 pub fn reset_label() -> &'static str {
59 "Reset status"
60 }
61
62 pub fn duration_menu_label() -> &'static str {
63 "Duration"
64 }
65
66 pub fn kind_id(kind: ForcedKind) -> &'static str {
67 match kind {
68 ForcedKind::Available => "status:available",
69 ForcedKind::Busy => "status:busy",
70 ForcedKind::DoNotDisturb => "status:dnd",
71 ForcedKind::BeRightBack => "status:brb",
72 ForcedKind::Away => "status:away",
73 ForcedKind::Offline => "status:offline",
74 }
75 }
76
77 pub fn parse_kind_id(id: &str) -> Option<ForcedKind> {
78 match id {
79 "status:available" => Some(ForcedKind::Available),
80 "status:busy" => Some(ForcedKind::Busy),
81 "status:dnd" => Some(ForcedKind::DoNotDisturb),
82 "status:brb" => Some(ForcedKind::BeRightBack),
83 "status:away" => Some(ForcedKind::Away),
84 "status:offline" => Some(ForcedKind::Offline),
85 _ => None,
86 }
87 }
88
89 pub fn duration_id(duration: TrayStatusDuration) -> &'static str {
90 match duration {
91 TrayStatusDuration::HalfHour => "status-duration:30m",
92 TrayStatusDuration::OneHour => "status-duration:1h",
93 TrayStatusDuration::TwoHours => "status-duration:2h",
94 TrayStatusDuration::Today => "status-duration:today",
95 TrayStatusDuration::ThisWeek => "status-duration:week",
96 }
97 }
98
99 pub fn parse_duration_id(id: &str) -> Option<TrayStatusDuration> {
100 match id {
101 "status-duration:30m" => Some(TrayStatusDuration::HalfHour),
102 "status-duration:1h" => Some(TrayStatusDuration::OneHour),
103 "status-duration:2h" => Some(TrayStatusDuration::TwoHours),
104 "status-duration:today" => Some(TrayStatusDuration::Today),
105 "status-duration:week" => Some(TrayStatusDuration::ThisWeek),
106 _ => None,
107 }
108 }
109
110 #[cfg(test)]
111 mod tests {
112 use super::*;
113
114 #[test]
115 fn every_choice_has_a_stable_id() {
116 for kind in STATUS_CHOICES {
117 assert_eq!(parse_kind_id(kind_id(kind)), Some(kind));
118 }
119 }
120
121 #[test]
122 fn every_duration_has_a_stable_id() {
123 for duration in STATUS_DURATIONS {
124 assert_eq!(parse_duration_id(duration_id(duration)), Some(duration));
125 }
126 }
127
128 #[test]
129 fn available_has_no_duration_target() {
130 assert_eq!(duration_target(Some(ForcedKind::Available)), None);
131 assert_eq!(
132 duration_target(Some(ForcedKind::DoNotDisturb)),
133 Some(ForcedKind::DoNotDisturb)
134 );
135 }
136 }
@@ -0,0 +1,136 @@
1//! Shared status labels for the tray menu. Keep in sync with
2//! `app-state::own_status::{choice_label, state_label, STATUS_CHOICES, STATUS_DURATIONS}`.
3
4use chatsvc::ForcedKind;
5
6use super::platform::TrayStatusDuration;
7
8pub const STATUS_CHOICES: [ForcedKind; 6] = [
9 ForcedKind::Available,
10 ForcedKind::Busy,
11 ForcedKind::DoNotDisturb,
12 ForcedKind::BeRightBack,
13 ForcedKind::Away,
14 ForcedKind::Offline,
15];
16
17pub const STATUS_DURATIONS: [TrayStatusDuration; 5] = [
18 TrayStatusDuration::HalfHour,
19 TrayStatusDuration::OneHour,
20 TrayStatusDuration::TwoHours,
21 TrayStatusDuration::Today,
22 TrayStatusDuration::ThisWeek,
23];
24
25pub fn choice_label(kind: ForcedKind) -> &'static str {
26 match kind {
27 ForcedKind::Away => "Appear away",
28 ForcedKind::Offline => "Appear offline",
29 other => state_label(other),
30 }
31}
32
33pub fn state_label(kind: ForcedKind) -> &'static str {
34 match kind {
35 ForcedKind::Available => "Available",
36 ForcedKind::Busy => "Busy",
37 ForcedKind::DoNotDisturb => "Do not disturb",
38 ForcedKind::BeRightBack => "Be right back",
39 ForcedKind::Away => "Away",
40 ForcedKind::Offline => "Offline",
41 }
42}
43
44pub fn duration_label(duration: TrayStatusDuration) -> &'static str {
45 match duration {
46 TrayStatusDuration::HalfHour => "30 minutes",
47 TrayStatusDuration::OneHour => "1 hour",
48 TrayStatusDuration::TwoHours => "2 hours",
49 TrayStatusDuration::Today => "Today",
50 TrayStatusDuration::ThisWeek => "This week",
51 }
52}
53
54pub fn duration_target(forced: Option<ForcedKind>) -> Option<ForcedKind> {
55 forced.filter(|kind| *kind != ForcedKind::Available)
56}
57
58pub fn reset_label() -> &'static str {
59 "Reset status"
60}
61
62pub fn duration_menu_label() -> &'static str {
63 "Duration"
64}
65
66pub fn kind_id(kind: ForcedKind) -> &'static str {
67 match kind {
68 ForcedKind::Available => "status:available",
69 ForcedKind::Busy => "status:busy",
70 ForcedKind::DoNotDisturb => "status:dnd",
71 ForcedKind::BeRightBack => "status:brb",
72 ForcedKind::Away => "status:away",
73 ForcedKind::Offline => "status:offline",
74 }
75}
76
77pub fn parse_kind_id(id: &str) -> Option<ForcedKind> {
78 match id {
79 "status:available" => Some(ForcedKind::Available),
80 "status:busy" => Some(ForcedKind::Busy),
81 "status:dnd" => Some(ForcedKind::DoNotDisturb),
82 "status:brb" => Some(ForcedKind::BeRightBack),
83 "status:away" => Some(ForcedKind::Away),
84 "status:offline" => Some(ForcedKind::Offline),
85 _ => None,
86 }
87}
88
89pub fn duration_id(duration: TrayStatusDuration) -> &'static str {
90 match duration {
91 TrayStatusDuration::HalfHour => "status-duration:30m",
92 TrayStatusDuration::OneHour => "status-duration:1h",
93 TrayStatusDuration::TwoHours => "status-duration:2h",
94 TrayStatusDuration::Today => "status-duration:today",
95 TrayStatusDuration::ThisWeek => "status-duration:week",
96 }
97}
98
99pub fn parse_duration_id(id: &str) -> Option<TrayStatusDuration> {
100 match id {
101 "status-duration:30m" => Some(TrayStatusDuration::HalfHour),
102 "status-duration:1h" => Some(TrayStatusDuration::OneHour),
103 "status-duration:2h" => Some(TrayStatusDuration::TwoHours),
104 "status-duration:today" => Some(TrayStatusDuration::Today),
105 "status-duration:week" => Some(TrayStatusDuration::ThisWeek),
106 _ => None,
107 }
108}
109
110#[cfg(test)]
111mod tests {
112 use super::*;
113
114 #[test]
115 fn every_choice_has_a_stable_id() {
116 for kind in STATUS_CHOICES {
117 assert_eq!(parse_kind_id(kind_id(kind)), Some(kind));
118 }
119 }
120
121 #[test]
122 fn every_duration_has_a_stable_id() {
123 for duration in STATUS_DURATIONS {
124 assert_eq!(parse_duration_id(duration_id(duration)), Some(duration));
125 }
126 }
127
128 #[test]
129 fn available_has_no_duration_target() {
130 assert_eq!(duration_target(Some(ForcedKind::Available)), None);
131 assert_eq!(
132 duration_target(Some(ForcedKind::DoNotDisturb)),
133 Some(ForcedKind::DoNotDisturb)
134 );
135 }
136}
crates/app-base/src/ui_locale.rs +1 −2
@@ -243,9 +243,8 @@ mod tests {
243 243 apply_locale("en");
244 244 assert_eq!(tr("tray.open"), "Open");
245 245 assert_eq!(tr("tray.quit"), "Quit");
246 assert_eq!(tr("tray.mute_sound"), "Mute sound");
246 assert_eq!(tr("tray.notifications"), "Notifications");
247 247 apply_locale("de");
248 assert_eq!(tr("tray.do_not_disturb"), "Nicht stören");
249 248 assert_eq!(tr("tray.notifications"), "Benachrichtigungen");
250 249 }
251 250
@@ -243,9 +243,8 @@ mod tests {
243 apply_locale("en");
243 apply_locale("en");
244 assert_eq!(tr("tray.open"), "Open");
244 assert_eq!(tr("tray.open"), "Open");
245 assert_eq!(tr("tray.quit"), "Quit");
245 assert_eq!(tr("tray.quit"), "Quit");
246 assert_eq!(tr("tray.mute_sound"), "Mute sound");
246 assert_eq!(tr("tray.notifications"), "Notifications");
247 apply_locale("de");
247 apply_locale("de");
248 assert_eq!(tr("tray.do_not_disturb"), "Nicht stören");
249 assert_eq!(tr("tray.notifications"), "Benachrichtigungen");
248 assert_eq!(tr("tray.notifications"), "Benachrichtigungen");
250 }
249 }
251
250
crates/app/src/notify/center.rs +67 −37
@@ -2,7 +2,7 @@ use std::cell::Cell;
2 2 use std::collections::{HashMap, HashSet};
3 3 use std::time::{Duration, Instant};
4 4
5 use chrono::{DateTime, Utc};
5 use chrono::{DateTime, Local, Utc};
6 6 use gpui_kit::*;
7 7 use store::Sidebar;
8 8 use teams_core::{ForcedAvailability, ForcedKind};
@@ -11,7 +11,9 @@ use super::badge::{Badge, badge_for};
11 11 use super::incoming::IncomingTracker;
12 12 use super::layout::{self, MEETING_HEIGHT, Slot, ring_height};
13 13 use super::meeting_view::MeetingToastView;
14 use super::platform::{self, NativeHandle, Tray, TrayCommand, WorkArea};
14 use super::platform::{
15 self, NativeHandle, Tray, TrayCommand, TrayPresence, TrayStatusDuration, WorkArea,
16 };
15 17 use super::ring_view::RingView;
16 18 use super::rules::{
17 19 ChatKind, Decision, Environment, Incoming, Preview, Settings, SoundThrottle, decide,
@@ -39,6 +41,7 @@ use crate::appearance::AppIcon;
39 41 use crate::autostart::{self, StartupSettings};
40 42 use crate::call::DemoScene;
41 43 use crate::data::{self, Directory, PresenceKind};
44 use crate::own_status::{self, StatusDuration};
42 45 use crate::runtime;
43 46 use crate::settings_section::SettingsSection;
44 47 use crate::single_instance;
@@ -106,7 +109,6 @@ pub struct NotificationCenter {
106 109 hover_hold: bool,
107 110 unread_mentions: HashSet<String>,
108 111 tray: Option<Tray>,
109 tray_do_not_disturb: bool,
110 112 app_icon: AppIcon,
111 113 shown_badge: Option<Badge>,
112 114 shown_mention_dot: bool,
@@ -131,15 +133,10 @@ impl NotificationCenter {
131 133 let mut settings = settings::load(&app.read(cx).store);
132 134 settings.account = app.read(cx).account_chat_settings().notifications;
133 135 let app_icon = active_appearance::current(cx).app_icon;
134 let tray_do_not_disturb = own_do_not_disturb(app.read(cx));
135 136 let tray = if app.read(cx).mode.demo {
136 137 None
137 138 } else {
138 Tray::new(
139 settings.sounds.notification_sound,
140 tray_do_not_disturb,
141 app_icon.png(),
142 )
139 Tray::new(tray_presence_from(&app.read(cx), false), app_icon.png())
143 140 };
144 141 platform::set_window_icon(window, app_icon.png());
145 142 let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {
@@ -189,7 +186,6 @@ impl NotificationCenter {
189 186 hover_hold: false,
190 187 unread_mentions: HashSet::new(),
191 188 tray,
192 tray_do_not_disturb,
193 189 app_icon,
194 190 shown_badge: None,
195 191 shown_mention_dot: false,
@@ -424,7 +420,7 @@ impl NotificationCenter {
424 420 AppEvent::Messages(conversation_id) => self.on_messages(conversation_id, cx),
425 421 AppEvent::Selection => self.on_selection(cx),
426 422 AppEvent::Sidebar => self.refresh_badge(cx),
427 AppEvent::Directory => self.sync_tray_presence(cx),
423 AppEvent::Directory | AppEvent::Status => self.sync_tray(cx),
428 424 AppEvent::Ring => self.on_rings_changed(cx),
429 425 AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
430 426 AppEvent::MeetingChime => self.on_meeting_chime(cx),
@@ -1176,11 +1172,40 @@ impl NotificationCenter {
1176 1172 match command {
1177 1173 TrayCommand::Toggle => self.toggle_main_window(cx),
1178 1174 TrayCommand::Open => self.raise_main_window(cx),
1179 TrayCommand::ToggleSound => self.update_settings(cx, |settings| {
1180 settings.sounds.notification_sound = !settings.sounds.notification_sound
1181 }),
1182 TrayCommand::ToggleDoNotDisturb => self.toggle_own_do_not_disturb(cx),
1183 TrayCommand::Settings => {
1175 TrayCommand::SetStatus(kind) => {
1176 let forced = ForcedAvailability {
1177 kind,
1178 expires_at: None,
1179 };
1180 self.app
1181 .update(cx, |state, cx| state.set_own_availability(Some(forced), cx));
1182 self.sync_tray(cx);
1183 }
1184 TrayCommand::SetStatusDuration(duration) => {
1185 let Some(kind) = self
1186 .app
1187 .read(cx)
1188 .own_status
1189 .forced
1190 .map(|forced| forced.kind)
1191 .filter(|kind| *kind != ForcedKind::Available)
1192 else {
1193 continue;
1194 };
1195 let forced = ForcedAvailability {
1196 kind,
1197 expires_at: Some(tray_duration(duration).expires_at(Local::now())),
1198 };
1199 self.app
1200 .update(cx, |state, cx| state.set_own_availability(Some(forced), cx));
1201 self.sync_tray(cx);
1202 }
1203 TrayCommand::ResetStatus => {
1204 self.app
1205 .update(cx, |state, cx| state.set_own_availability(None, cx));
1206 self.sync_tray(cx);
1207 }
1208 TrayCommand::Notifications => {
1184 1209 self.raise_main_window(cx);
1185 1210 self.app.update(cx, |state, cx| {
1186 1211 state.open_settings(SettingsSection::Notifications, cx)
@@ -1191,22 +1216,6 @@ impl NotificationCenter {
1191 1216 }
1192 1217 }
1193 1218
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
1210 1219 fn toggle_main_window(&mut self, cx: &mut Context<Self>) {
1211 1220 if self.main_window_active(cx) {
1212 1221 if let Some(native) = self.main_native {
@@ -1264,13 +1273,11 @@ impl NotificationCenter {
1264 1273 }
1265 1274
1266 1275 fn sync_tray(&mut self, cx: &App) {
1267 self.tray_do_not_disturb = own_do_not_disturb(self.app.read(cx));
1268 1276 if let Some(tray) = &self.tray {
1269 tray.sync(
1270 self.settings.sounds.notification_sound,
1271 self.tray_do_not_disturb,
1277 tray.sync(tray_presence_from(
1278 self.app.read(cx),
1272 1279 !self.unread_mentions.is_empty(),
1273 );
1280 ));
1274 1281 }
1275 1282 }
1276 1283
@@ -1547,6 +1554,29 @@ fn own_do_not_disturb(state: &AppState) -> bool {
1547 1554 own_presence(state) == PresenceKind::DoNotDisturb
1548 1555 }
1549 1556
1557 fn tray_presence_from(state: &AppState, mention: bool) -> TrayPresence {
1558 let summary = own_status::state_summary(&state.own_status, own_presence(state), &Local::now());
1559 let title = match &summary.until {
1560 Some(until) => format!("{} {until}", summary.label),
1561 None => summary.label.to_owned(),
1562 };
1563 TrayPresence::new(
1564 title,
1565 state.own_status.forced.map(|forced| forced.kind),
1566 mention,
1567 )
1568 }
1569
1570 fn tray_duration(duration: TrayStatusDuration) -> StatusDuration {
1571 match duration {
1572 TrayStatusDuration::HalfHour => StatusDuration::HalfHour,
1573 TrayStatusDuration::OneHour => StatusDuration::OneHour,
1574 TrayStatusDuration::TwoHours => StatusDuration::TwoHours,
1575 TrayStatusDuration::Today => StatusDuration::Today,
1576 TrayStatusDuration::ThisWeek => StatusDuration::ThisWeek,
1577 }
1578 }
1579
1550 1580 fn sync_loop(handle: &mut Option<SoundHandle>, audible: bool, tone: CallTone, cx: &App) {
1551 1581 match (audible, handle.is_some()) {
1552 1582 (true, false) => *handle = Some(sound_cache::start(tone.file_name(), true, cx)),
@@ -2,7 +2,7 @@ use std::cell::Cell;
2use std::collections::{HashMap, HashSet};
2use std::collections::{HashMap, HashSet};
3use std::time::{Duration, Instant};
3use std::time::{Duration, Instant};
4
4
5use chrono::{DateTime, Utc};
5use chrono::{DateTime, Local, Utc};
6use gpui_kit::*;
6use gpui_kit::*;
7use store::Sidebar;
7use store::Sidebar;
8use teams_core::{ForcedAvailability, ForcedKind};
8use teams_core::{ForcedAvailability, ForcedKind};
@@ -11,7 +11,9 @@ use super::badge::{Badge, badge_for};
11use super::incoming::IncomingTracker;
11use super::incoming::IncomingTracker;
12use super::layout::{self, MEETING_HEIGHT, Slot, ring_height};
12use super::layout::{self, MEETING_HEIGHT, Slot, ring_height};
13use super::meeting_view::MeetingToastView;
13use super::meeting_view::MeetingToastView;
14use super::platform::{self, NativeHandle, Tray, TrayCommand, WorkArea};
14use super::platform::{
15 self, NativeHandle, Tray, TrayCommand, TrayPresence, TrayStatusDuration, WorkArea,
16};
15use super::ring_view::RingView;
17use super::ring_view::RingView;
16use super::rules::{
18use super::rules::{
17 ChatKind, Decision, Environment, Incoming, Preview, Settings, SoundThrottle, decide,
19 ChatKind, Decision, Environment, Incoming, Preview, Settings, SoundThrottle, decide,
@@ -39,6 +41,7 @@ use crate::appearance::AppIcon;
39use crate::autostart::{self, StartupSettings};
41use crate::autostart::{self, StartupSettings};
40use crate::call::DemoScene;
42use crate::call::DemoScene;
41use crate::data::{self, Directory, PresenceKind};
43use crate::data::{self, Directory, PresenceKind};
44use crate::own_status::{self, StatusDuration};
42use crate::runtime;
45use crate::runtime;
43use crate::settings_section::SettingsSection;
46use crate::settings_section::SettingsSection;
44use crate::single_instance;
47use crate::single_instance;
@@ -106,7 +109,6 @@ pub struct NotificationCenter {
106 hover_hold: bool,
109 hover_hold: bool,
107 unread_mentions: HashSet<String>,
110 unread_mentions: HashSet<String>,
108 tray: Option<Tray>,
111 tray: Option<Tray>,
109 tray_do_not_disturb: bool,
110 app_icon: AppIcon,
112 app_icon: AppIcon,
111 shown_badge: Option<Badge>,
113 shown_badge: Option<Badge>,
112 shown_mention_dot: bool,
114 shown_mention_dot: bool,
@@ -131,15 +133,10 @@ impl NotificationCenter {
131 let mut settings = settings::load(&app.read(cx).store);
133 let mut settings = settings::load(&app.read(cx).store);
132 settings.account = app.read(cx).account_chat_settings().notifications;
134 settings.account = app.read(cx).account_chat_settings().notifications;
133 let app_icon = active_appearance::current(cx).app_icon;
135 let app_icon = active_appearance::current(cx).app_icon;
134 let tray_do_not_disturb = own_do_not_disturb(app.read(cx));
135 let tray = if app.read(cx).mode.demo {
136 let tray = if app.read(cx).mode.demo {
136 None
137 None
137 } else {
138 } else {
138 Tray::new(
139 Tray::new(tray_presence_from(&app.read(cx), false), app_icon.png())
139 settings.sounds.notification_sound,
140 tray_do_not_disturb,
141 app_icon.png(),
142 )
143 };
140 };
144 platform::set_window_icon(window, app_icon.png());
141 platform::set_window_icon(window, app_icon.png());
145 let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {
142 let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {
@@ -189,7 +186,6 @@ impl NotificationCenter {
189 hover_hold: false,
186 hover_hold: false,
190 unread_mentions: HashSet::new(),
187 unread_mentions: HashSet::new(),
191 tray,
188 tray,
192 tray_do_not_disturb,
193 app_icon,
189 app_icon,
194 shown_badge: None,
190 shown_badge: None,
195 shown_mention_dot: false,
191 shown_mention_dot: false,
@@ -424,7 +420,7 @@ impl NotificationCenter {
424 AppEvent::Messages(conversation_id) => self.on_messages(conversation_id, cx),
420 AppEvent::Messages(conversation_id) => self.on_messages(conversation_id, cx),
425 AppEvent::Selection => self.on_selection(cx),
421 AppEvent::Selection => self.on_selection(cx),
426 AppEvent::Sidebar => self.refresh_badge(cx),
422 AppEvent::Sidebar => self.refresh_badge(cx),
427 AppEvent::Directory => self.sync_tray_presence(cx),
423 AppEvent::Directory | AppEvent::Status => self.sync_tray(cx),
428 AppEvent::Ring => self.on_rings_changed(cx),
424 AppEvent::Ring => self.on_rings_changed(cx),
429 AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
425 AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
430 AppEvent::MeetingChime => self.on_meeting_chime(cx),
426 AppEvent::MeetingChime => self.on_meeting_chime(cx),
@@ -1176,11 +1172,40 @@ impl NotificationCenter {
1176 match command {
1172 match command {
1177 TrayCommand::Toggle => self.toggle_main_window(cx),
1173 TrayCommand::Toggle => self.toggle_main_window(cx),
1178 TrayCommand::Open => self.raise_main_window(cx),
1174 TrayCommand::Open => self.raise_main_window(cx),
1179 TrayCommand::ToggleSound => self.update_settings(cx, |settings| {
1175 TrayCommand::SetStatus(kind) => {
1180 settings.sounds.notification_sound = !settings.sounds.notification_sound
1176 let forced = ForcedAvailability {
1181 }),
1177 kind,
1182 TrayCommand::ToggleDoNotDisturb => self.toggle_own_do_not_disturb(cx),
1178 expires_at: None,
1183 TrayCommand::Settings => {
1179 };
1180 self.app
1181 .update(cx, |state, cx| state.set_own_availability(Some(forced), cx));
1182 self.sync_tray(cx);
1183 }
1184 TrayCommand::SetStatusDuration(duration) => {
1185 let Some(kind) = self
1186 .app
1187 .read(cx)
1188 .own_status
1189 .forced
1190 .map(|forced| forced.kind)
1191 .filter(|kind| *kind != ForcedKind::Available)
1192 else {
1193 continue;
1194 };
1195 let forced = ForcedAvailability {
1196 kind,
1197 expires_at: Some(tray_duration(duration).expires_at(Local::now())),
1198 };
1199 self.app
1200 .update(cx, |state, cx| state.set_own_availability(Some(forced), cx));
1201 self.sync_tray(cx);
1202 }
1203 TrayCommand::ResetStatus => {
1204 self.app
1205 .update(cx, |state, cx| state.set_own_availability(None, cx));
1206 self.sync_tray(cx);
1207 }
1208 TrayCommand::Notifications => {
1184 self.raise_main_window(cx);
1209 self.raise_main_window(cx);
1185 self.app.update(cx, |state, cx| {
1210 self.app.update(cx, |state, cx| {
1186 state.open_settings(SettingsSection::Notifications, cx)
1211 state.open_settings(SettingsSection::Notifications, cx)
@@ -1191,22 +1216,6 @@ impl NotificationCenter {
1191 }
1216 }
1192 }
1217 }
1193
1218
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
1210 fn toggle_main_window(&mut self, cx: &mut Context<Self>) {
1219 fn toggle_main_window(&mut self, cx: &mut Context<Self>) {
1211 if self.main_window_active(cx) {
1220 if self.main_window_active(cx) {
1212 if let Some(native) = self.main_native {
1221 if let Some(native) = self.main_native {
@@ -1264,13 +1273,11 @@ impl NotificationCenter {
1264 }
1273 }
1265
1274
1266 fn sync_tray(&mut self, cx: &App) {
1275 fn sync_tray(&mut self, cx: &App) {
1267 self.tray_do_not_disturb = own_do_not_disturb(self.app.read(cx));
1268 if let Some(tray) = &self.tray {
1276 if let Some(tray) = &self.tray {
1269 tray.sync(
1277 tray.sync(tray_presence_from(
1270 self.settings.sounds.notification_sound,
1278 self.app.read(cx),
1271 self.tray_do_not_disturb,
1272 !self.unread_mentions.is_empty(),
1279 !self.unread_mentions.is_empty(),
1273 );
1280 ));
1274 }
1281 }
1275 }
1282 }
1276
1283
@@ -1547,6 +1554,29 @@ fn own_do_not_disturb(state: &AppState) -> bool {
1547 own_presence(state) == PresenceKind::DoNotDisturb
1554 own_presence(state) == PresenceKind::DoNotDisturb
1548}
1555}
1549
1556
1557fn tray_presence_from(state: &AppState, mention: bool) -> TrayPresence {
1558 let summary = own_status::state_summary(&state.own_status, own_presence(state), &Local::now());
1559 let title = match &summary.until {
1560 Some(until) => format!("{} {until}", summary.label),
1561 None => summary.label.to_owned(),
1562 };
1563 TrayPresence::new(
1564 title,
1565 state.own_status.forced.map(|forced| forced.kind),
1566 mention,
1567 )
1568}
1569
1570fn tray_duration(duration: TrayStatusDuration) -> StatusDuration {
1571 match duration {
1572 TrayStatusDuration::HalfHour => StatusDuration::HalfHour,
1573 TrayStatusDuration::OneHour => StatusDuration::OneHour,
1574 TrayStatusDuration::TwoHours => StatusDuration::TwoHours,
1575 TrayStatusDuration::Today => StatusDuration::Today,
1576 TrayStatusDuration::ThisWeek => StatusDuration::ThisWeek,
1577 }
1578}
1579
1550fn sync_loop(handle: &mut Option<SoundHandle>, audible: bool, tone: CallTone, cx: &App) {
1580fn sync_loop(handle: &mut Option<SoundHandle>, audible: bool, tone: CallTone, cx: &App) {
1551 match (audible, handle.is_some()) {
1581 match (audible, handle.is_some()) {
1552 (true, false) => *handle = Some(sound_cache::start(tone.file_name(), true, cx)),
1582 (true, false) => *handle = Some(sound_cache::start(tone.file_name(), true, cx)),