Better tray ToolTip

This commit is contained in:
lennard
2023-06-10 01:08:36 +02:00
parent 2e3beb2d9c
commit a779acb8a5
2 changed files with 16 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
use ksni::{Tray, MenuItem, menu::{StandardItem}};
use ksni::{Tray, MenuItem, menu::{StandardItem}, ToolTip};
#[derive(Debug)]
pub struct BatteryTray {
@@ -14,7 +14,7 @@ impl BatteryTray {
}
}
pub fn refresh(&mut self, battery_level: u8, charging: bool) {
pub fn update(&mut self, battery_level: u8, charging: bool) {
self.battery_level = battery_level;
self.charging = charging;
}
@@ -24,13 +24,6 @@ impl Tray for BatteryTray {
fn icon_name(&self) -> String {
"headset".into()
}
fn title(&self) -> String {
if self.charging {
format!("Battery level: {}%\nCharging", self.battery_level).to_string()
} else {
format!("Battery level: {}%\nNot charging", self.battery_level).to_string()
}
}
fn menu(&self) -> Vec<MenuItem<Self>> {
vec![
StandardItem {
@@ -42,4 +35,17 @@ impl Tray for BatteryTray {
.into(),
]
}
fn tool_tip(&self) -> ToolTip {
let description = if self.charging {
format!("Battery level: {}%\nCharging", self.battery_level)
} else {
format!("Battery level: {}%\nNot charging", self.battery_level)
};
ToolTip {
title: "HyperX Cloud II".to_string(),
description: description,
icon_name: "".into(),
icon_pixmap: Vec::new(),
}
}
}

View File

@@ -40,7 +40,7 @@ fn main() {
}
};
handle.update(|tray: &mut BatteryTray| {
tray.refresh(battery_level, charging);
tray.update(battery_level, charging);
});
}
}