Code cleanup
This commit is contained in:
@@ -65,43 +65,11 @@ impl BatteryTray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Tray for BatteryTray {
|
impl Tray for BatteryTray {
|
||||||
fn icon_name(&self) -> String {
|
|
||||||
"audio-headset".into()
|
|
||||||
}
|
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
env!("CARGO_PKG_NAME").into()
|
env!("CARGO_PKG_NAME").into()
|
||||||
}
|
}
|
||||||
fn menu(&self) -> Vec<MenuItem<Self>> {
|
fn icon_name(&self) -> String {
|
||||||
let mut items = vec![
|
"audio-headset".into()
|
||||||
StandardItem {
|
|
||||||
label: format!("Battery level: {bat}% ({crg})", bat = self.battery_level,crg = (if self.charging.is_some() { "Charging" } else {"Discharging"})).into(),
|
|
||||||
enabled: false,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
StandardItem {
|
|
||||||
label: "Exit".into(),
|
|
||||||
icon_name: "application-exit".into(),
|
|
||||||
activate: Box::new(|_| std::process::exit(0)),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
];
|
|
||||||
if let Some(muted) = self.muted {
|
|
||||||
items.insert(1, StandardItem {
|
|
||||||
label: if muted { "Muted" } else { "Not muted" }.into(),
|
|
||||||
enabled: false,
|
|
||||||
..Default::default()
|
|
||||||
}.into());
|
|
||||||
}
|
|
||||||
if let Some(mic_connected) = self.mic_connected {
|
|
||||||
items.insert(2, StandardItem {
|
|
||||||
label: if mic_connected { "Microphone connected" } else { "Microphone not connected" }.into(),
|
|
||||||
enabled: false,
|
|
||||||
..Default::default()
|
|
||||||
}.into());
|
|
||||||
}
|
|
||||||
items
|
|
||||||
}
|
}
|
||||||
fn tool_tip(&self) -> ToolTip {
|
fn tool_tip(&self) -> ToolTip {
|
||||||
let description = match &self.status_message {
|
let description = match &self.status_message {
|
||||||
@@ -134,9 +102,41 @@ impl Tray for BatteryTray {
|
|||||||
};
|
};
|
||||||
ToolTip {
|
ToolTip {
|
||||||
title: "HyperX Cloud II".to_string(),
|
title: "HyperX Cloud II".to_string(),
|
||||||
description: description,
|
description,
|
||||||
icon_name: "audio-headset".into(),
|
icon_name: "audio-headset".into(),
|
||||||
icon_pixmap: Vec::new(),
|
icon_pixmap: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn menu(&self) -> Vec<MenuItem<Self>> {
|
||||||
|
let mut items = vec![
|
||||||
|
StandardItem {
|
||||||
|
label: format!("Battery level: {bat}% ({crg})", bat = self.battery_level,crg = (if self.charging.is_some() { "Charging" } else {"Discharging"})),
|
||||||
|
enabled: false,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
StandardItem {
|
||||||
|
label: "Exit".into(),
|
||||||
|
icon_name: "application-exit".into(),
|
||||||
|
activate: Box::new(|_| std::process::exit(0)),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
];
|
||||||
|
if let Some(muted) = self.muted {
|
||||||
|
items.insert(1, StandardItem {
|
||||||
|
label: if muted { "Muted" } else { "Not muted" }.into(),
|
||||||
|
enabled: false,
|
||||||
|
..Default::default()
|
||||||
|
}.into());
|
||||||
|
}
|
||||||
|
if let Some(mic_connected) = self.mic_connected {
|
||||||
|
items.insert(2, StandardItem {
|
||||||
|
label: if mic_connected { "Microphone connected" } else { "Microphone not connected" }.into(),
|
||||||
|
enabled: false,
|
||||||
|
..Default::default()
|
||||||
|
}.into());
|
||||||
|
}
|
||||||
|
items
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl DeviceEvent {
|
|||||||
return Err(DeviceError::NoResponse());
|
return Err(DeviceError::NoResponse());
|
||||||
}
|
}
|
||||||
if len != 8 {
|
if len != 8 {
|
||||||
return Err(DeviceError::UnknownResponse(buf.clone(), len));
|
return Err(DeviceError::UnknownResponse(*buf, len));
|
||||||
}
|
}
|
||||||
match buf {
|
match buf {
|
||||||
buf if buf.starts_with(&NOW_CHARGING) => Ok(Self::NowCharging),
|
buf if buf.starts_with(&NOW_CHARGING) => Ok(Self::NowCharging),
|
||||||
@@ -49,7 +49,7 @@ impl DeviceEvent {
|
|||||||
buf if buf.starts_with(&STOPPED_MUTED) => Ok(Self::StoppedMuted),
|
buf if buf.starts_with(&STOPPED_MUTED) => Ok(Self::StoppedMuted),
|
||||||
buf if buf.starts_with(&NOW_MIC_CONNECTED) => Ok(Self::NowMicConnected),
|
buf if buf.starts_with(&NOW_MIC_CONNECTED) => Ok(Self::NowMicConnected),
|
||||||
buf if buf.starts_with(&NOW_MIC_DISCONNECTED) => Ok(Self::NowMicDisconnected),
|
buf if buf.starts_with(&NOW_MIC_DISCONNECTED) => Ok(Self::NowMicDisconnected),
|
||||||
_ => Err(DeviceError::UnknownResponse(buf.clone(), len)),
|
_ => Err(DeviceError::UnknownResponse(*buf, len)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ impl Device {
|
|||||||
|
|
||||||
fn update_self_with_event(&mut self, event: &DeviceEvent) {
|
fn update_self_with_event(&mut self, event: &DeviceEvent) {
|
||||||
match event {
|
match event {
|
||||||
DeviceEvent::BatterLevel(level) => self.battery_level = level.clone(),
|
DeviceEvent::BatterLevel(level) => self.battery_level = *level,
|
||||||
DeviceEvent::NowCharging => self.charging = Some(true),
|
DeviceEvent::NowCharging => self.charging = Some(true),
|
||||||
DeviceEvent::StoppedCharging => self.charging = Some(false),
|
DeviceEvent::StoppedCharging => self.charging = Some(false),
|
||||||
DeviceEvent::NowMuted => self.muted = Some(true),
|
DeviceEvent::NowMuted => self.muted = Some(true),
|
||||||
|
|||||||
Reference in New Issue
Block a user