app: show a red tray icon while recording

The tray kept the app's medallion while the daemon recorded, so the
notification area said nothing about it. The icon now becomes a plain
red disc, set with the menu whenever the recording state changes. The
state comes from the daemon's status, so a recording started from
another program shows too.

Rune's tray could only replace its menu and tooltip, so the vendored
rune takes Tray::set_icon: Windows rebuilds the HICON and sends
NIM_MODIFY, Linux swaps IconPixmap and emits NewIcon.
This commit is contained in:
vhaudiquet committed 2026-11-23 18:44:12 +01:00
1 parent 9e4349fe42
commit 5377d88ca6
5 files changed
+107 -26

No files matched your search

+2 -1
View File
@@ -657,7 +657,7 @@ pub fn setup(app: &mut App, waker: rune::Waker) {
}
let (tx, rx) = channel::<rune::TrayEvent>();
let spec = rune::TraySpec::new(os::APP_ID, os::APP_NAME, os::tray_icon())
let spec = rune::TraySpec::new(os::APP_ID, os::APP_NAME, os::tray_icon(false))
.tooltip("League Recorder")
.menu(os::tray_menu(false));
let wake = waker.clone();
@@ -685,6 +685,7 @@ impl App {
if self.status.is_recording != was_recording {
if let Some(tray) = &self.tray {
tray.set_menu(os::tray_menu(self.status.is_recording));
tray.set_icon(os::tray_icon(self.status.is_recording));
}
if self.status.is_recording {
os::notify(
+48 -5
View File
@@ -81,20 +81,44 @@ pub fn set_app_icon() {
}
}
/// A 32 px tray icon: the app's medallion, decoded to the straight RGBA rows the tray takes.
pub fn tray_icon() -> rune::TrayIcon {
let (width, height, pixels) = tray_icon_pixels();
/// A 32 px tray icon: the app's medallion, or a plain red disc while the daemon records.
pub fn tray_icon(recording: bool) -> rune::TrayIcon {
let (width, height, pixels) = if recording {
recording_pixels()
} else {
medallion_pixels()
};
rune::TrayIcon::rgba(width, height, pixels)
}
/// The medallion at its bundled 32 px: straight RGBA rows for [`rune::TrayIcon`].
fn tray_icon_pixels() -> (u32, u32, Vec<u8>) {
fn medallion_pixels() -> (u32, u32, Vec<u8>) {
let image = image::load_from_memory(include_bytes!("../icons/32x32.png"))
.expect("the bundled tray icon decodes")
.into_rgba8();
(image.width(), image.height(), image.into_raw())
}
/// A red disc on clear pixels. The edge gets one pixel of coverage, so a tray that scales the
/// icon down to 16 px does not show a jagged ring.
fn recording_pixels() -> (u32, u32, Vec<u8>) {
const SIZE: u32 = 32;
const RADIUS: f32 = 11.0;
const RED: [u8; 3] = [220, 38, 38];
let center = SIZE as f32 / 2.0;
let mut pixels = Vec::with_capacity((SIZE * SIZE * 4) as usize);
for y in 0..SIZE {
for x in 0..SIZE {
let dx = x as f32 + 0.5 - center;
let dy = y as f32 + 0.5 - center;
let distance = (dx * dx + dy * dy).sqrt();
let alpha = ((RADIUS + 0.5 - distance).clamp(0.0, 1.0) * 255.0).round() as u8;
pixels.extend_from_slice(&[RED[0], RED[1], RED[2], alpha]);
}
}
(SIZE, SIZE, pixels)
}
/// The tray menu. `recording` flips the record item's label.
pub fn tray_menu(recording: bool) -> Vec<rune::TrayItem> {
vec![
@@ -120,8 +144,27 @@ mod tests {
#[test]
fn the_tray_icon_decodes_to_32_px_of_rgba() {
let (width, height, pixels) = tray_icon_pixels();
let (width, height, pixels) = medallion_pixels();
assert_eq!((width, height), (32, 32));
assert_eq!(pixels.len(), (32 * 32 * 4) as usize);
}
#[test]
fn the_recording_icon_is_a_red_disc_on_a_clear_square() {
let (width, height, pixels) = recording_pixels();
assert_eq!((width, height), (32, 32));
let at = |x: usize, y: usize| {
let i = (y * 32 + x) * 4;
[pixels[i], pixels[i + 1], pixels[i + 2], pixels[i + 3]]
};
assert_eq!(at(16, 16), [220, 38, 38, 255]);
assert_eq!(at(0, 0)[3], 0);
assert_eq!(at(31, 16)[3], 0);
assert!(
pixels
.chunks_exact(4)
.filter(|p| p[3] == 255)
.all(|p| p[..3] == [220, 38, 38])
);
}
}