Merge pull request #40: tray status submenu like Teams
- Conflicts with #41 in center.rs resolved (desktop client and tray presence side by side) - Status choices, durations and labels moved from app-state own_status to app-base status_choice; tray and status menu share them, TrayStatusDuration and the duplicate labels removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -36,6 +36,7 @@ pub mod remote_image;
36
36
pub mod runtime;
37
37
pub mod schedule_time;
38
38
pub mod single_instance;
39
pub mod status_choice;
39
40
pub mod stickers;
40
41
pub mod support;
41
42
pub mod task_dialog;
@@ -36,6 +36,7 @@ pub mod remote_image;36
pub mod runtime;36
pub mod runtime;37
pub mod schedule_time;37
pub mod schedule_time;38
pub mod single_instance;38
pub mod single_instance;39
pub mod status_choice;39
pub mod stickers;40
pub mod stickers;40
pub mod support;41
pub mod support;41
pub mod task_dialog;42
pub mod task_dialog;@@ -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))]4
pub mod platform;4
pub mod platform;5
pub mod sound_cache;5
pub mod sound_cache;6
pub mod tray_status;6
7
7
pub use chatsvc::sounds;8
pub use chatsvc::sounds;@@ -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,61 @@ 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| item.send(TrayCommand::SetStatus(kind))),
71
..Default::default()
72
}
73
.into(),
74
);
75
}
76
entries.push(MenuItem::Separator);
77
let duration_enabled = tray_status::duration_target(item.forced).is_some();
78
let mut duration_items = Vec::new();
79
for duration in tray_status::STATUS_DURATIONS {
80
duration_items.push(
81
StandardItem {
82
label: menu_label(duration.label()),
83
enabled: duration_enabled,
84
activate: Box::new(move |item: &mut Item| {
85
item.send(TrayCommand::SetStatusDuration(duration))
86
}),
87
..Default::default()
88
}
89
.into(),
90
);
91
}
92
entries.push(
93
SubMenu {
94
label: menu_label(&item.labels.duration),
95
enabled: duration_enabled,
96
submenu: duration_items,
97
..Default::default()
98
}
99
.into(),
100
);
101
entries.push(
102
StandardItem {
103
label: menu_label(&item.labels.reset),
104
activate: Box::new(|item: &mut Item| item.send(TrayCommand::ResetStatus)),
105
..Default::default()
106
}
107
.into(),
108
);
109
SubMenu {
110
label: menu_label(&item.title),
111
submenu: entries,
112
..Default::default()
113
}
114
.into()
115
}
116
60
117
impl ksni::Tray for Item {
61
118
fn id(&self) -> String {
62
119
DESKTOP_ID.to_owned()
@@ -98,23 +155,10 @@ impl ksni::Tray for Item {
98
155
}
99
156
.into(),
100
157
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(),
158
status_submenu(self),
115
159
StandardItem {
116
160
label: menu_label(&self.labels.notifications),
117
activate: Box::new(|item: &mut Self| item.send(TrayCommand::Settings)),
161
activate: Box::new(|item: &mut Self| item.send(TrayCommand::Notifications)),
118
162
..Default::default()
119
163
}
120
164
.into(),
@@ -137,15 +181,15 @@ pub struct Tray {
137
181
138
182
impl Tray {
139
183
/// `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> {
184
pub fn new(presence: TrayPresence, icon_png: &[u8]) -> Option<Self> {
141
185
let (plain, dotted) = tray_icons(icon_png)?;
142
186
let (sender, receiver) = channel();
143
187
let item = Item {
144
188
commands: sender,
145
189
labels: Labels::current(),
146
sound_on,
147
do_not_disturb,
148
mention: false,
190
title: presence.title,
191
forced: presence.forced,
192
mention: presence.mention,
149
193
plain,
150
194
dotted,
151
195
};
@@ -185,13 +229,13 @@ impl Tray {
185
229
});
186
230
}
187
231
188
pub fn sync(&self, sound_on: bool, do_not_disturb: bool, mention: bool) {
232
pub fn sync(&self, presence: TrayPresence) {
189
233
let labels = Labels::current();
190
234
self.handle.update(move |item| {
191
235
item.labels = labels;
192
item.sound_on = sound_on;
193
item.do_not_disturb = do_not_disturb;
194
item.mention = mention;
236
item.title = presence.title;
237
item.forced = presence.forced;
238
item.mention = presence.mention;
195
239
});
196
240
}
197
241
}
@@ -272,4 +316,37 @@ mod tests {
272
316
fn underscores_stay_visible_in_menu_labels() {
273
317
assert_eq!(menu_label("Do_not_disturb"), "Do__not__disturb");
274
318
}
319
320
#[test]
321
fn status_submenu_lists_every_choice_and_reset() {
322
let (sender, _receiver) = channel();
323
let item = Item {
324
commands: sender,
325
labels: Labels::current(),
326
title: "Available".into(),
327
forced: Some(ForcedKind::Busy),
328
mention: false,
329
plain: Vec::new(),
330
dotted: Vec::new(),
331
};
332
let MenuItem::SubMenu(menu) = status_submenu(&item) else {
333
panic!("expected status submenu");
334
};
335
assert_eq!(menu.label, "Available");
336
let labels: Vec<_> = menu
337
.submenu
338
.iter()
339
.filter_map(|entry| match entry {
340
MenuItem::Checkmark(item) => Some(item.label.as_str()),
341
MenuItem::Standard(item) => Some(item.label.as_str()),
342
MenuItem::SubMenu(item) => Some(item.label.as_str()),
343
_ => None,
344
})
345
.collect();
346
for kind in tray_status::STATUS_CHOICES {
347
assert!(labels.contains(&tray_status::choice_label(kind)));
348
}
349
assert!(labels.contains(&tray_status::reset_label()));
350
assert!(labels.contains(&tray_status::duration_menu_label()));
351
}
275
352
}
@@ -4,12 +4,14 @@4
use std::sync::Mutex;4
use std::sync::Mutex;5
use std::sync::mpsc::{Receiver, Sender, channel};5
use std::sync::mpsc::{Receiver, Sender, channel};6
6
7
use chatsvc::ForcedKind;7
use ksni::blocking::{Handle, TrayMethods as _};8
use ksni::blocking::{Handle, TrayMethods as _};8
use ksni::menu::{CheckmarkItem, StandardItem};9
use ksni::menu::{CheckmarkItem, StandardItem, SubMenu};9
use ksni::{Category, Icon, MenuItem, ToolTip};10
use ksni::{Category, Icon, MenuItem, ToolTip};10
11
11
use super::TrayCommand;12
use super::{TrayCommand, TrayPresence};12
use crate::linux_desktop::DESKTOP_ID;13
use crate::linux_desktop::DESKTOP_ID;14
use crate::notify::tray_status;13
15
14
const TRAY_ICON_SIZES: [u32; 3] = [22, 32, 64];16
const TRAY_ICON_SIZES: [u32; 3] = [22, 32, 64];15
const DOT_COLOR: [u8; 4] = [0xef, 0x44, 0x44, 0xff];17
const 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)]18
struct Labels {20
struct 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
26
impl Labels {28
impl 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 {39
struct Item {41
struct 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,61 @@ fn menu_label(text: &str) -> String {57
text.replace('_', "__")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| item.send(TrayCommand::SetStatus(kind))),71
..Default::default()72
}73
.into(),74
);75
}76
entries.push(MenuItem::Separator);77
let duration_enabled = tray_status::duration_target(item.forced).is_some();78
let mut duration_items = Vec::new();79
for duration in tray_status::STATUS_DURATIONS {80
duration_items.push(81
StandardItem {82
label: menu_label(duration.label()),83
enabled: duration_enabled,84
activate: Box::new(move |item: &mut Item| {85
item.send(TrayCommand::SetStatusDuration(duration))86
}),87
..Default::default()88
}89
.into(),90
);91
}92
entries.push(93
SubMenu {94
label: menu_label(&item.labels.duration),95
enabled: duration_enabled,96
submenu: duration_items,97
..Default::default()98
}99
.into(),100
);101
entries.push(102
StandardItem {103
label: menu_label(&item.labels.reset),104
activate: Box::new(|item: &mut Item| item.send(TrayCommand::ResetStatus)),105
..Default::default()106
}107
.into(),108
);109
SubMenu {110
label: menu_label(&item.title),111
submenu: entries,112
..Default::default()113
}114
.into()115
}116
60
impl ksni::Tray for Item {117
impl ksni::Tray for Item {61
fn id(&self) -> String {118
fn id(&self) -> String {62
DESKTOP_ID.to_owned()119
DESKTOP_ID.to_owned()@@ -98,23 +155,10 @@ impl ksni::Tray for Item {98
}155
}99
.into(),156
.into(),100
MenuItem::Separator,157
MenuItem::Separator,101
CheckmarkItem {158
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 {159
StandardItem {116
label: menu_label(&self.labels.notifications),160
label: menu_label(&self.labels.notifications),117
activate: Box::new(|item: &mut Self| item.send(TrayCommand::Settings)),161
activate: Box::new(|item: &mut Self| item.send(TrayCommand::Notifications)),118
..Default::default()162
..Default::default()119
}163
}120
.into(),164
.into(),@@ -137,15 +181,15 @@ pub struct Tray {137
181
138
impl Tray {182
impl Tray {139
/// `None` when there is no session bus or no tray host (no StatusNotifierWatcher).183
/// `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> {184
pub fn new(presence: TrayPresence, icon_png: &[u8]) -> Option<Self> {141
let (plain, dotted) = tray_icons(icon_png)?;185
let (plain, dotted) = tray_icons(icon_png)?;142
let (sender, receiver) = channel();186
let (sender, receiver) = channel();143
let item = Item {187
let item = Item {144
commands: sender,188
commands: sender,145
labels: Labels::current(),189
labels: Labels::current(),146
sound_on,190
title: presence.title,147
do_not_disturb,191
forced: presence.forced,148
mention: false,192
mention: presence.mention,149
plain,193
plain,150
dotted,194
dotted,151
};195
};@@ -185,13 +229,13 @@ impl Tray {185
});229
});186
}230
}187
231
188
pub fn sync(&self, sound_on: bool, do_not_disturb: bool, mention: bool) {232
pub fn sync(&self, presence: TrayPresence) {189
let labels = Labels::current();233
let labels = Labels::current();190
self.handle.update(move |item| {234
self.handle.update(move |item| {191
item.labels = labels;235
item.labels = labels;192
item.sound_on = sound_on;236
item.title = presence.title;193
item.do_not_disturb = do_not_disturb;237
item.forced = presence.forced;194
item.mention = mention;238
item.mention = presence.mention;195
});239
});196
}240
}197
}241
}@@ -272,4 +316,37 @@ mod tests {272
fn underscores_stay_visible_in_menu_labels() {316
fn underscores_stay_visible_in_menu_labels() {273
assert_eq!(menu_label("Do_not_disturb"), "Do__not__disturb");317
assert_eq!(menu_label("Do_not_disturb"), "Do__not__disturb");274
}318
}319
320
#[test]321
fn status_submenu_lists_every_choice_and_reset() {322
let (sender, _receiver) = channel();323
let item = Item {324
commands: sender,325
labels: Labels::current(),326
title: "Available".into(),327
forced: Some(ForcedKind::Busy),328
mention: false,329
plain: Vec::new(),330
dotted: Vec::new(),331
};332
let MenuItem::SubMenu(menu) = status_submenu(&item) else {333
panic!("expected status submenu");334
};335
assert_eq!(menu.label, "Available");336
let labels: Vec<_> = menu337
.submenu338
.iter()339
.filter_map(|entry| match entry {340
MenuItem::Checkmark(item) => Some(item.label.as_str()),341
MenuItem::Standard(item) => Some(item.label.as_str()),342
MenuItem::SubMenu(item) => Some(item.label.as_str()),343
_ => None,344
})345
.collect();346
for kind in tray_status::STATUS_CHOICES {347
assert!(labels.contains(&tray_status::choice_label(kind)));348
}349
assert!(labels.contains(&tray_status::reset_label()));350
assert!(labels.contains(&tray_status::duration_menu_label()));351
}275
}352
}@@ -65,8 +65,30 @@ pub struct ShareGeometry {
65
65
pub enum TrayCommand {
66
66
Toggle,
67
67
Open,
68
ToggleSound,
69
ToggleDoNotDisturb,
70
Settings,
68
SetStatus(chatsvc::ForcedKind),
69
SetStatusDuration(crate::status_choice::StatusDuration),
70
ResetStatus,
71
Notifications,
71
72
Quit,
72
73
}
74
75
#[derive(Debug, Clone, PartialEq, Eq)]
76
pub struct TrayPresence {
77
pub title: String,
78
pub forced: Option<chatsvc::ForcedKind>,
79
pub mention: bool,
80
}
81
82
impl TrayPresence {
83
pub fn new(
84
title: impl Into<String>,
85
forced: Option<chatsvc::ForcedKind>,
86
mention: bool,
87
) -> Self {
88
Self {
89
title: title.into(),
90
forced,
91
mention,
92
}
93
}
94
}
@@ -65,8 +65,30 @@ pub struct ShareGeometry {65
pub enum TrayCommand {65
pub enum TrayCommand {66
Toggle,66
Toggle,67
Open,67
Open,68
ToggleSound,68
SetStatus(chatsvc::ForcedKind),69
ToggleDoNotDisturb,69
SetStatusDuration(crate::status_choice::StatusDuration),70
Settings,70
ResetStatus,71
Notifications,71
Quit,72
Quit,72
}73
}74
75
#[derive(Debug, Clone, PartialEq, Eq)]76
pub struct TrayPresence {77
pub title: String,78
pub forced: Option<chatsvc::ForcedKind>,79
pub mention: bool,80
}81
82
impl TrayPresence {83
pub fn new(84
title: impl Into<String>,85
forced: Option<chatsvc::ForcedKind>,86
mention: bool,87
) -> Self {88
Self {89
title: title.into(),90
forced,91
mention,92
}93
}94
}@@ -117,7 +117,7 @@ pub struct Tray;
117
117
118
118
#[cfg(not(target_os = "linux"))]
119
119
impl Tray {
120
pub fn new(_sound_on: bool, _do_not_disturb: bool, _icon_png: &[u8]) -> Option<Self> {
120
pub fn new(_presence: super::TrayPresence, _icon_png: &[u8]) -> Option<Self> {
121
121
None
122
122
}
123
123
@@ -127,7 +127,7 @@ impl Tray {
127
127
Vec::new()
128
128
}
129
129
130
pub fn sync(&self, _sound_on: bool, _do_not_disturb: bool, _mention: bool) {}
130
pub fn sync(&self, _presence: super::TrayPresence) {}
131
131
132
132
pub fn relocalize(&self) {}
133
133
}
@@ -117,7 +117,7 @@ pub struct Tray;117
117
118
#[cfg(not(target_os = "linux"))]118
#[cfg(not(target_os = "linux"))]119
impl Tray {119
impl Tray {120
pub fn new(_sound_on: bool, _do_not_disturb: bool, _icon_png: &[u8]) -> Option<Self> {120
pub fn new(_presence: super::TrayPresence, _icon_png: &[u8]) -> Option<Self> {121
None121
None122
}122
}123
123
@@ -127,7 +127,7 @@ impl Tray {127
Vec::new()127
Vec::new()128
}128
}129
129
130
pub fn sync(&self, _sound_on: bool, _do_not_disturb: bool, _mention: bool) {}130
pub fn sync(&self, _presence: super::TrayPresence) {}131
131
132
pub fn relocalize(&self) {}132
pub fn relocalize(&self) {}133
}133
}@@ -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
duration.label(),
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
¬ifications,
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(duration.label());
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;7
use calling::ShareKind;7
use calling::ShareKind;8
use gpui_kit::Window;8
use gpui_kit::Window;9
use raw_window_handle::{HasWindowHandle, RawWindowHandle};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
use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};11
use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};12
use windows::Win32::Foundation::{COLORREF, HWND, LPARAM, POINT, RECT, WPARAM};12
use windows::Win32::Foundation::{COLORREF, HWND, LPARAM, POINT, RECT, WPARAM};13
use windows::Win32::Graphics::Dwm::{13
use windows::Win32::Graphics::Dwm::{@@ -43,8 +43,9 @@ use windows::Win32::UI::WindowsAndMessaging::{43
use windows::core::{BOOL, PCWSTR, w};43
use windows::core::{BOOL, PCWSTR, w};44
44
45
use super::stack_plan::{StackPlan, stack_plan};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
use crate::notify::badge::{Badge, render_badge};47
use crate::notify::badge::{Badge, render_badge};48
use crate::notify::tray_status;48
49
49
const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");50
const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");50
const TRAY_ICON_SIZE: u32 = 32;51
const TRAY_ICON_SIZE: u32 = 32;@@ -652,17 +653,19 @@ pub fn play_sound() {652
}653
}653
654
654
const ID_OPEN: &str = "open";655
const ID_OPEN: &str = "open";655
const ID_SOUND: &str = "sound";656
const ID_NOTIFICATIONS: &str = "notifications";656
const ID_DO_NOT_DISTURB: &str = "do_not_disturb";657
const ID_SETTINGS: &str = "settings";658
const ID_QUIT: &str = "quit";657
const ID_QUIT: &str = "quit";658
const ID_RESET_STATUS: &str = "status:reset";659
659
660
pub struct Tray {660
pub 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
675
impl Tray {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
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_CHOICES680
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_DURATIONS693
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
duration.label(),701
duration_enabled,702
None,703
)704
})705
.collect();706
let duration_refs: Vec<&dyn tray_icon::menu::IsMenuItem> = duration_items707
.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_items718
.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
¬ifications,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 _ = self734
.do_not_disturb735
.set_text(tray_menu_label("tray.do_not_disturb"));736
let _ = self767
let _ = self737
.settings768
.notifications738
.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 _ = self773
.duration_menu774
.set_text(tray_status::duration_menu_label());775
for (item, kind) in self776
.status_items777
.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 self783
.duration_items784
.iter()785
.zip(tray_status::STATUS_DURATIONS.into_iter())786
{787
let _ = item.set_text(duration.label());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 self782
let icon = if mention { &self.with_dot } else { &self.plain };839
.status_items840
.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_dot852
} else {853
&self.plain854
};783
let _ = self.icon.set_icon(Some(icon.clone()));855
let _ = self.icon.set_icon(Some(icon.clone()));784
}856
}785
}857
}@@ -0,0 +1,88 @@
1
use chatsvc::ForcedKind;
2
3
use crate::status_choice::StatusDuration;
4
pub use crate::status_choice::{STATUS_CHOICES, STATUS_DURATIONS, choice_label};
5
6
pub fn duration_target(forced: Option<ForcedKind>) -> Option<ForcedKind> {
7
forced.filter(|kind| *kind != ForcedKind::Available)
8
}
9
10
pub fn reset_label() -> &'static str {
11
"Reset status"
12
}
13
14
pub fn duration_menu_label() -> &'static str {
15
"Duration"
16
}
17
18
pub fn kind_id(kind: ForcedKind) -> &'static str {
19
match kind {
20
ForcedKind::Available => "status:available",
21
ForcedKind::Busy => "status:busy",
22
ForcedKind::DoNotDisturb => "status:dnd",
23
ForcedKind::BeRightBack => "status:brb",
24
ForcedKind::Away => "status:away",
25
ForcedKind::Offline => "status:offline",
26
}
27
}
28
29
pub fn parse_kind_id(id: &str) -> Option<ForcedKind> {
30
match id {
31
"status:available" => Some(ForcedKind::Available),
32
"status:busy" => Some(ForcedKind::Busy),
33
"status:dnd" => Some(ForcedKind::DoNotDisturb),
34
"status:brb" => Some(ForcedKind::BeRightBack),
35
"status:away" => Some(ForcedKind::Away),
36
"status:offline" => Some(ForcedKind::Offline),
37
_ => None,
38
}
39
}
40
41
pub fn duration_id(duration: StatusDuration) -> &'static str {
42
match duration {
43
StatusDuration::HalfHour => "status-duration:30m",
44
StatusDuration::OneHour => "status-duration:1h",
45
StatusDuration::TwoHours => "status-duration:2h",
46
StatusDuration::Today => "status-duration:today",
47
StatusDuration::ThisWeek => "status-duration:week",
48
}
49
}
50
51
pub fn parse_duration_id(id: &str) -> Option<StatusDuration> {
52
match id {
53
"status-duration:30m" => Some(StatusDuration::HalfHour),
54
"status-duration:1h" => Some(StatusDuration::OneHour),
55
"status-duration:2h" => Some(StatusDuration::TwoHours),
56
"status-duration:today" => Some(StatusDuration::Today),
57
"status-duration:week" => Some(StatusDuration::ThisWeek),
58
_ => None,
59
}
60
}
61
62
#[cfg(test)]
63
mod tests {
64
use super::*;
65
66
#[test]
67
fn every_choice_has_a_stable_id() {
68
for kind in STATUS_CHOICES {
69
assert_eq!(parse_kind_id(kind_id(kind)), Some(kind));
70
}
71
}
72
73
#[test]
74
fn every_duration_has_a_stable_id() {
75
for duration in STATUS_DURATIONS {
76
assert_eq!(parse_duration_id(duration_id(duration)), Some(duration));
77
}
78
}
79
80
#[test]
81
fn available_has_no_duration_target() {
82
assert_eq!(duration_target(Some(ForcedKind::Available)), None);
83
assert_eq!(
84
duration_target(Some(ForcedKind::DoNotDisturb)),
85
Some(ForcedKind::DoNotDisturb)
86
);
87
}
88
}
@@ -0,0 +1,88 @@1
use chatsvc::ForcedKind;2
3
use crate::status_choice::StatusDuration;4
pub use crate::status_choice::{STATUS_CHOICES, STATUS_DURATIONS, choice_label};5
6
pub fn duration_target(forced: Option<ForcedKind>) -> Option<ForcedKind> {7
forced.filter(|kind| *kind != ForcedKind::Available)8
}9
10
pub fn reset_label() -> &'static str {11
"Reset status"12
}13
14
pub fn duration_menu_label() -> &'static str {15
"Duration"16
}17
18
pub fn kind_id(kind: ForcedKind) -> &'static str {19
match kind {20
ForcedKind::Available => "status:available",21
ForcedKind::Busy => "status:busy",22
ForcedKind::DoNotDisturb => "status:dnd",23
ForcedKind::BeRightBack => "status:brb",24
ForcedKind::Away => "status:away",25
ForcedKind::Offline => "status:offline",26
}27
}28
29
pub fn parse_kind_id(id: &str) -> Option<ForcedKind> {30
match id {31
"status:available" => Some(ForcedKind::Available),32
"status:busy" => Some(ForcedKind::Busy),33
"status:dnd" => Some(ForcedKind::DoNotDisturb),34
"status:brb" => Some(ForcedKind::BeRightBack),35
"status:away" => Some(ForcedKind::Away),36
"status:offline" => Some(ForcedKind::Offline),37
_ => None,38
}39
}40
41
pub fn duration_id(duration: StatusDuration) -> &'static str {42
match duration {43
StatusDuration::HalfHour => "status-duration:30m",44
StatusDuration::OneHour => "status-duration:1h",45
StatusDuration::TwoHours => "status-duration:2h",46
StatusDuration::Today => "status-duration:today",47
StatusDuration::ThisWeek => "status-duration:week",48
}49
}50
51
pub fn parse_duration_id(id: &str) -> Option<StatusDuration> {52
match id {53
"status-duration:30m" => Some(StatusDuration::HalfHour),54
"status-duration:1h" => Some(StatusDuration::OneHour),55
"status-duration:2h" => Some(StatusDuration::TwoHours),56
"status-duration:today" => Some(StatusDuration::Today),57
"status-duration:week" => Some(StatusDuration::ThisWeek),58
_ => None,59
}60
}61
62
#[cfg(test)]63
mod tests {64
use super::*;65
66
#[test]67
fn every_choice_has_a_stable_id() {68
for kind in STATUS_CHOICES {69
assert_eq!(parse_kind_id(kind_id(kind)), Some(kind));70
}71
}72
73
#[test]74
fn every_duration_has_a_stable_id() {75
for duration in STATUS_DURATIONS {76
assert_eq!(parse_duration_id(duration_id(duration)), Some(duration));77
}78
}79
80
#[test]81
fn available_has_no_duration_target() {82
assert_eq!(duration_target(Some(ForcedKind::Available)), None);83
assert_eq!(84
duration_target(Some(ForcedKind::DoNotDisturb)),85
Some(ForcedKind::DoNotDisturb)86
);87
}88
}@@ -0,0 +1,93 @@
1
use chatsvc::ForcedKind;
2
use chrono::{DateTime, Datelike, Duration, NaiveTime, TimeZone, Utc};
3
4
pub const STATUS_CHOICES: [ForcedKind; 6] = [
5
ForcedKind::Available,
6
ForcedKind::Busy,
7
ForcedKind::DoNotDisturb,
8
ForcedKind::BeRightBack,
9
ForcedKind::Away,
10
ForcedKind::Offline,
11
];
12
pub const STATUS_DURATIONS: [StatusDuration; 5] = [
13
StatusDuration::HalfHour,
14
StatusDuration::OneHour,
15
StatusDuration::TwoHours,
16
StatusDuration::Today,
17
StatusDuration::ThisWeek,
18
];
19
20
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21
pub enum StatusDuration {
22
HalfHour,
23
OneHour,
24
TwoHours,
25
Today,
26
ThisWeek,
27
}
28
29
impl StatusDuration {
30
pub fn label(self) -> &'static str {
31
match self {
32
StatusDuration::HalfHour => "30 minutes",
33
StatusDuration::OneHour => "1 hour",
34
StatusDuration::TwoHours => "2 hours",
35
StatusDuration::Today => "Today",
36
StatusDuration::ThisWeek => "This week",
37
}
38
}
39
40
pub fn expires_at<Zone: TimeZone>(self, now: DateTime<Zone>) -> DateTime<Utc> {
41
match self {
42
StatusDuration::HalfHour => after(&now, Duration::minutes(30)),
43
StatusDuration::OneHour => after(&now, Duration::hours(1)),
44
StatusDuration::TwoHours => after(&now, Duration::hours(2)),
45
StatusDuration::Today => end_of_day(&now),
46
StatusDuration::ThisWeek => end_of_week(&now),
47
}
48
}
49
}
50
51
pub fn after<Zone: TimeZone>(now: &DateTime<Zone>, span: Duration) -> DateTime<Utc> {
52
(now.clone() + span).with_timezone(&Utc)
53
}
54
55
fn end_of_local_date<Zone: TimeZone>(now: &DateTime<Zone>, days_ahead: i64) -> DateTime<Utc> {
56
let last_moment = NaiveTime::from_hms_milli_opt(23, 59, 59, 999).unwrap_or(NaiveTime::MIN);
57
let date = now.date_naive() + Duration::days(days_ahead);
58
now.timezone()
59
.from_local_datetime(&date.and_time(last_moment))
60
.latest()
61
.map_or_else(
62
|| after(now, Duration::days(days_ahead + 1)),
63
|moment| moment.with_timezone(&Utc),
64
)
65
}
66
67
pub fn end_of_day<Zone: TimeZone>(now: &DateTime<Zone>) -> DateTime<Utc> {
68
end_of_local_date(now, 0)
69
}
70
71
pub fn end_of_week<Zone: TimeZone>(now: &DateTime<Zone>) -> DateTime<Utc> {
72
let days_since_sunday = i64::from(now.weekday().num_days_from_sunday());
73
end_of_local_date(now, 6 - days_since_sunday)
74
}
75
76
pub fn choice_label(kind: ForcedKind) -> &'static str {
77
match kind {
78
ForcedKind::Away => "Appear away",
79
ForcedKind::Offline => "Appear offline",
80
other => state_label(other),
81
}
82
}
83
84
pub fn state_label(kind: ForcedKind) -> &'static str {
85
match kind {
86
ForcedKind::Available => "Available",
87
ForcedKind::Busy => "Busy",
88
ForcedKind::DoNotDisturb => "Do not disturb",
89
ForcedKind::BeRightBack => "Be right back",
90
ForcedKind::Away => "Away",
91
ForcedKind::Offline => "Offline",
92
}
93
}
@@ -0,0 +1,93 @@1
use chatsvc::ForcedKind;2
use chrono::{DateTime, Datelike, Duration, NaiveTime, TimeZone, Utc};3
4
pub const STATUS_CHOICES: [ForcedKind; 6] = [5
ForcedKind::Available,6
ForcedKind::Busy,7
ForcedKind::DoNotDisturb,8
ForcedKind::BeRightBack,9
ForcedKind::Away,10
ForcedKind::Offline,11
];12
pub const STATUS_DURATIONS: [StatusDuration; 5] = [13
StatusDuration::HalfHour,14
StatusDuration::OneHour,15
StatusDuration::TwoHours,16
StatusDuration::Today,17
StatusDuration::ThisWeek,18
];19
20
#[derive(Debug, Clone, Copy, PartialEq, Eq)]21
pub enum StatusDuration {22
HalfHour,23
OneHour,24
TwoHours,25
Today,26
ThisWeek,27
}28
29
impl StatusDuration {30
pub fn label(self) -> &'static str {31
match self {32
StatusDuration::HalfHour => "30 minutes",33
StatusDuration::OneHour => "1 hour",34
StatusDuration::TwoHours => "2 hours",35
StatusDuration::Today => "Today",36
StatusDuration::ThisWeek => "This week",37
}38
}39
40
pub fn expires_at<Zone: TimeZone>(self, now: DateTime<Zone>) -> DateTime<Utc> {41
match self {42
StatusDuration::HalfHour => after(&now, Duration::minutes(30)),43
StatusDuration::OneHour => after(&now, Duration::hours(1)),44
StatusDuration::TwoHours => after(&now, Duration::hours(2)),45
StatusDuration::Today => end_of_day(&now),46
StatusDuration::ThisWeek => end_of_week(&now),47
}48
}49
}50
51
pub fn after<Zone: TimeZone>(now: &DateTime<Zone>, span: Duration) -> DateTime<Utc> {52
(now.clone() + span).with_timezone(&Utc)53
}54
55
fn end_of_local_date<Zone: TimeZone>(now: &DateTime<Zone>, days_ahead: i64) -> DateTime<Utc> {56
let last_moment = NaiveTime::from_hms_milli_opt(23, 59, 59, 999).unwrap_or(NaiveTime::MIN);57
let date = now.date_naive() + Duration::days(days_ahead);58
now.timezone()59
.from_local_datetime(&date.and_time(last_moment))60
.latest()61
.map_or_else(62
|| after(now, Duration::days(days_ahead + 1)),63
|moment| moment.with_timezone(&Utc),64
)65
}66
67
pub fn end_of_day<Zone: TimeZone>(now: &DateTime<Zone>) -> DateTime<Utc> {68
end_of_local_date(now, 0)69
}70
71
pub fn end_of_week<Zone: TimeZone>(now: &DateTime<Zone>) -> DateTime<Utc> {72
let days_since_sunday = i64::from(now.weekday().num_days_from_sunday());73
end_of_local_date(now, 6 - days_since_sunday)74
}75
76
pub fn choice_label(kind: ForcedKind) -> &'static str {77
match kind {78
ForcedKind::Away => "Appear away",79
ForcedKind::Offline => "Appear offline",80
other => state_label(other),81
}82
}83
84
pub fn state_label(kind: ForcedKind) -> &'static str {85
match kind {86
ForcedKind::Available => "Available",87
ForcedKind::Busy => "Busy",88
ForcedKind::DoNotDisturb => "Do not disturb",89
ForcedKind::BeRightBack => "Be right back",90
ForcedKind::Away => "Away",91
ForcedKind::Offline => "Offline",92
}93
}@@ -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
@@ -1,6 +1,11 @@
1
1
use std::sync::Arc;
2
2
3
use chrono::{DateTime, Datelike, Duration, NaiveTime, TimeZone, Utc};
3
use app_base::status_choice::after;
4
pub use app_base::status_choice::{
5
STATUS_CHOICES, STATUS_DURATIONS, StatusDuration, choice_label, end_of_day, end_of_week,
6
state_label,
7
};
8
use chrono::{DateTime, Duration, TimeZone, Utc};
4
9
use gpui_kit::*;
5
10
use teams_core::{
6
11
ForcedAvailability, ForcedKind, PresenceStatus, StatusNote, WorkLocation, WorkLocationKind,
@@ -13,21 +18,6 @@ use crate::data::PresenceKind;
13
18
14
19
pub const NOTE_LIMIT: usize = 280;
15
20
const WORK_LOCATION_FAILED: &str = "Work location couldn't be set. Try again.";
16
pub const STATUS_CHOICES: [ForcedKind; 6] = [
17
ForcedKind::Available,
18
ForcedKind::Busy,
19
ForcedKind::DoNotDisturb,
20
ForcedKind::BeRightBack,
21
ForcedKind::Away,
22
ForcedKind::Offline,
23
];
24
pub const STATUS_DURATIONS: [StatusDuration; 5] = [
25
StatusDuration::HalfHour,
26
StatusDuration::OneHour,
27
StatusDuration::TwoHours,
28
StatusDuration::Today,
29
StatusDuration::ThisWeek,
30
];
31
21
pub const NOTE_DURATIONS: [NoteDuration; 5] = [
32
22
NoteDuration::Never,
33
23
NoteDuration::OneHour,
@@ -36,37 +26,6 @@ pub const NOTE_DURATIONS: [NoteDuration; 5] = [
36
26
NoteDuration::ThisWeek,
37
27
];
38
28
39
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40
pub enum StatusDuration {
41
HalfHour,
42
OneHour,
43
TwoHours,
44
Today,
45
ThisWeek,
46
}
47
48
impl StatusDuration {
49
pub fn label(self) -> &'static str {
50
match self {
51
StatusDuration::HalfHour => "30 minutes",
52
StatusDuration::OneHour => "1 hour",
53
StatusDuration::TwoHours => "2 hours",
54
StatusDuration::Today => "Today",
55
StatusDuration::ThisWeek => "This week",
56
}
57
}
58
59
pub fn expires_at<Zone: TimeZone>(self, now: DateTime<Zone>) -> DateTime<Utc> {
60
match self {
61
StatusDuration::HalfHour => after(&now, Duration::minutes(30)),
62
StatusDuration::OneHour => after(&now, Duration::hours(1)),
63
StatusDuration::TwoHours => after(&now, Duration::hours(2)),
64
StatusDuration::Today => end_of_day(&now),
65
StatusDuration::ThisWeek => end_of_week(&now),
66
}
67
}
68
}
69
70
29
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
71
30
pub enum NoteDuration {
72
31
Never,
@@ -100,50 +59,6 @@ impl NoteDuration {
100
59
}
101
60
}
102
61
103
fn after<Zone: TimeZone>(now: &DateTime<Zone>, span: Duration) -> DateTime<Utc> {
104
(now.clone() + span).with_timezone(&Utc)
105
}
106
107
fn end_of_local_date<Zone: TimeZone>(now: &DateTime<Zone>, days_ahead: i64) -> DateTime<Utc> {
108
let last_moment = NaiveTime::from_hms_milli_opt(23, 59, 59, 999).unwrap_or(NaiveTime::MIN);
109
let date = now.date_naive() + Duration::days(days_ahead);
110
now.timezone()
111
.from_local_datetime(&date.and_time(last_moment))
112
.latest()
113
.map_or_else(
114
|| after(now, Duration::days(days_ahead + 1)),
115
|moment| moment.with_timezone(&Utc),
116
)
117
}
118
119
pub fn end_of_day<Zone: TimeZone>(now: &DateTime<Zone>) -> DateTime<Utc> {
120
end_of_local_date(now, 0)
121
}
122
123
pub fn end_of_week<Zone: TimeZone>(now: &DateTime<Zone>) -> DateTime<Utc> {
124
let days_since_sunday = i64::from(now.weekday().num_days_from_sunday());
125
end_of_local_date(now, 6 - days_since_sunday)
126
}
127
128
pub fn choice_label(kind: ForcedKind) -> &'static str {
129
match kind {
130
ForcedKind::Away => "Appear away",
131
ForcedKind::Offline => "Appear offline",
132
other => state_label(other),
133
}
134
}
135
136
pub fn state_label(kind: ForcedKind) -> &'static str {
137
match kind {
138
ForcedKind::Available => "Available",
139
ForcedKind::Busy => "Busy",
140
ForcedKind::DoNotDisturb => "Do not disturb",
141
ForcedKind::BeRightBack => "Be right back",
142
ForcedKind::Away => "Away",
143
ForcedKind::Offline => "Offline",
144
}
145
}
146
147
62
pub fn presence_kind_for(kind: ForcedKind) -> PresenceKind {
148
63
match kind {
149
64
ForcedKind::Available => PresenceKind::Available,
@@ -1,6 +1,11 @@1
use std::sync::Arc;1
use std::sync::Arc;2
2
3
use chrono::{DateTime, Datelike, Duration, NaiveTime, TimeZone, Utc};3
use app_base::status_choice::after;4
pub use app_base::status_choice::{5
STATUS_CHOICES, STATUS_DURATIONS, StatusDuration, choice_label, end_of_day, end_of_week,6
state_label,7
};8
use chrono::{DateTime, Duration, TimeZone, Utc};4
use gpui_kit::*;9
use gpui_kit::*;5
use teams_core::{10
use teams_core::{6
ForcedAvailability, ForcedKind, PresenceStatus, StatusNote, WorkLocation, WorkLocationKind,11
ForcedAvailability, ForcedKind, PresenceStatus, StatusNote, WorkLocation, WorkLocationKind,@@ -13,21 +18,6 @@ use crate::data::PresenceKind;13
18
14
pub const NOTE_LIMIT: usize = 280;19
pub const NOTE_LIMIT: usize = 280;15
const WORK_LOCATION_FAILED: &str = "Work location couldn't be set. Try again.";20
const WORK_LOCATION_FAILED: &str = "Work location couldn't be set. Try again.";16
pub const STATUS_CHOICES: [ForcedKind; 6] = [17
ForcedKind::Available,18
ForcedKind::Busy,19
ForcedKind::DoNotDisturb,20
ForcedKind::BeRightBack,21
ForcedKind::Away,22
ForcedKind::Offline,23
];24
pub const STATUS_DURATIONS: [StatusDuration; 5] = [25
StatusDuration::HalfHour,26
StatusDuration::OneHour,27
StatusDuration::TwoHours,28
StatusDuration::Today,29
StatusDuration::ThisWeek,30
];31
pub const NOTE_DURATIONS: [NoteDuration; 5] = [21
pub const NOTE_DURATIONS: [NoteDuration; 5] = [32
NoteDuration::Never,22
NoteDuration::Never,33
NoteDuration::OneHour,23
NoteDuration::OneHour,@@ -36,37 +26,6 @@ pub const NOTE_DURATIONS: [NoteDuration; 5] = [36
NoteDuration::ThisWeek,26
NoteDuration::ThisWeek,37
];27
];38
28
39
#[derive(Debug, Clone, Copy, PartialEq, Eq)]40
pub enum StatusDuration {41
HalfHour,42
OneHour,43
TwoHours,44
Today,45
ThisWeek,46
}47
48
impl StatusDuration {49
pub fn label(self) -> &'static str {50
match self {51
StatusDuration::HalfHour => "30 minutes",52
StatusDuration::OneHour => "1 hour",53
StatusDuration::TwoHours => "2 hours",54
StatusDuration::Today => "Today",55
StatusDuration::ThisWeek => "This week",56
}57
}58
59
pub fn expires_at<Zone: TimeZone>(self, now: DateTime<Zone>) -> DateTime<Utc> {60
match self {61
StatusDuration::HalfHour => after(&now, Duration::minutes(30)),62
StatusDuration::OneHour => after(&now, Duration::hours(1)),63
StatusDuration::TwoHours => after(&now, Duration::hours(2)),64
StatusDuration::Today => end_of_day(&now),65
StatusDuration::ThisWeek => end_of_week(&now),66
}67
}68
}69
70
#[derive(Debug, Clone, Copy, PartialEq, Eq)]29
#[derive(Debug, Clone, Copy, PartialEq, Eq)]71
pub enum NoteDuration {30
pub enum NoteDuration {72
Never,31
Never,@@ -100,50 +59,6 @@ impl NoteDuration {100
}59
}101
}60
}102
61
103
fn after<Zone: TimeZone>(now: &DateTime<Zone>, span: Duration) -> DateTime<Utc> {104
(now.clone() + span).with_timezone(&Utc)105
}106
107
fn end_of_local_date<Zone: TimeZone>(now: &DateTime<Zone>, days_ahead: i64) -> DateTime<Utc> {108
let last_moment = NaiveTime::from_hms_milli_opt(23, 59, 59, 999).unwrap_or(NaiveTime::MIN);109
let date = now.date_naive() + Duration::days(days_ahead);110
now.timezone()111
.from_local_datetime(&date.and_time(last_moment))112
.latest()113
.map_or_else(114
|| after(now, Duration::days(days_ahead + 1)),115
|moment| moment.with_timezone(&Utc),116
)117
}118
119
pub fn end_of_day<Zone: TimeZone>(now: &DateTime<Zone>) -> DateTime<Utc> {120
end_of_local_date(now, 0)121
}122
123
pub fn end_of_week<Zone: TimeZone>(now: &DateTime<Zone>) -> DateTime<Utc> {124
let days_since_sunday = i64::from(now.weekday().num_days_from_sunday());125
end_of_local_date(now, 6 - days_since_sunday)126
}127
128
pub fn choice_label(kind: ForcedKind) -> &'static str {129
match kind {130
ForcedKind::Away => "Appear away",131
ForcedKind::Offline => "Appear offline",132
other => state_label(other),133
}134
}135
136
pub fn state_label(kind: ForcedKind) -> &'static str {137
match kind {138
ForcedKind::Available => "Available",139
ForcedKind::Busy => "Busy",140
ForcedKind::DoNotDisturb => "Do not disturb",141
ForcedKind::BeRightBack => "Be right back",142
ForcedKind::Away => "Away",143
ForcedKind::Offline => "Offline",144
}145
}146
147
pub fn presence_kind_for(kind: ForcedKind) -> PresenceKind {62
pub fn presence_kind_for(kind: ForcedKind) -> PresenceKind {148
match kind {63
match kind {149
ForcedKind::Available => PresenceKind::Available,64
ForcedKind::Available => PresenceKind::Available,@@ -15,7 +15,7 @@ use super::desktop_payload::{
15
15
use super::incoming::IncomingTracker;
16
16
use super::layout::{self, MEETING_HEIGHT, Slot, ring_height};
17
17
use super::meeting_view::MeetingToastView;
18
use super::platform::{self, NativeHandle, Tray, TrayCommand, WorkArea};
18
use super::platform::{self, NativeHandle, Tray, TrayCommand, TrayPresence, WorkArea};
19
19
#[cfg(target_os = "linux")]
20
20
use super::platform::{
21
21
BusNotification, DesktopNotifications, NotificationEvent, NotificationImage,
@@ -47,6 +47,7 @@ use crate::appearance::AppIcon;
47
47
use crate::autostart::{self, StartupSettings};
48
48
use crate::call::DemoScene;
49
49
use crate::data::{self, Directory, PresenceKind};
50
use crate::own_status;
50
51
use crate::runtime;
51
52
use crate::settings_section::SettingsSection;
52
53
use crate::single_instance;
@@ -114,7 +115,6 @@ pub struct NotificationCenter {
114
115
hover_hold: bool,
115
116
unread_mentions: HashSet<String>,
116
117
tray: Option<Tray>,
117
tray_do_not_disturb: bool,
118
118
#[cfg(target_os = "linux")]
119
119
desktop: Option<DesktopNotifications>,
120
120
#[cfg(target_os = "linux")]
@@ -123,6 +123,7 @@ pub struct NotificationCenter {
123
123
desktop_published: HashSet<String>,
124
124
#[cfg(target_os = "linux")]
125
125
desktop_avatar_cache: HashMap<String, (u64, NotificationImage)>,
126
last_tray_presence: Option<TrayPresence>,
126
127
app_icon: AppIcon,
127
128
shown_badge: Option<Badge>,
128
129
shown_mention_dot: bool,
@@ -147,22 +148,22 @@ impl NotificationCenter {
147
148
let mut settings = settings::load(&app.read(cx).store);
148
149
settings.account = app.read(cx).account_chat_settings().notifications;
149
150
let app_icon = active_appearance::current(cx).app_icon;
150
let tray_do_not_disturb = own_do_not_disturb(app.read(cx));
151
let initial_presence = tray_presence_from(&app.read(cx), false);
151
152
let tray = if app.read(cx).mode.demo {
152
153
None
153
154
} else {
154
Tray::new(
155
settings.sounds.notification_sound,
156
tray_do_not_disturb,
157
app_icon.png(),
158
)
155
Tray::new(initial_presence.clone(), app_icon.png())
159
156
};
157
let last_tray_presence = tray.as_ref().map(|_| initial_presence);
160
158
platform::set_window_icon(window, app_icon.png());
161
159
let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {
162
160
this.apply_app_icon(active_appearance::current(cx).app_icon, cx)
163
161
});
164
let locale_observation = cx.observe_global::<ActiveLocale>(|this, _| {
162
let locale_observation = cx.observe_global::<ActiveLocale>(|this, cx| {
163
// Locale changes the presence title; force a tray sync.
164
this.last_tray_presence = None;
165
165
this.relocalize_tray();
166
this.sync_tray(cx);
166
167
});
167
168
let subscription = cx.subscribe(&app, |this, _, event: &AppEvent, cx| {
168
169
this.on_app_event(event, cx);
@@ -205,7 +206,6 @@ impl NotificationCenter {
205
206
hover_hold: false,
206
207
unread_mentions: HashSet::new(),
207
208
tray,
208
tray_do_not_disturb,
209
209
#[cfg(target_os = "linux")]
210
210
desktop: if app.read(cx).mode.demo {
211
211
None
@@ -218,6 +218,7 @@ impl NotificationCenter {
218
218
desktop_published: HashSet::new(),
219
219
#[cfg(target_os = "linux")]
220
220
desktop_avatar_cache: HashMap::new(),
221
last_tray_presence,
221
222
app_icon,
222
223
shown_badge: None,
223
224
shown_mention_dot: false,
@@ -452,7 +453,7 @@ impl NotificationCenter {
452
453
AppEvent::Messages(conversation_id) => self.on_messages(conversation_id, cx),
453
454
AppEvent::Selection => self.on_selection(cx),
454
455
AppEvent::Sidebar => self.refresh_badge(cx),
455
AppEvent::Directory | AppEvent::Status => self.sync_tray_presence(cx),
456
AppEvent::Directory | AppEvent::Status => self.sync_tray(cx),
456
457
AppEvent::Ring => self.on_rings_changed(cx),
457
458
AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
458
459
AppEvent::MeetingChime => self.on_meeting_chime(cx),
@@ -1482,11 +1483,40 @@ impl NotificationCenter {
1482
1483
match command {
1483
1484
TrayCommand::Toggle => self.toggle_main_window(cx),
1484
1485
TrayCommand::Open => self.raise_main_window(cx),
1485
TrayCommand::ToggleSound => self.update_settings(cx, |settings| {
1486
settings.sounds.notification_sound = !settings.sounds.notification_sound
1487
}),
1488
TrayCommand::ToggleDoNotDisturb => self.toggle_own_do_not_disturb(cx),
1489
TrayCommand::Settings => {
1486
TrayCommand::SetStatus(kind) => {
1487
let forced = ForcedAvailability {
1488
kind,
1489
expires_at: None,
1490
};
1491
self.app
1492
.update(cx, |state, cx| state.set_own_availability(Some(forced), cx));
1493
self.sync_tray(cx);
1494
}
1495
TrayCommand::SetStatusDuration(duration) => {
1496
let Some(kind) = self
1497
.app
1498
.read(cx)
1499
.own_status
1500
.forced
1501
.map(|forced| forced.kind)
1502
.filter(|kind| *kind != ForcedKind::Available)
1503
else {
1504
continue;
1505
};
1506
let forced = ForcedAvailability {
1507
kind,
1508
expires_at: Some(duration.expires_at(Local::now())),
1509
};
1510
self.app
1511
.update(cx, |state, cx| state.set_own_availability(Some(forced), cx));
1512
self.sync_tray(cx);
1513
}
1514
TrayCommand::ResetStatus => {
1515
self.app
1516
.update(cx, |state, cx| state.set_own_availability(None, cx));
1517
self.sync_tray(cx);
1518
}
1519
TrayCommand::Notifications => {
1490
1520
self.raise_main_window(cx);
1491
1521
self.app.update(cx, |state, cx| {
1492
1522
state.open_settings(SettingsSection::Notifications, cx)
@@ -1497,22 +1527,6 @@ impl NotificationCenter {
1497
1527
}
1498
1528
}
1499
1529
1500
fn toggle_own_do_not_disturb(&mut self, cx: &mut Context<Self>) {
1501
let forced = (!own_do_not_disturb(self.app.read(cx))).then_some(ForcedAvailability {
1502
kind: ForcedKind::DoNotDisturb,
1503
expires_at: None,
1504
});
1505
self.app
1506
.update(cx, |state, cx| state.set_own_availability(forced, cx));
1507
self.sync_tray(cx);
1508
}
1509
1510
fn sync_tray_presence(&mut self, cx: &App) {
1511
if self.tray_do_not_disturb != own_do_not_disturb(self.app.read(cx)) {
1512
self.sync_tray(cx);
1513
}
1514
}
1515
1516
1530
fn toggle_main_window(&mut self, cx: &mut Context<Self>) {
1517
1531
if self.main_window_active(cx) {
1518
1532
if let Some(native) = self.main_native {
@@ -1570,14 +1584,15 @@ impl NotificationCenter {
1570
1584
}
1571
1585
1572
1586
fn sync_tray(&mut self, cx: &App) {
1573
self.tray_do_not_disturb = own_do_not_disturb(self.app.read(cx));
1574
if let Some(tray) = &self.tray {
1575
tray.sync(
1576
self.settings.sounds.notification_sound,
1577
self.tray_do_not_disturb,
1578
!self.unread_mentions.is_empty(),
1579
);
1587
let Some(tray) = &self.tray else {
1588
return;
1589
};
1590
let presence = tray_presence_from(self.app.read(cx), !self.unread_mentions.is_empty());
1591
if self.last_tray_presence.as_ref() == Some(&presence) {
1592
return;
1580
1593
}
1594
tray.sync(presence.clone());
1595
self.last_tray_presence = Some(presence);
1581
1596
}
1582
1597
1583
1598
fn refresh_badge(&mut self, cx: &mut Context<Self>) {
@@ -1853,6 +1868,19 @@ fn own_do_not_disturb(state: &AppState) -> bool {
1853
1868
own_presence(state) == PresenceKind::DoNotDisturb
1854
1869
}
1855
1870
1871
fn tray_presence_from(state: &AppState, mention: bool) -> TrayPresence {
1872
let summary = own_status::state_summary(&state.own_status, own_presence(state), &Local::now());
1873
let title = match &summary.until {
1874
Some(until) => format!("{} {until}", summary.label),
1875
None => summary.label.to_owned(),
1876
};
1877
TrayPresence::new(
1878
title,
1879
state.own_status.forced.map(|forced| forced.kind),
1880
mention,
1881
)
1882
}
1883
1856
1884
fn sync_loop(handle: &mut Option<SoundHandle>, audible: bool, tone: CallTone, cx: &App) {
1857
1885
match (audible, handle.is_some()) {
1858
1886
(true, false) => *handle = Some(sound_cache::start(tone.file_name(), true, cx)),
@@ -15,7 +15,7 @@ use super::desktop_payload::{15
use super::incoming::IncomingTracker;15
use super::incoming::IncomingTracker;16
use super::layout::{self, MEETING_HEIGHT, Slot, ring_height};16
use super::layout::{self, MEETING_HEIGHT, Slot, ring_height};17
use super::meeting_view::MeetingToastView;17
use super::meeting_view::MeetingToastView;18
use super::platform::{self, NativeHandle, Tray, TrayCommand, WorkArea};18
use super::platform::{self, NativeHandle, Tray, TrayCommand, TrayPresence, WorkArea};19
#[cfg(target_os = "linux")]19
#[cfg(target_os = "linux")]20
use super::platform::{20
use super::platform::{21
BusNotification, DesktopNotifications, NotificationEvent, NotificationImage,21
BusNotification, DesktopNotifications, NotificationEvent, NotificationImage,@@ -47,6 +47,7 @@ use crate::appearance::AppIcon;47
use crate::autostart::{self, StartupSettings};47
use crate::autostart::{self, StartupSettings};48
use crate::call::DemoScene;48
use crate::call::DemoScene;49
use crate::data::{self, Directory, PresenceKind};49
use crate::data::{self, Directory, PresenceKind};50
use crate::own_status;50
use crate::runtime;51
use crate::runtime;51
use crate::settings_section::SettingsSection;52
use crate::settings_section::SettingsSection;52
use crate::single_instance;53
use crate::single_instance;@@ -114,7 +115,6 @@ pub struct NotificationCenter {114
hover_hold: bool,115
hover_hold: bool,115
unread_mentions: HashSet<String>,116
unread_mentions: HashSet<String>,116
tray: Option<Tray>,117
tray: Option<Tray>,117
tray_do_not_disturb: bool,118
#[cfg(target_os = "linux")]118
#[cfg(target_os = "linux")]119
desktop: Option<DesktopNotifications>,119
desktop: Option<DesktopNotifications>,120
#[cfg(target_os = "linux")]120
#[cfg(target_os = "linux")]@@ -123,6 +123,7 @@ pub struct NotificationCenter {123
desktop_published: HashSet<String>,123
desktop_published: HashSet<String>,124
#[cfg(target_os = "linux")]124
#[cfg(target_os = "linux")]125
desktop_avatar_cache: HashMap<String, (u64, NotificationImage)>,125
desktop_avatar_cache: HashMap<String, (u64, NotificationImage)>,126
last_tray_presence: Option<TrayPresence>,126
app_icon: AppIcon,127
app_icon: AppIcon,127
shown_badge: Option<Badge>,128
shown_badge: Option<Badge>,128
shown_mention_dot: bool,129
shown_mention_dot: bool,@@ -147,22 +148,22 @@ impl NotificationCenter {147
let mut settings = settings::load(&app.read(cx).store);148
let mut settings = settings::load(&app.read(cx).store);148
settings.account = app.read(cx).account_chat_settings().notifications;149
settings.account = app.read(cx).account_chat_settings().notifications;149
let app_icon = active_appearance::current(cx).app_icon;150
let app_icon = active_appearance::current(cx).app_icon;150
let tray_do_not_disturb = own_do_not_disturb(app.read(cx));151
let initial_presence = tray_presence_from(&app.read(cx), false);151
let tray = if app.read(cx).mode.demo {152
let tray = if app.read(cx).mode.demo {152
None153
None153
} else {154
} else {154
Tray::new(155
Tray::new(initial_presence.clone(), app_icon.png())155
settings.sounds.notification_sound,156
tray_do_not_disturb,157
app_icon.png(),158
)159
};156
};157
let last_tray_presence = tray.as_ref().map(|_| initial_presence);160
platform::set_window_icon(window, app_icon.png());158
platform::set_window_icon(window, app_icon.png());161
let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {159
let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {162
this.apply_app_icon(active_appearance::current(cx).app_icon, cx)160
this.apply_app_icon(active_appearance::current(cx).app_icon, cx)163
});161
});164
let locale_observation = cx.observe_global::<ActiveLocale>(|this, _| {162
let locale_observation = cx.observe_global::<ActiveLocale>(|this, cx| {163
// Locale changes the presence title; force a tray sync.164
this.last_tray_presence = None;165
this.relocalize_tray();165
this.relocalize_tray();166
this.sync_tray(cx);166
});167
});167
let subscription = cx.subscribe(&app, |this, _, event: &AppEvent, cx| {168
let subscription = cx.subscribe(&app, |this, _, event: &AppEvent, cx| {168
this.on_app_event(event, cx);169
this.on_app_event(event, cx);@@ -205,7 +206,6 @@ impl NotificationCenter {205
hover_hold: false,206
hover_hold: false,206
unread_mentions: HashSet::new(),207
unread_mentions: HashSet::new(),207
tray,208
tray,208
tray_do_not_disturb,209
#[cfg(target_os = "linux")]209
#[cfg(target_os = "linux")]210
desktop: if app.read(cx).mode.demo {210
desktop: if app.read(cx).mode.demo {211
None211
None@@ -218,6 +218,7 @@ impl NotificationCenter {218
desktop_published: HashSet::new(),218
desktop_published: HashSet::new(),219
#[cfg(target_os = "linux")]219
#[cfg(target_os = "linux")]220
desktop_avatar_cache: HashMap::new(),220
desktop_avatar_cache: HashMap::new(),221
last_tray_presence,221
app_icon,222
app_icon,222
shown_badge: None,223
shown_badge: None,223
shown_mention_dot: false,224
shown_mention_dot: false,@@ -452,7 +453,7 @@ impl NotificationCenter {452
AppEvent::Messages(conversation_id) => self.on_messages(conversation_id, cx),453
AppEvent::Messages(conversation_id) => self.on_messages(conversation_id, cx),453
AppEvent::Selection => self.on_selection(cx),454
AppEvent::Selection => self.on_selection(cx),454
AppEvent::Sidebar => self.refresh_badge(cx),455
AppEvent::Sidebar => self.refresh_badge(cx),455
AppEvent::Directory | AppEvent::Status => self.sync_tray_presence(cx),456
AppEvent::Directory | AppEvent::Status => self.sync_tray(cx),456
AppEvent::Ring => self.on_rings_changed(cx),457
AppEvent::Ring => self.on_rings_changed(cx),457
AppEvent::MeetingReminder => self.on_meeting_reminder(cx),458
AppEvent::MeetingReminder => self.on_meeting_reminder(cx),458
AppEvent::MeetingChime => self.on_meeting_chime(cx),459
AppEvent::MeetingChime => self.on_meeting_chime(cx),@@ -1482,11 +1483,40 @@ impl NotificationCenter {1482
match command {1483
match command {1483
TrayCommand::Toggle => self.toggle_main_window(cx),1484
TrayCommand::Toggle => self.toggle_main_window(cx),1484
TrayCommand::Open => self.raise_main_window(cx),1485
TrayCommand::Open => self.raise_main_window(cx),1485
TrayCommand::ToggleSound => self.update_settings(cx, |settings| {1486
TrayCommand::SetStatus(kind) => {1486
settings.sounds.notification_sound = !settings.sounds.notification_sound1487
let forced = ForcedAvailability {1487
}),1488
kind,1488
TrayCommand::ToggleDoNotDisturb => self.toggle_own_do_not_disturb(cx),1489
expires_at: None,1489
TrayCommand::Settings => {1490
};1491
self.app1492
.update(cx, |state, cx| state.set_own_availability(Some(forced), cx));1493
self.sync_tray(cx);1494
}1495
TrayCommand::SetStatusDuration(duration) => {1496
let Some(kind) = self1497
.app1498
.read(cx)1499
.own_status1500
.forced1501
.map(|forced| forced.kind)1502
.filter(|kind| *kind != ForcedKind::Available)1503
else {1504
continue;1505
};1506
let forced = ForcedAvailability {1507
kind,1508
expires_at: Some(duration.expires_at(Local::now())),1509
};1510
self.app1511
.update(cx, |state, cx| state.set_own_availability(Some(forced), cx));1512
self.sync_tray(cx);1513
}1514
TrayCommand::ResetStatus => {1515
self.app1516
.update(cx, |state, cx| state.set_own_availability(None, cx));1517
self.sync_tray(cx);1518
}1519
TrayCommand::Notifications => {1490
self.raise_main_window(cx);1520
self.raise_main_window(cx);1491
self.app.update(cx, |state, cx| {1521
self.app.update(cx, |state, cx| {1492
state.open_settings(SettingsSection::Notifications, cx)1522
state.open_settings(SettingsSection::Notifications, cx)@@ -1497,22 +1527,6 @@ impl NotificationCenter {1497
}1527
}1498
}1528
}1499
1529
1500
fn toggle_own_do_not_disturb(&mut self, cx: &mut Context<Self>) {1501
let forced = (!own_do_not_disturb(self.app.read(cx))).then_some(ForcedAvailability {1502
kind: ForcedKind::DoNotDisturb,1503
expires_at: None,1504
});1505
self.app1506
.update(cx, |state, cx| state.set_own_availability(forced, cx));1507
self.sync_tray(cx);1508
}1509
1510
fn sync_tray_presence(&mut self, cx: &App) {1511
if self.tray_do_not_disturb != own_do_not_disturb(self.app.read(cx)) {1512
self.sync_tray(cx);1513
}1514
}1515
1516
fn toggle_main_window(&mut self, cx: &mut Context<Self>) {1530
fn toggle_main_window(&mut self, cx: &mut Context<Self>) {1517
if self.main_window_active(cx) {1531
if self.main_window_active(cx) {1518
if let Some(native) = self.main_native {1532
if let Some(native) = self.main_native {@@ -1570,14 +1584,15 @@ impl NotificationCenter {1570
}1584
}1571
1585
1572
fn sync_tray(&mut self, cx: &App) {1586
fn sync_tray(&mut self, cx: &App) {1573
self.tray_do_not_disturb = own_do_not_disturb(self.app.read(cx));1587
let Some(tray) = &self.tray else {1574
if let Some(tray) = &self.tray {1588
return;1575
tray.sync(1589
};1576
self.settings.sounds.notification_sound,1590
let presence = tray_presence_from(self.app.read(cx), !self.unread_mentions.is_empty());1577
self.tray_do_not_disturb,1591
if self.last_tray_presence.as_ref() == Some(&presence) {1578
!self.unread_mentions.is_empty(),1592
return;1579
);1580
}1593
}1594
tray.sync(presence.clone());1595
self.last_tray_presence = Some(presence);1581
}1596
}1582
1597
1583
fn refresh_badge(&mut self, cx: &mut Context<Self>) {1598
fn refresh_badge(&mut self, cx: &mut Context<Self>) {@@ -1853,6 +1868,19 @@ fn own_do_not_disturb(state: &AppState) -> bool {1853
own_presence(state) == PresenceKind::DoNotDisturb1868
own_presence(state) == PresenceKind::DoNotDisturb1854
}1869
}1855
1870
1871
fn tray_presence_from(state: &AppState, mention: bool) -> TrayPresence {1872
let summary = own_status::state_summary(&state.own_status, own_presence(state), &Local::now());1873
let title = match &summary.until {1874
Some(until) => format!("{} {until}", summary.label),1875
None => summary.label.to_owned(),1876
};1877
TrayPresence::new(1878
title,1879
state.own_status.forced.map(|forced| forced.kind),1880
mention,1881
)1882
}1883
1856
fn sync_loop(handle: &mut Option<SoundHandle>, audible: bool, tone: CallTone, cx: &App) {1884
fn sync_loop(handle: &mut Option<SoundHandle>, audible: bool, tone: CallTone, cx: &App) {1857
match (audible, handle.is_some()) {1885
match (audible, handle.is_some()) {1858
(true, false) => *handle = Some(sound_cache::start(tone.file_name(), true, cx)),1886
(true, false) => *handle = Some(sound_cache::start(tone.file_name(), true, cx)),