Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions linux-rust/src/ui/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ksni::MenuItem<Self>> {
use ksni::menu::*;
let allow_off = self.allow_off_option == Some(0x01);
Expand All @@ -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(),
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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),
};

<MyTray as ksni::Tray>::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;
}