Only display known information
This commit is contained in:
@@ -71,45 +71,7 @@ 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();
|
write!(f, "{}", self.to_string_with_padding(25))
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"Name: {}
|
|
||||||
Battery level: {}
|
|
||||||
Charging status: {}
|
|
||||||
Muted: {}
|
|
||||||
Mic connected: {}
|
|
||||||
Automatic shutdown after: {}
|
|
||||||
Pairing info: {}
|
|
||||||
Product color: {}
|
|
||||||
Side tone on: {}
|
|
||||||
Side tone volume: {}
|
|
||||||
Surround sound: {}
|
|
||||||
Voice prompt on: {}
|
|
||||||
Connected: {}
|
|
||||||
Silent: {}",
|
|
||||||
self.device_name.clone().unwrap_or("Unknown".to_string()),
|
|
||||||
self.battery_level
|
|
||||||
.map_or(unknown.clone(), |l| format!("{l}%")),
|
|
||||||
self.charging.map_or(unknown.clone(), |c| c.to_string()),
|
|
||||||
self.muted.map_or(unknown.clone(), |m| m.to_string()),
|
|
||||||
self.mic_connected
|
|
||||||
.map_or(unknown.clone(), |m| m.to_string()),
|
|
||||||
self.automatic_shutdown_after
|
|
||||||
.map_or(unknown.clone(), |a| format!("{} min", a.as_secs() / 60)),
|
|
||||||
self.pairing_info.map_or(unknown.clone(), |p| p.to_string()),
|
|
||||||
self.product_color
|
|
||||||
.map_or(unknown.clone(), |c| c.to_string()),
|
|
||||||
self.side_tone_on.map_or(unknown.clone(), |s| s.to_string()),
|
|
||||||
self.side_tone_volume
|
|
||||||
.map_or(unknown.clone(), |s| s.to_string()),
|
|
||||||
self.surround_sound
|
|
||||||
.map_or(unknown.clone(), |s| s.to_string()),
|
|
||||||
self.voice_prompt_on
|
|
||||||
.map_or(unknown.clone(), |v| v.to_string()),
|
|
||||||
self.connected.map_or(unknown.clone(), |c| c.to_string()),
|
|
||||||
self.silent.map_or(unknown.clone(), |s| s.to_string()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,43 +117,65 @@ impl DeviceState {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string_no_padding(&self) -> String {
|
pub fn to_string_with_padding(&self, padding: usize) -> String {
|
||||||
let unknown = "Unknown".to_string();
|
let data = [
|
||||||
format!(
|
(
|
||||||
"Battery level: {}
|
"Battery level:",
|
||||||
Charging status: {}
|
self.battery_level.map(|l| l.to_string()),
|
||||||
Muted: {}
|
"%",
|
||||||
Mic connected: {}
|
),
|
||||||
Automatic shutdown after: {}
|
("Charging status:", self.charging.map(|c| c.to_string()), ""),
|
||||||
Pairing info: {}
|
("Muted:", self.muted.map(|c| c.to_string()), ""),
|
||||||
Product color: {}
|
(
|
||||||
Side tone on: {}
|
"Mic connected:",
|
||||||
Side tone volume: {}
|
self.mic_connected.map(|c| c.to_string()),
|
||||||
Surround sound: {}
|
"",
|
||||||
Voice prompt on: {}
|
),
|
||||||
Connected: {}
|
(
|
||||||
Silent: {}",
|
"Automatic shutdown after:",
|
||||||
self.battery_level
|
|
||||||
.map_or(unknown.clone(), |l| format!("{l}%")),
|
|
||||||
self.charging.map_or(unknown.clone(), |c| c.to_string()),
|
|
||||||
self.muted.map_or(unknown.clone(), |m| m.to_string()),
|
|
||||||
self.mic_connected
|
|
||||||
.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(|c| (c.as_secs() / 60).to_string()),
|
||||||
self.pairing_info.map_or(unknown.clone(), |p| p.to_string()),
|
"min",
|
||||||
self.product_color
|
),
|
||||||
.map_or(unknown.clone(), |c| c.to_string()),
|
(
|
||||||
self.side_tone_on.map_or(unknown.clone(), |s| s.to_string()),
|
"pairing info:",
|
||||||
self.side_tone_volume
|
self.pairing_info.map(|c| c.to_string()),
|
||||||
.map_or(unknown.clone(), |s| s.to_string()),
|
"",
|
||||||
self.surround_sound
|
),
|
||||||
.map_or(unknown.clone(), |s| s.to_string()),
|
(
|
||||||
self.voice_prompt_on
|
"product color:",
|
||||||
.map_or(unknown.clone(), |v| v.to_string()),
|
self.product_color.map(|c| c.to_string()),
|
||||||
self.connected.map_or(unknown.clone(), |c| c.to_string()),
|
"",
|
||||||
self.silent.map_or(unknown.clone(), |s| s.to_string()),
|
),
|
||||||
)
|
("Side tone:", self.side_tone_on.map(|c| c.to_string()), ""),
|
||||||
|
(
|
||||||
|
"Side tone volume:",
|
||||||
|
self.side_tone_volume.map(|c| c.to_string()),
|
||||||
|
"",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"Surround sound:",
|
||||||
|
self.surround_sound.map(|c| c.to_string()),
|
||||||
|
"",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"Voice prompt:",
|
||||||
|
self.voice_prompt_on.map(|c| c.to_string()),
|
||||||
|
"",
|
||||||
|
),
|
||||||
|
("Connected:", self.connected.map(|c| c.to_string()), ""),
|
||||||
|
("Playback muted:", self.silent.map(|c| c.to_string()), ""),
|
||||||
|
];
|
||||||
|
data.iter()
|
||||||
|
.filter_map(|(prefix, data, suffix)| {
|
||||||
|
if let Some(data) = data {
|
||||||
|
Some(format!("{:<padding$} {}{}", prefix, data, suffix))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_self_with_event(&mut self, event: &DeviceEvent) {
|
fn update_self_with_event(&mut self, event: &DeviceEvent) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ impl TrayHandler {
|
|||||||
device_state.device_name.clone(),
|
device_state.device_name.clone(),
|
||||||
),
|
),
|
||||||
Some(true) => (
|
Some(true) => (
|
||||||
device_state.to_string_no_padding(),
|
device_state.to_string_with_padding(0),
|
||||||
device_state.device_name.clone(),
|
device_state.device_name.clone(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user