@@ -4,24 +4,26 @@ use ab_glyph::{Font, ScaleFont};
44use ksni:: { Icon , ToolTip } ;
55use tokio:: sync:: mpsc:: UnboundedSender ;
66
7- use crate :: bluetooth:: aacp:: ControlCommandIdentifiers ;
7+ use crate :: bluetooth:: aacp:: { BatteryStatus , ControlCommandIdentifiers } ;
88use crate :: ui:: messages:: BluetoothUIMessage ;
99use crate :: utils:: get_app_settings_path;
1010
1111#[ derive( Debug ) ]
12- pub ( crate ) struct MyTray {
13- pub ( crate ) conversation_detect_enabled : Option < bool > ,
14- pub ( crate ) battery_l : Option < u8 > ,
15- pub ( crate ) battery_l_status : Option < crate :: bluetooth:: aacp:: BatteryStatus > ,
16- pub ( crate ) battery_r : Option < u8 > ,
17- pub ( crate ) battery_r_status : Option < crate :: bluetooth:: aacp:: BatteryStatus > ,
18- pub ( crate ) battery_c : Option < u8 > ,
19- pub ( crate ) battery_c_status : Option < crate :: bluetooth:: aacp:: BatteryStatus > ,
20- pub ( crate ) connected : bool ,
21- pub ( crate ) listening_mode : Option < u8 > ,
22- pub ( crate ) allow_off_option : Option < u8 > ,
23- pub ( crate ) command_tx : Option < UnboundedSender < ( ControlCommandIdentifiers , Vec < u8 > ) > > ,
24- pub ( crate ) ui_tx : Option < UnboundedSender < BluetoothUIMessage > > ,
12+ pub struct MyTray {
13+ pub conversation_detect_enabled : Option < bool > ,
14+ pub battery_headphone : Option < u8 > ,
15+ pub battery_headphone_status : Option < BatteryStatus > ,
16+ pub battery_l : Option < u8 > ,
17+ pub battery_l_status : Option < BatteryStatus > ,
18+ pub battery_r : Option < u8 > ,
19+ pub battery_r_status : Option < BatteryStatus > ,
20+ pub battery_c : Option < u8 > ,
21+ pub battery_c_status : Option < BatteryStatus > ,
22+ pub connected : bool ,
23+ pub listening_mode : Option < u8 > ,
24+ pub allow_off_option : Option < u8 > ,
25+ pub command_tx : Option < UnboundedSender < ( ControlCommandIdentifiers , Vec < u8 > ) > > ,
26+ pub ui_tx : Option < UnboundedSender < BluetoothUIMessage > > ,
2527}
2628
2729impl ksni:: Tray for MyTray {
@@ -34,30 +36,36 @@ impl ksni::Tray for MyTray {
3436 fn icon_pixmap ( & self ) -> Vec < Icon > {
3537 let text = {
3638 let mut levels: Vec < u8 > = Vec :: new ( ) ;
37- if let Some ( l ) = self . battery_l {
38- if self . battery_l_status != Some ( crate :: bluetooth :: aacp :: BatteryStatus :: Disconnected ) {
39- levels. push ( l ) ;
39+ if let Some ( h ) = self . battery_headphone {
40+ if self . battery_headphone_status != Some ( BatteryStatus :: Disconnected ) {
41+ levels. push ( h ) ;
4042 }
41- }
42- if let Some ( r) = self . battery_r {
43- if self . battery_r_status != Some ( crate :: bluetooth:: aacp:: BatteryStatus :: Disconnected ) {
44- levels. push ( r) ;
43+ } else {
44+ if let Some ( l) = self . battery_l {
45+ if self . battery_l_status != Some ( BatteryStatus :: Disconnected ) {
46+ levels. push ( l) ;
47+ }
48+ }
49+ if let Some ( r) = self . battery_r {
50+ if self . battery_r_status != Some ( BatteryStatus :: Disconnected ) {
51+ levels. push ( r) ;
52+ }
4553 }
54+ // if let Some(c) = self.battery_c {
55+ // if self.battery_c_status != Some(BatteryStatus::Disconnected) {
56+ // levels.push(c);
57+ // }
58+ // }
4659 }
47- // if let Some(c) = self.battery_c {
48- // if self.battery_c_status != Some(crate::bluetooth::aacp::BatteryStatus::Disconnected) {
49- // levels.push(c);
50- // }
51- // }
5260 let min_battery = levels. iter ( ) . min ( ) . copied ( ) ;
5361 if let Some ( b) = min_battery {
5462 format ! ( "{}" , b)
5563 } else {
5664 "?" . to_string ( )
5765 }
5866 } ;
59- let any_bud_charging = matches ! ( self . battery_l_status, Some ( crate :: bluetooth :: aacp :: BatteryStatus :: Charging ) )
60- || matches ! ( self . battery_r_status, Some ( crate :: bluetooth :: aacp :: BatteryStatus :: Charging ) ) ;
67+ let any_bud_charging = matches ! ( self . battery_l_status, Some ( BatteryStatus :: Charging ) )
68+ || matches ! ( self . battery_r_status, Some ( BatteryStatus :: Charging ) ) ;
6169 let app_settings_path = get_app_settings_path ( ) ;
6270 let settings = std:: fs:: read_to_string ( & app_settings_path)
6371 . ok ( )
@@ -70,12 +78,12 @@ impl ksni::Tray for MyTray {
7078 vec ! [ icon]
7179 }
7280 fn tool_tip ( & self ) -> ToolTip {
73- let format_component = |label : & str , level : Option < u8 > , status : Option < crate :: bluetooth :: aacp :: BatteryStatus > | -> String {
81+ let format_component = |label : & str , level : Option < u8 > , status : Option < BatteryStatus > | -> String {
7482 match status {
75- Some ( crate :: bluetooth :: aacp :: BatteryStatus :: Disconnected ) => format ! ( "{}: -" , label) ,
83+ Some ( BatteryStatus :: Disconnected ) => format ! ( "{}: -" , label) ,
7684 _ => {
7785 let pct = level. map ( |b| format ! ( "{}%" , b) ) . unwrap_or ( "?" . to_string ( ) ) ;
78- let suffix = if status == Some ( crate :: bluetooth :: aacp :: BatteryStatus :: Charging ) {
86+ let suffix = if status == Some ( BatteryStatus :: Charging ) {
7987 "⚡"
8088 } else {
8189 ""
0 commit comments