diff --git a/linux-rust/src/ui/tray.rs b/linux-rust/src/ui/tray.rs index b3adbc53a..3f5620290 100644 --- a/linux-rust/src/ui/tray.rs +++ b/linux-rust/src/ui/tray.rs @@ -106,6 +106,9 @@ impl ksni::Tray for MyTray { description: format!("{} {} {}", l, r, c), } } + fn activate(&mut self, _x: i32, _y: i32) { + self.open_window(); + } fn menu(&self) -> Vec> { use ksni::menu::*; let allow_off = self.allow_off_option == Some(0x01); @@ -132,11 +135,7 @@ impl ksni::Tray for MyTray { StandardItem { label: "Open Window".into(), icon_name: "window-new".into(), - activate: Box::new(|this: &mut Self| { - if let Some(tx) = &this.ui_tx { - let _ = tx.send(BluetoothUIMessage::OpenWindow); - } - }), + activate: Box::new(|this: &mut Self| this.open_window()), ..Default::default() } .into(), @@ -193,6 +192,14 @@ impl ksni::Tray for MyTray { } } +impl MyTray { + fn open_window(&self) { + if let Some(tx) = &self.ui_tx { + let _ = tx.send(BluetoothUIMessage::OpenWindow); + } + } +} + fn generate_icon(text: &str, text_mode: bool, charging: bool) -> Icon { use ab_glyph::{FontRef, PxScale}; use image::{ImageBuffer, Rgba}; @@ -299,3 +306,36 @@ fn generate_icon(text: &str, text_mode: bool, charging: bool) -> Icon { data, } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn tray_activation_opens_window() { + let (ui_tx, mut ui_rx) = tokio::sync::mpsc::unbounded_channel(); + let mut tray = MyTray { + conversation_detect_enabled: None, + battery_headphone: None, + battery_headphone_status: None, + battery_l: None, + battery_l_status: None, + battery_r: None, + battery_r_status: None, + battery_c: None, + battery_c_status: None, + connected: false, + listening_mode: None, + allow_off_option: None, + command_tx: None, + ui_tx: Some(ui_tx), + }; + + ::activate(&mut tray, TRAY_ACTIVATION_X, TRAY_ACTIVATION_Y); + + assert!(matches!(ui_rx.try_recv(), Ok(BluetoothUIMessage::OpenWindow))); + } + + const TRAY_ACTIVATION_X: i32 = 0; + const TRAY_ACTIVATION_Y: i32 = 0; +}