Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LennardKittner committed May 29, 2024
1 parent 7e2c301 commit e23f3cd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
70 changes: 35 additions & 35 deletions src/battery_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,43 +65,11 @@ impl BatteryTray {
}

impl Tray for BatteryTray {
fn icon_name(&self) -> String {
"audio-headset".into()
}
fn id(&self) -> String {
env!("CARGO_PKG_NAME").into()
}
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"})).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 icon_name(&self) -> String {
"audio-headset".into()
}
fn tool_tip(&self) -> ToolTip {
let description = match &self.status_message {
Expand Down Expand Up @@ -134,9 +102,41 @@ impl Tray for BatteryTray {
};
ToolTip {
title: "HyperX Cloud II".to_string(),
description: description,
description,
icon_name: "audio-headset".into(),
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
}
}
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl DeviceEvent {
return Err(DeviceError::NoResponse());
}
if len != 8 {
return Err(DeviceError::UnknownResponse(buf.clone(), len));
return Err(DeviceError::UnknownResponse(*buf, len));
}
match buf {
buf if buf.starts_with(&NOW_CHARGING) => Ok(Self::NowCharging),
Expand All @@ -49,7 +49,7 @@ impl DeviceEvent {
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_DISCONNECTED) => Ok(Self::NowMicDisconnected),
_ => Err(DeviceError::UnknownResponse(buf.clone(), len)),
_ => Err(DeviceError::UnknownResponse(*buf, len)),
}
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ impl Device {

fn update_self_with_event(&mut self, event: &DeviceEvent) {
match event {
DeviceEvent::BatterLevel(level) => self.battery_level = level.clone(),
DeviceEvent::BatterLevel(level) => self.battery_level = *level,
DeviceEvent::NowCharging => self.charging = Some(true),
DeviceEvent::StoppedCharging => self.charging = Some(false),
DeviceEvent::NowMuted => self.muted = Some(true),
Expand Down

0 comments on commit e23f3cd

Please sign in to comment.