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> {
|
fn parse_threshold(thresh: String) -> Option<Threshold> {
|
||||||
let mut s = thresh.clone();
|
let mut s = thresh;
|
||||||
|
|
||||||
let last = s.pop();
|
let last = s.pop();
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ fn format_duration(duration: f32) -> String {
|
|||||||
}
|
}
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
if d < 0 {
|
if d < 0 {
|
||||||
s.push_str("-");
|
s.push('-');
|
||||||
d = -d;
|
d = -d;
|
||||||
}
|
}
|
||||||
let hours = d / 3600;
|
let hours = d / 3600;
|
||||||
@ -105,11 +105,11 @@ fn format_duration(duration: f32) -> String {
|
|||||||
s.push_str(&format!("{}h", hours));
|
s.push_str(&format!("{}h", hours));
|
||||||
}
|
}
|
||||||
if minutes > 0 {
|
if minutes > 0 {
|
||||||
if hours > 0 { s.push_str(" "); }
|
if hours > 0 { s.push(' '); }
|
||||||
s.push_str(&format!("{}m", minutes));
|
s.push_str(&format!("{}m", minutes));
|
||||||
}
|
}
|
||||||
if seconds > 0 {
|
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.push_str(&format!("{}s", seconds));
|
||||||
}
|
}
|
||||||
s
|
s
|
||||||
@ -205,29 +205,29 @@ fn main() -> battery::Result<()> {
|
|||||||
if state != last_state {
|
if state != last_state {
|
||||||
match state {
|
match state {
|
||||||
State::Charging => {
|
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.title = Some(format!("Charging, {} until full", format_duration(ttf.value)));
|
||||||
osd.urgency = Urgency::Low;
|
osd.urgency = Urgency::Low;
|
||||||
osd.update().unwrap();
|
osd.update().unwrap();
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
State::Low => {
|
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.title = Some(format!("Low battery, {} remaining", format_duration(tte.value)));
|
||||||
osd.urgency = Urgency::Normal;
|
osd.urgency = Urgency::Normal;
|
||||||
osd.update().unwrap();
|
osd.update().unwrap();
|
||||||
});
|
};
|
||||||
},
|
},
|
||||||
State::Normal | State::Critical => { }
|
State::Normal | State::Critical => { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if state == 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.title = Some(format!("Critically low battery, {} remaining", format_duration(tte.value)));
|
||||||
osd.urgency = Urgency::Critical;
|
osd.urgency = Urgency::Critical;
|
||||||
osd.update().unwrap();
|
osd.update().unwrap();
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::sleep(Duration::from_secs(refresh_interval));
|
thread::sleep(Duration::from_secs(refresh_interval));
|
||||||
|
@ -32,7 +32,7 @@ fn main() {
|
|||||||
loop {
|
loop {
|
||||||
let device = adapter.get_first_device().unwrap();
|
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 {
|
if device_name != last_device_name {
|
||||||
osd.title = Some(format!("Bluetooth: connected to {}", device_name));
|
osd.title = Some(format!("Bluetooth: connected to {}", device_name));
|
||||||
|
@ -28,7 +28,7 @@ fn main() {
|
|||||||
loop {
|
loop {
|
||||||
b = brightness.get_brightness().unwrap() as f32;
|
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.contents = OSDContents::Progress(b/m, OSDProgressText::Percentage);
|
||||||
osd.update().unwrap();
|
osd.update().unwrap();
|
||||||
}
|
}
|
||||||
|
@ -154,24 +154,24 @@ pub mod notify {
|
|||||||
|
|
||||||
let notification = Notification::new();
|
let notification = Notification::new();
|
||||||
|
|
||||||
return OSD {
|
OSD {
|
||||||
title: None, icon: None,
|
title: None, icon: None,
|
||||||
contents: OSDContents::default(),
|
contents: OSDContents::default(),
|
||||||
urgency: Urgency::Normal, id: None,
|
urgency: Urgency::Normal, id: None,
|
||||||
timeout,
|
timeout,
|
||||||
length, full, empty, start, end,
|
length, full, empty, start, end,
|
||||||
notification
|
notification
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn construct_fake_handle(id: u32, notification: Notification) -> NotificationHandle {
|
fn construct_fake_handle(id: u32, notification: Notification) -> NotificationHandle {
|
||||||
let h = CustomHandle
|
let h = CustomHandle
|
||||||
{ id: id,
|
{ id,
|
||||||
connection: Connection::get_private(BusType::Session).unwrap(),
|
connection: Connection::get_private(BusType::Session).unwrap(),
|
||||||
notification: notification };
|
notification };
|
||||||
unsafe {
|
unsafe {
|
||||||
let handle : NotificationHandle = std::mem::transmute(h);
|
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(self.end.as_str());
|
||||||
|
|
||||||
s.push_str(" ");
|
s.push(' ');
|
||||||
|
|
||||||
match text {
|
match text {
|
||||||
OSDProgressText::Percentage => {
|
OSDProgressText::Percentage => {
|
||||||
s.push_str(((value * 100.) as i32).to_string().as_str());
|
s.push_str(((value * 100.) as i32).to_string().as_str());
|
||||||
|
|
||||||
s.push_str("%");
|
s.push('%');
|
||||||
},
|
},
|
||||||
OSDProgressText::Text(text) => {
|
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));
|
self.id.map(|i| self.notification.id(i));
|
||||||
let handle = self.notification
|
let handle = self.notification
|
||||||
.summary(self.title.as_deref().unwrap_or(""))
|
.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(""))
|
.icon(self.icon.as_deref().unwrap_or(""))
|
||||||
.urgency(self.urgency)
|
.urgency(self.urgency)
|
||||||
.finalize()
|
.finalize()
|
||||||
@ -246,4 +246,10 @@ pub mod notify {
|
|||||||
self.fake_handle().close();
|
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 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 update_on_volume_change = config.lock().unwrap().get_default("default", "update on volume change", true);
|
||||||
let timeout = config.clone().lock().unwrap().get_default("default", "notification display time", 5);
|
let timeout = config.lock().unwrap().get_default("default", "notification display time", 5);
|
||||||
|
|
||||||
let trigger = Arc::new(Mutex::new(SystemTime::now()));
|
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()))
|
Some(volume_changes::VolumeMonitor::new(config.clone(), trigger.clone(), dismissed.clone()))
|
||||||
} else { None };
|
} else { None };
|
||||||
|
|
||||||
drop(update_on_volume_change);
|
|
||||||
drop(config);
|
drop(config);
|
||||||
|
|
||||||
let mut title;
|
let mut title;
|
||||||
@ -204,13 +203,13 @@ fn main() {
|
|||||||
dismissed.lock().unwrap().store(false, Ordering::Relaxed);
|
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) {
|
if elapsed.as_secs() < timeout && playback_status != PlaybackStatus::Stopped && ! dismissed.lock().unwrap().load(Ordering::Relaxed) {
|
||||||
let metadata = progress.metadata();
|
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 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));
|
osd.title = Some(format!("{:?}: {} - {}", playback_status, title, artists));
|
||||||
let ratio = position.as_secs_f32() / length.as_secs_f32();
|
let ratio = position.as_secs_f32() / length.as_secs_f32();
|
||||||
@ -240,6 +239,6 @@ fn main() {
|
|||||||
old_playback_status = playback_status;
|
old_playback_status = playback_status;
|
||||||
|
|
||||||
#[cfg(feature = "display_on_volume_changes")]
|
#[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