Formatting
This commit is contained in:
@@ -45,9 +45,11 @@ pub struct DeviceState {
|
|||||||
impl Display for DeviceState {
|
impl Display for DeviceState {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let unknown = "Unknown".to_string();
|
let unknown = "Unknown".to_string();
|
||||||
write!(f, "Name: {}
|
write!(
|
||||||
|
f,
|
||||||
|
"Name: {}
|
||||||
Battery level: {}
|
Battery level: {}
|
||||||
Charging status: {}
|
Charging status: {}
|
||||||
Muted: {}
|
Muted: {}
|
||||||
Mic connected: {}
|
Mic connected: {}
|
||||||
Automatic shutdown after: {}
|
Automatic shutdown after: {}
|
||||||
@@ -57,24 +59,24 @@ Side tone on: {}
|
|||||||
Side tone volume: {}
|
Side tone volume: {}
|
||||||
Voice prompt on: {}
|
Voice prompt on: {}
|
||||||
Connected: {}",
|
Connected: {}",
|
||||||
self.device_name.clone().unwrap_or("Unknown".to_string()),
|
self.device_name.clone().unwrap_or("Unknown".to_string()),
|
||||||
self.battery_level
|
self.battery_level
|
||||||
.map_or(unknown.clone(), |l| format!("{l}%")),
|
.map_or(unknown.clone(), |l| format!("{l}%")),
|
||||||
self.charging.map_or(unknown.clone(), |c| c.to_string()),
|
self.charging.map_or(unknown.clone(), |c| c.to_string()),
|
||||||
self.muted.map_or(unknown.clone(), |m| m.to_string()),
|
self.muted.map_or(unknown.clone(), |m| m.to_string()),
|
||||||
self.mic_connected
|
self.mic_connected
|
||||||
.map_or(unknown.clone(), |m| m.to_string()),
|
.map_or(unknown.clone(), |m| m.to_string()),
|
||||||
self.automatic_shutdown_after
|
self.automatic_shutdown_after
|
||||||
.map_or(unknown.clone(), |a| format!("{} min", a.as_secs() / 60)),
|
.map_or(unknown.clone(), |a| format!("{} min", a.as_secs() / 60)),
|
||||||
self.pairing_info.map_or(unknown.clone(), |p| p.to_string()),
|
self.pairing_info.map_or(unknown.clone(), |p| p.to_string()),
|
||||||
self.product_color
|
self.product_color
|
||||||
.map_or(unknown.clone(), |c| c.to_string()),
|
.map_or(unknown.clone(), |c| c.to_string()),
|
||||||
self.side_tone_on.map_or(unknown.clone(), |s| s.to_string()),
|
self.side_tone_on.map_or(unknown.clone(), |s| s.to_string()),
|
||||||
self.side_tone_volume
|
self.side_tone_volume
|
||||||
.map_or(unknown.clone(), |s| s.to_string()),
|
.map_or(unknown.clone(), |s| s.to_string()),
|
||||||
self.voice_prompt_on
|
self.voice_prompt_on
|
||||||
.map_or(unknown.clone(), |v| v.to_string()),
|
.map_or(unknown.clone(), |v| v.to_string()),
|
||||||
self.connected.map_or(unknown.clone(), |c| c.to_string()),
|
self.connected.map_or(unknown.clone(), |c| c.to_string()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +90,11 @@ impl DeviceState {
|
|||||||
if product_ids.contains(&info.product_id())
|
if product_ids.contains(&info.product_id())
|
||||||
&& vendor_ids.contains(&info.vendor_id())
|
&& vendor_ids.contains(&info.vendor_id())
|
||||||
{
|
{
|
||||||
Some((hid_api.open(info.vendor_id(), info.product_id()), info.product_id(), info.vendor_id()))
|
Some((
|
||||||
|
hid_api.open(info.vendor_id(), info.product_id()),
|
||||||
|
info.product_id(),
|
||||||
|
info.vendor_id(),
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -117,7 +123,8 @@ impl DeviceState {
|
|||||||
|
|
||||||
pub fn to_string_no_padding(&self) -> String {
|
pub fn to_string_no_padding(&self) -> String {
|
||||||
let unknown = "Unknown".to_string();
|
let unknown = "Unknown".to_string();
|
||||||
format!("Battery level: {}
|
format!(
|
||||||
|
"Battery level: {}
|
||||||
Charging status: {}
|
Charging status: {}
|
||||||
Muted: {}
|
Muted: {}
|
||||||
Mic connected: {}
|
Mic connected: {}
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ impl TrayHandler {
|
|||||||
"Headset is not connected".to_string(),
|
"Headset is not connected".to_string(),
|
||||||
device_state.device_name.clone(),
|
device_state.device_name.clone(),
|
||||||
),
|
),
|
||||||
Some(true) => (device_state.to_string_no_padding(), device_state.device_name.clone()),
|
Some(true) => (
|
||||||
|
device_state.to_string_no_padding(),
|
||||||
|
device_state.device_name.clone(),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
self.handle.update(|tray| {
|
self.handle.update(|tray| {
|
||||||
tray.message = message;
|
tray.message = message;
|
||||||
@@ -53,7 +56,13 @@ impl Tray for StatusTray {
|
|||||||
"audio-headset".into()
|
"audio-headset".into()
|
||||||
}
|
}
|
||||||
fn tool_tip(&self) -> ToolTip {
|
fn tool_tip(&self) -> ToolTip {
|
||||||
let description = self.message.clone().lines().filter(|l| !l.contains("Unknown")).collect::<Vec<&str>>().join("\n");
|
let description = self
|
||||||
|
.message
|
||||||
|
.clone()
|
||||||
|
.lines()
|
||||||
|
.filter(|l| !l.contains("Unknown"))
|
||||||
|
.collect::<Vec<&str>>()
|
||||||
|
.join("\n");
|
||||||
ToolTip {
|
ToolTip {
|
||||||
title: self.device_name.clone().unwrap_or("Unknown".to_string()),
|
title: self.device_name.clone().unwrap_or("Unknown".to_string()),
|
||||||
description,
|
description,
|
||||||
|
|||||||
Reference in New Issue
Block a user