BlueGit

ict rusty-teams

fix(notify): white badge digits, stop flashing once everything is read

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-08 · 7 weeks ago

Hash
7f23b00db3f40f46a64b9cc0368b0412cda2e6be
Parent
74e3d6e9
4 files changed +21 −3
crates/app/src/notify/badge.rs +2 −2
@@ -4,7 +4,7 @@ const GLYPH_HEIGHT: usize = 7;
4 4 const GLYPH_SCALE: usize = 2;
5 5 const GLYPH_GAP: usize = 1;
6 6 const RED: [u8; 3] = [0xef, 0x44, 0x44];
7 const INK: [u8; 3] = [0x0a, 0x0a, 0x0a];
7 const INK: [u8; 3] = [0xff, 0xff, 0xff];
8 8
9 9 #[derive(Debug, Clone, PartialEq, Eq)]
10 10 pub struct Badge {
@@ -132,7 +132,7 @@ mod tests {
132 132 .any(|pixel| pixel == [blue, green, red, 0xff])
133 133 };
134 134 assert!(has(0x44, 0x44, 0xef));
135 assert!(has(0x0a, 0x0a, 0x0a));
135 assert!(has(0xff, 0xff, 0xff));
136 136 }
137 137
138 138 #[test]
@@ -4,7 +4,7 @@ const GLYPH_HEIGHT: usize = 7;
4const GLYPH_SCALE: usize = 2;
4const GLYPH_SCALE: usize = 2;
5const GLYPH_GAP: usize = 1;
5const GLYPH_GAP: usize = 1;
6const RED: [u8; 3] = [0xef, 0x44, 0x44];
6const RED: [u8; 3] = [0xef, 0x44, 0x44];
7const INK: [u8; 3] = [0x0a, 0x0a, 0x0a];
7const INK: [u8; 3] = [0xff, 0xff, 0xff];
8
8
9#[derive(Debug, Clone, PartialEq, Eq)]
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct Badge {
10pub struct Badge {
@@ -132,7 +132,7 @@ mod tests {
132 .any(|pixel| pixel == [blue, green, red, 0xff])
132 .any(|pixel| pixel == [blue, green, red, 0xff])
133 };
133 };
134 assert!(has(0x44, 0x44, 0xef));
134 assert!(has(0x44, 0x44, 0xef));
135 assert!(has(0x0a, 0x0a, 0x0a));
135 assert!(has(0xff, 0xff, 0xff));
136 }
136 }
137
137
138 #[test]
138 #[test]
crates/app/src/notify/center.rs +3 −0
@@ -525,6 +525,9 @@ impl NotificationCenter {
525 525 }
526 526 if let Some(native) = self.main_native {
527 527 platform::set_badge(native, badge.as_ref());
528 if badge.is_none() && self.shown_badge.is_some() {
529 platform::stop_flash(native);
530 }
528 531 }
529 532 self.shown_badge = badge;
530 533 self.sync_tray();
@@ -525,6 +525,9 @@ impl NotificationCenter {
525 }
525 }
526 if let Some(native) = self.main_native {
526 if let Some(native) = self.main_native {
527 platform::set_badge(native, badge.as_ref());
527 platform::set_badge(native, badge.as_ref());
528 if badge.is_none() && self.shown_badge.is_some() {
529 platform::stop_flash(native);
530 }
528 }
531 }
529 self.shown_badge = badge;
532 self.shown_badge = badge;
530 self.sync_tray();
533 self.sync_tray();
crates/app/src/notify/platform/stub.rs +2 −0
@@ -27,6 +27,8 @@ pub fn hide_window(_handle: NativeHandle) {}
27 27
28 28 pub fn flash(_handle: NativeHandle) {}
29 29
30 pub fn stop_flash(_handle: NativeHandle) {}
31
30 32 pub fn set_badge(_handle: NativeHandle, _badge: Option<&Badge>) {}
31 33
32 34 pub fn play_sound() {}
@@ -27,6 +27,8 @@ pub fn hide_window(_handle: NativeHandle) {}
27
27
28pub fn flash(_handle: NativeHandle) {}
28pub fn flash(_handle: NativeHandle) {}
29
29
30pub fn stop_flash(_handle: NativeHandle) {}
31
30pub fn set_badge(_handle: NativeHandle, _badge: Option<&Badge>) {}
32pub fn set_badge(_handle: NativeHandle, _badge: Option<&Badge>) {}
31
33
32pub fn play_sound() {}
34pub fn play_sound() {}
crates/app/src/notify/platform/windows_impl.rs +14 −1
@@ -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_TIMERNOFG, FLASHW_TRAY, FLASHWINFO, FlashWindowEx, GWL_EXSTYLE, GWL_STYLE,
24 CreateIconIndirect, DestroyIcon, FLASHW_STOP, 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,
@@ -184,6 +184,19 @@ pub fn flash(handle: NativeHandle) {
184 184 }
185 185 }
186 186
187 pub fn stop_flash(handle: NativeHandle) {
188 let info = FLASHWINFO {
189 cbSize: size_of::<FLASHWINFO>() as u32,
190 hwnd: hwnd(handle),
191 dwFlags: FLASHW_STOP,
192 uCount: 0,
193 dwTimeout: 0,
194 };
195 unsafe {
196 let _ = FlashWindowEx(&info);
197 }
198 }
199
187 200 pub fn set_badge(handle: NativeHandle, badge: Option<&Badge>) {
188 201 unsafe {
189 202 let Ok(taskbar) = CoCreateInstance::<_, ITaskbarList3>(&TaskbarList, None, CLSCTX_INPROC_SERVER)
@@ -21,7 +21,7 @@ use windows::Win32::UI::Shell::{
21 SHQueryUserNotificationState, TaskbarList,
21 SHQueryUserNotificationState, TaskbarList,
22};
22};
23use windows::Win32::UI::WindowsAndMessaging::{
23use windows::Win32::UI::WindowsAndMessaging::{
24 CreateIconIndirect, DestroyIcon, FLASHW_TIMERNOFG, FLASHW_TRAY, FLASHWINFO, FlashWindowEx, GWL_EXSTYLE, GWL_STYLE,
24 CreateIconIndirect, DestroyIcon, FLASHW_STOP, 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,
@@ -184,6 +184,19 @@ pub fn flash(handle: NativeHandle) {
184 }
184 }
185}
185}
186
186
187pub fn stop_flash(handle: NativeHandle) {
188 let info = FLASHWINFO {
189 cbSize: size_of::<FLASHWINFO>() as u32,
190 hwnd: hwnd(handle),
191 dwFlags: FLASHW_STOP,
192 uCount: 0,
193 dwTimeout: 0,
194 };
195 unsafe {
196 let _ = FlashWindowEx(&info);
197 }
198}
199
187pub fn set_badge(handle: NativeHandle, badge: Option<&Badge>) {
200pub fn set_badge(handle: NativeHandle, badge: Option<&Badge>) {
188 unsafe {
201 unsafe {
189 let Ok(taskbar) = CoCreateInstance::<_, ITaskbarList3>(&TaskbarList, None, CLSCTX_INPROC_SERVER)
202 let Ok(taskbar) = CoCreateInstance::<_, ITaskbarList3>(&TaskbarList, None, CLSCTX_INPROC_SERVER)