Make clippy happy
This commit is contained in:
parent
dd5883f58c
commit
776d2ec912
@ -39,7 +39,7 @@ fn threshold_sane(thresh: Threshold) -> Option<Threshold> {
|
||||
}
|
||||
|
||||
fn parse_threshold(thresh: String) -> Option<Threshold> {
|
||||
let mut s = thresh.clone();
|
||||
let mut s = thresh;
|
||||
|
||||
let last = s.pop();
|
||||
|
||||
@ -93,7 +93,7 @@ fn format_duration(duration: f32) -> String {
|
||||
}
|
||||
let mut s = String::new();
|
||||
if d < 0 {
|
||||
s.push_str("-");
|
||||
s.push('-');
|
||||
d = -d;
|
||||
}
|
||||
let hours = d / 3600;
|
||||
@ -105,11 +105,11 @@ fn format_duration(duration: f32) -> String {
|
||||
s.push_str(&format!("{}h", hours));
|
||||
}
|
||||
if minutes > 0 {
|
||||
if hours > 0 { s.push_str(" "); }
|
||||
if hours > 0 { s.push(' '); }
|
||||
s.push_str(&format!("{}m", minutes));
|
||||
}
|
||||
if seconds > 0 {
|
||||
if hours > 0 || minutes > 0 { s.push_str(" "); }
|
||||
if hours > 0 || minutes > 0 { s.push(' '); }
|
||||
s.push_str(&format!("{}s", seconds));
|
||||
}
|
||||
s
|
||||
@ -205,29 +205,29 @@ fn main() -> battery::Result<()> {
|
||||
if state != last_state {
|
||||
match state {
|
||||
State::Charging => {
|
||||
battery.time_to_full().map(|ttf| {
|
||||
if let Some(ttf) = battery.time_to_full() {
|
||||
osd.title = Some(format!("Charging, {} until full", format_duration(ttf.value)));
|
||||
osd.urgency = Urgency::Low;
|
||||
osd.update().unwrap();
|
||||
});
|
||||
};
|
||||
}
|
||||
State::Low => {
|
||||
battery.time_to_empty().map(|tte| {
|
||||
if let Some(tte) = battery.time_to_empty() {
|
||||
osd.title = Some(format!("Low battery, {} remaining", format_duration(tte.value)));
|
||||
osd.urgency = Urgency::Normal;
|
||||
osd.update().unwrap();
|
||||
});
|
||||
};
|
||||
},
|
||||
State::Normal | State::Critical => { }
|
||||
}
|
||||
}
|
||||
|
||||
if state == State::Critical {
|
||||
battery.time_to_empty().map(|tte| {
|
||||
if let Some(tte) = battery.time_to_empty() {
|
||||
osd.title = Some(format!("Critically low battery, {} remaining", format_duration(tte.value)));
|
||||
osd.urgency = Urgency::Critical;
|
||||
osd.update().unwrap();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
thread::sleep(Duration::from_secs(refresh_interval));
|
||||
|
@ -32,7 +32,7 @@ fn main() {
|
||||
loop {
|
||||
let device = adapter.get_first_device().unwrap();
|
||||
|
||||
device_name = device.get_name().unwrap_or(String::from(""));
|
||||
device_name = device.get_name().ok().unwrap_or_else(String::new);
|
||||
|
||||
if device_name != last_device_name {
|
||||
osd.title = Some(format!("Bluetooth: connected to {}", device_name));
|
||||
|
@ -28,7 +28,7 @@ fn main() {
|
||||
loop {
|
||||
b = brightness.get_brightness().unwrap() as f32;
|
||||
|
||||
if b != last_b {
|
||||
if (b - last_b).abs() > 0.1 {
|
||||
osd.contents = OSDContents::Progress(b/m, OSDProgressText::Percentage);
|
||||
osd.update().unwrap();
|
||||
}
|
||||
|
@ -154,24 +154,24 @@ pub mod notify {
|
||||
|
||||
let notification = Notification::new();
|
||||
|
||||
return OSD {
|
||||
OSD {
|
||||
title: None, icon: None,
|
||||
contents: OSDContents::default(),
|
||||
urgency: Urgency::Normal, id: None,
|
||||
timeout,
|
||||
length, full, empty, start, end,
|
||||
notification
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn construct_fake_handle(id: u32, notification: Notification) -> NotificationHandle {
|
||||
let h = CustomHandle
|
||||
{ id: id,
|
||||
{ id,
|
||||
connection: Connection::get_private(BusType::Session).unwrap(),
|
||||
notification: notification };
|
||||
notification };
|
||||
unsafe {
|
||||
let handle : NotificationHandle = std::mem::transmute(h);
|
||||
return handle;
|
||||
handle
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,16 +197,16 @@ pub mod notify {
|
||||
|
||||
s.push_str(self.end.as_str());
|
||||
|
||||
s.push_str(" ");
|
||||
s.push(' ');
|
||||
|
||||
match text {
|
||||
OSDProgressText::Percentage => {
|
||||
s.push_str(((value * 100.) as i32).to_string().as_str());
|
||||
|
||||
s.push_str("%");
|
||||
s.push('%');
|
||||
},
|
||||
OSDProgressText::Text(text) => {
|
||||
text.as_ref().map(|text| s.push_str(text.as_str()));
|
||||
if let Some(text) = text.as_ref() { s.push_str(text.as_str()) };
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ pub mod notify {
|
||||
self.id.map(|i| self.notification.id(i));
|
||||
let handle = self.notification
|
||||
.summary(self.title.as_deref().unwrap_or(""))
|
||||
.body(&text.unwrap_or("".to_string()))
|
||||
.body(&text.unwrap_or_else(String::new))
|
||||
.icon(self.icon.as_deref().unwrap_or(""))
|
||||
.urgency(self.urgency)
|
||||
.finalize()
|
||||
@ -246,4 +246,10 @@ pub mod notify {
|
||||
self.fake_handle().close();
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for OSD {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -175,8 +175,8 @@ fn main() {
|
||||
|
||||
let mut progress_tracker = player.track_progress(100).unwrap();
|
||||
|
||||
let update_on_volume_change = config.clone().lock().unwrap().get_default("default", "update on volume change", true);
|
||||
let timeout = config.clone().lock().unwrap().get_default("default", "notification display time", 5);
|
||||
let update_on_volume_change = config.lock().unwrap().get_default("default", "update on volume change", true);
|
||||
let timeout = config.lock().unwrap().get_default("default", "notification display time", 5);
|
||||
|
||||
let trigger = Arc::new(Mutex::new(SystemTime::now()));
|
||||
|
||||
@ -185,7 +185,6 @@ fn main() {
|
||||
Some(volume_changes::VolumeMonitor::new(config.clone(), trigger.clone(), dismissed.clone()))
|
||||
} else { None };
|
||||
|
||||
drop(update_on_volume_change);
|
||||
drop(config);
|
||||
|
||||
let mut title;
|
||||
@ -204,13 +203,13 @@ fn main() {
|
||||
dismissed.lock().unwrap().store(false, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
let elapsed = trigger.lock().unwrap().elapsed().unwrap_or(Duration::from_secs(timeout + 1));
|
||||
let elapsed = trigger.lock().unwrap().elapsed().unwrap_or_else(|_| Duration::from_secs(timeout + 1));
|
||||
|
||||
if elapsed.as_secs() < timeout && playback_status != PlaybackStatus::Stopped && ! dismissed.lock().unwrap().load(Ordering::Relaxed) {
|
||||
let metadata = progress.metadata();
|
||||
let artists = metadata.artists().and_then(|artists| format_artists(artists)).unwrap_or("Unknown".to_string());
|
||||
let artists = metadata.artists().and_then(format_artists).unwrap_or_else(|| "Unknown".to_string());
|
||||
let position = progress.position();
|
||||
let length = progress.length().unwrap_or(Duration::from_secs(100000000));
|
||||
let length = progress.length().unwrap_or_else(|| Duration::from_secs(100000000));
|
||||
|
||||
osd.title = Some(format!("{:?}: {} - {}", playback_status, title, artists));
|
||||
let ratio = position.as_secs_f32() / length.as_secs_f32();
|
||||
@ -240,6 +239,6 @@ fn main() {
|
||||
old_playback_status = playback_status;
|
||||
|
||||
#[cfg(feature = "display_on_volume_changes")]
|
||||
vc.as_ref().map(|v| v.tick());
|
||||
if let Some(v) = vc.as_ref() { v.tick() };
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user