feat(notify): red taskbar badge and flash until focus like Teams
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -128,7 +128,7 @@ Feature parity with the Microsoft Teams desktop client.
128
128
|---|---|---|
129
129
| Desktop toast, click opens the chat at the message | Done | |
130
130
| Reply and Mark as read in the toast | Done | |
131
| Sound, taskbar badge, flash on mention | Done | |
131
| Sound, red taskbar badge, taskbar flash on new messages | Done | |
132
132
| Quiet during Do not disturb, Focus Assist, calls | Done | |
133
133
| Mentions-only mode, preview off | Done | |
134
134
| Stack of 3, queue, Hide all, fade-out | Done | |
@@ -128,7 +128,7 @@ Feature parity with the Microsoft Teams desktop client.128
|---|---|---|128
|---|---|---|129
| Desktop toast, click opens the chat at the message | Done | |129
| Desktop toast, click opens the chat at the message | Done | |130
| Reply and Mark as read in the toast | Done | |130
| Reply and Mark as read in the toast | Done | |131
| Sound, taskbar badge, flash on mention | Done | |131
| Sound, red taskbar badge, taskbar flash on new messages | Done | |132
| Quiet during Do not disturb, Focus Assist, calls | Done | |132
| Quiet during Do not disturb, Focus Assist, calls | Done | |133
| Mentions-only mode, preview off | Done | |133
| Mentions-only mode, preview off | Done | |134
| Stack of 3, queue, Hide all, fade-out | Done | |134
| Stack of 3, queue, Hide all, fade-out | Done | |@@ -3,17 +3,15 @@ const GLYPH_WIDTH: usize = 5;
3
3
const GLYPH_HEIGHT: usize = 7;
4
4
const GLYPH_SCALE: usize = 2;
5
5
const GLYPH_GAP: usize = 1;
6
const NEUTRAL: [u8; 3] = [0xf4, 0xf4, 0xf5];
7
const MENTION: [u8; 3] = [0xef, 0x44, 0x44];
6
const RED: [u8; 3] = [0xef, 0x44, 0x44];
8
7
const INK: [u8; 3] = [0x0a, 0x0a, 0x0a];
9
8
10
9
#[derive(Debug, Clone, PartialEq, Eq)]
11
10
pub struct Badge {
12
11
pub text: String,
13
pub mention: bool,
14
12
}
15
13
16
pub fn badge_for(unread_chats: usize, unread_mention: bool) -> Option<Badge> {
14
pub fn badge_for(unread_chats: usize) -> Option<Badge> {
17
15
if unread_chats == 0 {
18
16
return None;
19
17
}
@@ -22,10 +20,7 @@ pub fn badge_for(unread_chats: usize, unread_mention: bool) -> Option<Badge> {
22
20
} else {
23
21
unread_chats.to_string()
24
22
};
25
Some(Badge {
26
text,
27
mention: unread_mention,
28
})
23
Some(Badge { text })
29
24
}
30
25
31
26
const GLYPHS: [[u8; GLYPH_HEIGHT]; 11] = [
@@ -60,7 +55,6 @@ pub fn text_width(text: &str) -> usize {
60
55
61
56
/// BGRA, premultiplied, top-down, `BADGE_SIZE` square.
62
57
pub fn render_badge(badge: &Badge) -> Vec<u8> {
63
let fill = if badge.mention { MENTION } else { NEUTRAL };
64
58
let mut pixels = vec![0u8; BADGE_SIZE * BADGE_SIZE * 4];
65
59
let center = (BADGE_SIZE as f32 - 1.) / 2.;
66
60
let radius = BADGE_SIZE as f32 / 2.;
@@ -68,7 +62,7 @@ pub fn render_badge(badge: &Badge) -> Vec<u8> {
68
62
for column in 0..BADGE_SIZE {
69
63
let distance = ((column as f32 - center).powi(2) + (row as f32 - center).powi(2)).sqrt();
70
64
if distance <= radius - 0.5 {
71
put(&mut pixels, column, row, fill);
65
put(&mut pixels, column, row, RED);
72
66
}
73
67
}
74
68
}
@@ -115,26 +109,20 @@ mod tests {
115
109
116
110
#[test]
117
111
fn no_unread_means_no_badge() {
118
assert_eq!(badge_for(0, true), None);
112
assert_eq!(badge_for(0), None);
119
113
}
120
114
121
115
#[test]
122
116
fn counts_chats_and_caps_at_nine_plus() {
123
assert_eq!(badge_for(3, false).unwrap().text, "3");
124
assert_eq!(badge_for(9, false).unwrap().text, "9");
125
assert_eq!(badge_for(10, false).unwrap().text, "9+");
126
assert_eq!(badge_for(250, false).unwrap().text, "9+");
127
}
128
129
#[test]
130
fn mention_turns_badge_red() {
131
assert!(badge_for(1, true).unwrap().mention);
132
assert!(!badge_for(1, false).unwrap().mention);
117
assert_eq!(badge_for(3).unwrap().text, "3");
118
assert_eq!(badge_for(9).unwrap().text, "9");
119
assert_eq!(badge_for(10).unwrap().text, "9+");
120
assert_eq!(badge_for(250).unwrap().text, "9+");
133
121
}
134
122
135
123
#[test]
136
124
fn rendered_badge_has_fill_ink_and_transparent_corner() {
137
let badge = badge_for(3, true).unwrap();
125
let badge = badge_for(3).unwrap();
138
126
let pixels = render_badge(&badge);
139
127
assert_eq!(pixels.len(), BADGE_SIZE * BADGE_SIZE * 4);
140
128
assert_eq!(pixels[3], 0);
@@ -3,17 +3,15 @@ const GLYPH_WIDTH: usize = 5;3
const GLYPH_HEIGHT: usize = 7;3
const GLYPH_HEIGHT: usize = 7;4
const GLYPH_SCALE: usize = 2;4
const GLYPH_SCALE: usize = 2;5
const GLYPH_GAP: usize = 1;5
const GLYPH_GAP: usize = 1;6
const NEUTRAL: [u8; 3] = [0xf4, 0xf4, 0xf5];6
const RED: [u8; 3] = [0xef, 0x44, 0x44];7
const MENTION: [u8; 3] = [0xef, 0x44, 0x44];8
const INK: [u8; 3] = [0x0a, 0x0a, 0x0a];7
const INK: [u8; 3] = [0x0a, 0x0a, 0x0a];9
8
10
#[derive(Debug, Clone, PartialEq, Eq)]9
#[derive(Debug, Clone, PartialEq, Eq)]11
pub struct Badge {10
pub struct Badge {12
pub text: String,11
pub text: String,13
pub mention: bool,14
}12
}15
13
16
pub fn badge_for(unread_chats: usize, unread_mention: bool) -> Option<Badge> {14
pub fn badge_for(unread_chats: usize) -> Option<Badge> {17
if unread_chats == 0 {15
if unread_chats == 0 {18
return None;16
return None;19
}17
}@@ -22,10 +20,7 @@ pub fn badge_for(unread_chats: usize, unread_mention: bool) -> Option<Badge> {22
} else {20
} else {23
unread_chats.to_string()21
unread_chats.to_string()24
};22
};25
Some(Badge {23
Some(Badge { text })26
text,27
mention: unread_mention,28
})29
}24
}30
25
31
const GLYPHS: [[u8; GLYPH_HEIGHT]; 11] = [26
const GLYPHS: [[u8; GLYPH_HEIGHT]; 11] = [@@ -60,7 +55,6 @@ pub fn text_width(text: &str) -> usize {60
55
61
/// BGRA, premultiplied, top-down, `BADGE_SIZE` square.56
/// BGRA, premultiplied, top-down, `BADGE_SIZE` square.62
pub fn render_badge(badge: &Badge) -> Vec<u8> {57
pub fn render_badge(badge: &Badge) -> Vec<u8> {63
let fill = if badge.mention { MENTION } else { NEUTRAL };64
let mut pixels = vec![0u8; BADGE_SIZE * BADGE_SIZE * 4];58
let mut pixels = vec![0u8; BADGE_SIZE * BADGE_SIZE * 4];65
let center = (BADGE_SIZE as f32 - 1.) / 2.;59
let center = (BADGE_SIZE as f32 - 1.) / 2.;66
let radius = BADGE_SIZE as f32 / 2.;60
let radius = BADGE_SIZE as f32 / 2.;@@ -68,7 +62,7 @@ pub fn render_badge(badge: &Badge) -> Vec<u8> {68
for column in 0..BADGE_SIZE {62
for column in 0..BADGE_SIZE {69
let distance = ((column as f32 - center).powi(2) + (row as f32 - center).powi(2)).sqrt();63
let distance = ((column as f32 - center).powi(2) + (row as f32 - center).powi(2)).sqrt();70
if distance <= radius - 0.5 {64
if distance <= radius - 0.5 {71
put(&mut pixels, column, row, fill);65
put(&mut pixels, column, row, RED);72
}66
}73
}67
}74
}68
}@@ -115,26 +109,20 @@ mod tests {115
109
116
#[test]110
#[test]117
fn no_unread_means_no_badge() {111
fn no_unread_means_no_badge() {118
assert_eq!(badge_for(0, true), None);112
assert_eq!(badge_for(0), None);119
}113
}120
114
121
#[test]115
#[test]122
fn counts_chats_and_caps_at_nine_plus() {116
fn counts_chats_and_caps_at_nine_plus() {123
assert_eq!(badge_for(3, false).unwrap().text, "3");117
assert_eq!(badge_for(3).unwrap().text, "3");124
assert_eq!(badge_for(9, false).unwrap().text, "9");118
assert_eq!(badge_for(9).unwrap().text, "9");125
assert_eq!(badge_for(10, false).unwrap().text, "9+");119
assert_eq!(badge_for(10).unwrap().text, "9+");126
assert_eq!(badge_for(250, false).unwrap().text, "9+");120
assert_eq!(badge_for(250).unwrap().text, "9+");127
}128
129
#[test]130
fn mention_turns_badge_red() {131
assert!(badge_for(1, true).unwrap().mention);132
assert!(!badge_for(1, false).unwrap().mention);133
}121
}134
122
135
#[test]123
#[test]136
fn rendered_badge_has_fill_ink_and_transparent_corner() {124
fn rendered_badge_has_fill_ink_and_transparent_corner() {137
let badge = badge_for(3, true).unwrap();125
let badge = badge_for(3).unwrap();138
let pixels = render_badge(&badge);126
let pixels = render_badge(&badge);139
assert_eq!(pixels.len(), BADGE_SIZE * BADGE_SIZE * 4);127
assert_eq!(pixels.len(), BADGE_SIZE * BADGE_SIZE * 4);140
assert_eq!(pixels[3], 0);128
assert_eq!(pixels[3], 0);@@ -243,7 +243,7 @@ impl NotificationCenter {
243
243
self.present(&incoming, decision, cx);
244
244
if should_flash(
245
245
&self.settings,
246
incoming.mentions_me && decision.toast,
246
decision.toast,
247
247
self.main_window_active(cx),
248
248
) && let Some(native) = self.main_native
249
249
{
@@ -519,7 +519,7 @@ impl NotificationCenter {
519
519
let (count, still_unread) = unread_summary(&self.app.read(cx).sidebar);
520
520
self.unread_mentions
521
521
.retain(|conversation_id| still_unread.contains(conversation_id));
522
let badge = badge_for(count, !self.unread_mentions.is_empty());
522
let badge = badge_for(count);
523
523
if badge == self.shown_badge {
524
524
return;
525
525
}
@@ -243,7 +243,7 @@ impl NotificationCenter {243
self.present(&incoming, decision, cx);243
self.present(&incoming, decision, cx);244
if should_flash(244
if should_flash(245
&self.settings,245
&self.settings,246
incoming.mentions_me && decision.toast,246
decision.toast,247
self.main_window_active(cx),247
self.main_window_active(cx),248
) && let Some(native) = self.main_native248
) && let Some(native) = self.main_native249
{249
{@@ -519,7 +519,7 @@ impl NotificationCenter {519
let (count, still_unread) = unread_summary(&self.app.read(cx).sidebar);519
let (count, still_unread) = unread_summary(&self.app.read(cx).sidebar);520
self.unread_mentions520
self.unread_mentions521
.retain(|conversation_id| still_unread.contains(conversation_id));521
.retain(|conversation_id| still_unread.contains(conversation_id));522
let badge = badge_for(count, !self.unread_mentions.is_empty());522
let badge = badge_for(count);523
if badge == self.shown_badge {523
if badge == self.shown_badge {524
return;524
return;525
}525
}@@ -21,7 +21,7 @@ use windows::Win32::UI::Shell::{
21
21
SHQueryUserNotificationState, TaskbarList,
22
22
};
23
23
use windows::Win32::UI::WindowsAndMessaging::{
24
CreateIconIndirect, DestroyIcon, FLASHW_ALL, FLASHWINFO, FlashWindowEx, GWL_EXSTYLE, GWL_STYLE,
24
CreateIconIndirect, DestroyIcon, FLASHW_TIMERNOFG, FLASHW_TRAY, FLASHWINFO, FlashWindowEx, GWL_EXSTYLE, GWL_STYLE,
25
25
GetWindowLongPtrW, HICON, HWND_TOPMOST, ICONINFO, IsIconic, SW_HIDE, SW_RESTORE, SW_SHOW, SWP_NOACTIVATE,
26
26
SPI_GETCLIENTAREAANIMATION, SWP_FRAMECHANGED, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,
27
27
SWP_NOZORDER, WS_CAPTION, WS_POPUP, WS_THICKFRAME, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow,
@@ -37,7 +37,6 @@ const SOUND_BYTES: &[u8] = include_bytes!("../../../assets/sounds/notification.m
37
37
const TRAY_ICON_PNG: &[u8] = include_bytes!("../../../assets/icon/teams-fast-256.png");
38
38
const TRAY_ICON_SIZE: u32 = 32;
39
39
const TRAY_DOT_RADIUS: f32 = 6.;
40
const FLASH_COUNT: u32 = 3;
41
40
const BASE_DPI: f32 = 96.;
42
41
43
42
fn hwnd(handle: NativeHandle) -> HWND {
@@ -176,8 +175,8 @@ pub fn flash(handle: NativeHandle) {
176
175
let info = FLASHWINFO {
177
176
cbSize: size_of::<FLASHWINFO>() as u32,
178
177
hwnd: hwnd(handle),
179
dwFlags: FLASHW_ALL,
180
uCount: FLASH_COUNT,
178
dwFlags: FLASHW_TRAY | FLASHW_TIMERNOFG,
179
uCount: 0,
181
180
dwTimeout: 0,
182
181
};
183
182
unsafe {
@@ -21,7 +21,7 @@ use windows::Win32::UI::Shell::{21
SHQueryUserNotificationState, TaskbarList,21
SHQueryUserNotificationState, TaskbarList,22
};22
};23
use windows::Win32::UI::WindowsAndMessaging::{23
use windows::Win32::UI::WindowsAndMessaging::{24
CreateIconIndirect, DestroyIcon, FLASHW_ALL, FLASHWINFO, FlashWindowEx, GWL_EXSTYLE, GWL_STYLE,24
CreateIconIndirect, DestroyIcon, FLASHW_TIMERNOFG, FLASHW_TRAY, FLASHWINFO, FlashWindowEx, GWL_EXSTYLE, GWL_STYLE,25
GetWindowLongPtrW, HICON, HWND_TOPMOST, ICONINFO, IsIconic, SW_HIDE, SW_RESTORE, SW_SHOW, SWP_NOACTIVATE,25
GetWindowLongPtrW, HICON, HWND_TOPMOST, ICONINFO, IsIconic, SW_HIDE, SW_RESTORE, SW_SHOW, SWP_NOACTIVATE,26
SPI_GETCLIENTAREAANIMATION, SWP_FRAMECHANGED, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,26
SPI_GETCLIENTAREAANIMATION, SWP_FRAMECHANGED, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,27
SWP_NOZORDER, WS_CAPTION, WS_POPUP, WS_THICKFRAME, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow,27
SWP_NOZORDER, WS_CAPTION, WS_POPUP, WS_THICKFRAME, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow,@@ -37,7 +37,6 @@ const SOUND_BYTES: &[u8] = include_bytes!("../../../assets/sounds/notification.m37
const TRAY_ICON_PNG: &[u8] = include_bytes!("../../../assets/icon/teams-fast-256.png");37
const TRAY_ICON_PNG: &[u8] = include_bytes!("../../../assets/icon/teams-fast-256.png");38
const TRAY_ICON_SIZE: u32 = 32;38
const TRAY_ICON_SIZE: u32 = 32;39
const TRAY_DOT_RADIUS: f32 = 6.;39
const TRAY_DOT_RADIUS: f32 = 6.;40
const FLASH_COUNT: u32 = 3;41
const BASE_DPI: f32 = 96.;40
const BASE_DPI: f32 = 96.;42
41
43
fn hwnd(handle: NativeHandle) -> HWND {42
fn hwnd(handle: NativeHandle) -> HWND {@@ -176,8 +175,8 @@ pub fn flash(handle: NativeHandle) {176
let info = FLASHWINFO {175
let info = FLASHWINFO {177
cbSize: size_of::<FLASHWINFO>() as u32,176
cbSize: size_of::<FLASHWINFO>() as u32,178
hwnd: hwnd(handle),177
hwnd: hwnd(handle),179
dwFlags: FLASHW_ALL,178
dwFlags: FLASHW_TRAY | FLASHW_TIMERNOFG,180
uCount: FLASH_COUNT,179
uCount: 0,181
dwTimeout: 0,180
dwTimeout: 0,182
};181
};183
unsafe {182
unsafe {@@ -169,8 +169,8 @@ impl SoundThrottle {
169
169
}
170
170
}
171
171
172
pub fn should_flash(settings: &Settings, mentions_me: bool, window_active: bool) -> bool {
173
settings.flash && mentions_me && !window_active
172
pub fn should_flash(settings: &Settings, toast_shown: bool, window_active: bool) -> bool {
173
settings.flash && toast_shown && !window_active
174
174
}
175
175
176
176
#[cfg(test)]
@@ -305,7 +305,7 @@ mod tests {
305
305
}
306
306
307
307
#[test]
308
fn flash_needs_mention_inactive_window_and_setting() {
308
fn flash_needs_toast_inactive_window_and_setting() {
309
309
let settings = Settings::default();
310
310
assert!(should_flash(&settings, true, false));
311
311
assert!(!should_flash(&settings, true, true));
@@ -169,8 +169,8 @@ impl SoundThrottle {169
}169
}170
}170
}171
171
172
pub fn should_flash(settings: &Settings, mentions_me: bool, window_active: bool) -> bool {172
pub fn should_flash(settings: &Settings, toast_shown: bool, window_active: bool) -> bool {173
settings.flash && mentions_me && !window_active173
settings.flash && toast_shown && !window_active174
}174
}175
175
176
#[cfg(test)]176
#[cfg(test)]@@ -305,7 +305,7 @@ mod tests {305
}305
}306
306
307
#[test]307
#[test]308
fn flash_needs_mention_inactive_window_and_setting() {308
fn flash_needs_toast_inactive_window_and_setting() {309
let settings = Settings::default();309
let settings = Settings::default();310
assert!(should_flash(&settings, true, false));310
assert!(should_flash(&settings, true, false));311
assert!(!should_flash(&settings, true, true));311
assert!(!should_flash(&settings, true, true));@@ -23,7 +23,7 @@ fn serialize(settings: &Settings) -> String {
23
23
("mentions_only", settings.mentions_only.to_string()),
24
24
("preview", settings.preview.to_string()),
25
25
("corner", settings.corner.key().to_owned()),
26
("flash", settings.flash.to_string()),
26
("taskbar_flash", settings.flash.to_string()),
27
27
("close_to_tray", settings.close_to_tray.to_string()),
28
28
("do_not_disturb", settings.do_not_disturb.to_string()),
29
29
]
@@ -45,7 +45,7 @@ fn parse(text: &str) -> Settings {
45
45
"mentions_only" => settings.mentions_only = flag,
46
46
"preview" => settings.preview = flag,
47
47
"corner" => settings.corner = Corner::from_key(value).unwrap_or_default(),
48
"flash" => settings.flash = flag,
48
"taskbar_flash" => settings.flash = flag,
49
49
"close_to_tray" => settings.close_to_tray = flag,
50
50
"do_not_disturb" => settings.do_not_disturb = flag,
51
51
_ => {}
@@ -72,6 +72,12 @@ mod tests {
72
72
assert_eq!(parse(&serialize(&settings)), settings);
73
73
}
74
74
75
#[test]
76
fn old_flash_key_is_ignored() {
77
assert!(parse("flash=false").flash);
78
assert!(!parse("taskbar_flash=false").flash);
79
}
80
75
81
#[test]
76
82
fn empty_or_garbage_gives_defaults() {
77
83
assert_eq!(parse(""), Settings::default());
@@ -23,7 +23,7 @@ fn serialize(settings: &Settings) -> String {23
("mentions_only", settings.mentions_only.to_string()),23
("mentions_only", settings.mentions_only.to_string()),24
("preview", settings.preview.to_string()),24
("preview", settings.preview.to_string()),25
("corner", settings.corner.key().to_owned()),25
("corner", settings.corner.key().to_owned()),26
("flash", settings.flash.to_string()),26
("taskbar_flash", settings.flash.to_string()),27
("close_to_tray", settings.close_to_tray.to_string()),27
("close_to_tray", settings.close_to_tray.to_string()),28
("do_not_disturb", settings.do_not_disturb.to_string()),28
("do_not_disturb", settings.do_not_disturb.to_string()),29
]29
]@@ -45,7 +45,7 @@ fn parse(text: &str) -> Settings {45
"mentions_only" => settings.mentions_only = flag,45
"mentions_only" => settings.mentions_only = flag,46
"preview" => settings.preview = flag,46
"preview" => settings.preview = flag,47
"corner" => settings.corner = Corner::from_key(value).unwrap_or_default(),47
"corner" => settings.corner = Corner::from_key(value).unwrap_or_default(),48
"flash" => settings.flash = flag,48
"taskbar_flash" => settings.flash = flag,49
"close_to_tray" => settings.close_to_tray = flag,49
"close_to_tray" => settings.close_to_tray = flag,50
"do_not_disturb" => settings.do_not_disturb = flag,50
"do_not_disturb" => settings.do_not_disturb = flag,51
_ => {}51
_ => {}@@ -72,6 +72,12 @@ mod tests {72
assert_eq!(parse(&serialize(&settings)), settings);72
assert_eq!(parse(&serialize(&settings)), settings);73
}73
}74
74
75
#[test]76
fn old_flash_key_is_ignored() {77
assert!(parse("flash=false").flash);78
assert!(!parse("taskbar_flash=false").flash);79
}80
75
#[test]81
#[test]76
fn empty_or_garbage_gives_defaults() {82
fn empty_or_garbage_gives_defaults() {77
assert_eq!(parse(""), Settings::default());83
assert_eq!(parse(""), Settings::default());@@ -31,7 +31,7 @@ const ROWS: [Row; 5] = [
31
31
},
32
32
Row {
33
33
title: "Flash taskbar",
34
detail: "On mention, when the window is not active",
34
detail: "On new messages, until you open the window",
35
35
field: |settings| &mut settings.flash,
36
36
},
37
37
Row {
@@ -31,7 +31,7 @@ const ROWS: [Row; 5] = [31
},31
},32
Row {32
Row {33
title: "Flash taskbar",33
title: "Flash taskbar",34
detail: "On mention, when the window is not active",34
detail: "On new messages, until you open the window",35
field: |settings| &mut settings.flash,35
field: |settings| &mut settings.flash,36
},36
},37
Row {37
Row {