Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Luk-ESC committed Aug 17, 2024
1 parent c074f18 commit 626389a
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async fn popsicle(
let mut confirm = String::new();
io::stdin().read_line(&mut confirm).unwrap();

if confirm.trim() != &fl!("y") && confirm.trim() != "yes" {
if confirm.trim() != fl!("y") && confirm.trim() != "yes" {
return Err(anyhow!(fl!("error-exiting")));
}
}
Expand Down
2 changes: 1 addition & 1 deletion gtk/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {

let status = Command::new("glib-compile-resources")
.arg("--sourcedir=assets")
.arg(&format!("--target={}/compiled.gresource", out_dir))
.arg(format!("--target={}/compiled.gresource", out_dir))
.arg("assets/resources.gresource.xml")
.status()
.unwrap();
Expand Down
4 changes: 3 additions & 1 deletion gtk/src/app/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::thread::{self, JoinHandle};

pub type FlashResult = anyhow::Result<(anyhow::Result<()>, Vec<Result<(), FlashError>>)>;

pub enum UiEvent {
SetImageLabel(PathBuf),
RefreshDevices(Box<[Arc<DiskDevice>]>),
SetHash(io::Result<String>),
Flash(JoinHandle<anyhow::Result<(anyhow::Result<()>, Vec<Result<(), FlashError>>)>>),
Flash(JoinHandle<FlashResult>),
Reset,
}

Expand Down
24 changes: 12 additions & 12 deletions gtk/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,27 +134,27 @@ impl GtkUi {
ActiveView::Images => {
back.set_label(&fl!("cancel"));
back_ctx.remove_class("back-button");
back_ctx.remove_class(&gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
back_ctx.remove_class(gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);

next.set_label(&fl!("next"));
next.set_visible(true);
next.set_sensitive(true);
next_ctx.remove_class(&gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
next_ctx.add_class(&gtk::STYLE_CLASS_SUGGESTED_ACTION);
next_ctx.remove_class(gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
next_ctx.add_class(gtk::STYLE_CLASS_SUGGESTED_ACTION);

&self.content.image_view.view.container
}
ActiveView::Devices => {
next_ctx.remove_class(&gtk::STYLE_CLASS_SUGGESTED_ACTION);
next_ctx.add_class(&gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
next_ctx.remove_class(gtk::STYLE_CLASS_SUGGESTED_ACTION);
next_ctx.add_class(gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
next.set_sensitive(false);

let _ = state.back_event_tx.send(BackgroundEvent::RefreshDevices);
&self.content.devices_view.view.container
}
ActiveView::Flashing => {
match self.errorck(
&state,
state,
File::open(&*state.image_path.borrow()),
&fl!("iso-open-failed"),
) {
Expand All @@ -172,28 +172,28 @@ impl GtkUi {
}

back_ctx.remove_class("back-button");
back_ctx.add_class(&gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
back_ctx.add_class(gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);

next.set_visible(false);
&self.content.flash_view.view.container
}
ActiveView::Summary => {
back_ctx.remove_class(&gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
back_ctx.remove_class(gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
back.set_label(&fl!("flash-again"));

next_ctx.remove_class(&gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
next_ctx.remove_class(gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
next.set_visible(true);
next.set_label(&fl!("done"));
&self.content.summary_view.view.container
}
ActiveView::Error => {
back.set_label(&fl!("flash-again"));
back_ctx.remove_class(&gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
back_ctx.remove_class(gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);

next.set_visible(true);
next.set_label(&fl!("close"));
next_ctx.remove_class(&gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
next_ctx.remove_class(&gtk::STYLE_CLASS_SUGGESTED_ACTION);
next_ctx.remove_class(gtk::STYLE_CLASS_DESTRUCTIVE_ACTION);
next_ctx.remove_class(gtk::STYLE_CLASS_SUGGESTED_ACTION);

&self.content.error_view.view.container
}
Expand Down
11 changes: 3 additions & 8 deletions gtk/src/app/signals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ impl App {
None
};

ui.content.image_view.set_image(
&path,
image_size,
warning.as_ref().map(|x| x.as_str()),
);
ui.content.image_view.set_image(&path, image_size, warning.as_deref());
ui.content.image_view.set_hash_sensitive(true);
ui.header.next.set_sensitive(true);

Expand Down Expand Up @@ -148,7 +144,7 @@ impl App {
};

let label = cascade! {
gtk::Label::new(Some(&misc::device_label(&device)));
gtk::Label::new(Some(&misc::device_label(device)));
..set_justify(gtk::Justification::Right);
..style_context().add_class("bold");
};
Expand Down Expand Up @@ -209,8 +205,7 @@ impl App {
let tasks = tasks.as_mut().expect("no flash task");
let mut previous = tasks.previous.lock().expect("mutex lock");

for (id, &(ref pbar, ref label)) in flashing_devices.iter().enumerate()
{
for (id, (pbar, label)) in flashing_devices.iter().enumerate() {
let prev_values = &mut previous[id];
let progress = &tasks.progress[id];
let finished = &tasks.finished[id];
Expand Down
6 changes: 3 additions & 3 deletions gtk/src/app/views/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl DevicesView {

for row in list_.children() {
if let Ok(row) = row.downcast::<gtk::ListBoxRow>() {
if let Some(widget) = row.children().get(0) {
if let Some(widget) = row.children().first() {
if let Some(button) = widget.downcast_ref::<gtk::CheckButton>() {
button.set_active(button.get_sensitive() && state);
}
Expand Down Expand Up @@ -79,7 +79,7 @@ impl DevicesView {
.children()
.into_iter()
.filter_map(|row| row.downcast::<gtk::ListBoxRow>().ok())
.filter_map(|row| row.children().get(0).cloned())
.filter_map(|row| row.children().first().cloned())
.filter_map(|row| row.downcast::<gtk::CheckButton>().ok())
}

Expand All @@ -97,7 +97,7 @@ impl DevicesView {
for device in devices {
let valid_size = device.parent.size >= image_size;

let label = &misc::device_label(&device);
let label = &misc::device_label(device);

let size_str = bytesize::to_string(device.parent.size, true);
let name = if valid_size {
Expand Down
10 changes: 4 additions & 6 deletions gtk/src/app/views/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ impl ImageView {
let hash_label_clone = hash_label.clone();
let check_clone = check.clone();
hash.connect_changed(move |combo_box| {
let sensitive = match combo_box.active_text() {
Some(text) if text.as_str() != "None" => true,
_ => false,
};
let sensitive = combo_box.active_text().is_some_and(|text| text.as_str() != "None");

hash_label_clone.set_sensitive(sensitive);
check_clone.set_sensitive(sensitive);
});
Expand Down Expand Up @@ -136,9 +134,9 @@ impl ImageView {
let text = self.hash_label.text();
if !text.is_empty() {
let fg = if text.eq_ignore_ascii_case(hash) {
AttrColor::new_foreground(0, std::u16::MAX, 0)
AttrColor::new_foreground(0, u16::MAX, 0)
} else {
AttrColor::new_foreground(std::u16::MAX, 0, 0)
AttrColor::new_foreground(u16::MAX, 0, 0)
};
let attrs = AttrList::new();
attrs.insert(fg);
Expand Down
11 changes: 4 additions & 7 deletions gtk/src/flash.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::app::events::FlashResult;
use atomic::Atomic;
use dbus::arg::{OwnedFd, RefArg, Variant};
use dbus::blocking::{Connection, Proxy};
use dbus_udisks2::DiskDevice;
use futures::executor;
use libc;
use popsicle::{Progress, Task};
use std::cell::Cell;
use std::collections::HashMap;
Expand Down Expand Up @@ -88,7 +88,7 @@ impl FlashRequest {
FlashRequest { source: Some(source), destinations, status, progress, finished }
}

pub fn write(mut self) -> anyhow::Result<(anyhow::Result<()>, Vec<Result<(), FlashError>>)> {
pub fn write(mut self) -> FlashResult {
self.status.store(FlashStatus::Active, Ordering::SeqCst);

let source = self.source.take().unwrap();
Expand All @@ -103,10 +103,7 @@ impl FlashRequest {
res
}

fn write_inner<'a>(
&'a self,
source: File,
) -> anyhow::Result<(anyhow::Result<()>, Vec<Result<(), FlashError>>)> {
fn write_inner(&self, source: File) -> FlashResult {
// Unmount the devices beforehand.
for device in &self.destinations {
let _ = udisks_unmount(&device.parent.path);
Expand All @@ -130,7 +127,7 @@ impl FlashRequest {

let mut task = Task::new(source.into(), false);
for (i, file) in files.into_iter().enumerate() {
let progress = FlashProgress { request: &self, errors: errors_cells, id: i };
let progress = FlashProgress { request: self, errors: errors_cells, id: i };
task.subscribe(file.into(), (), progress);
}

Expand Down
3 changes: 1 addition & 2 deletions gtk/src/misc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use dbus_udisks2::DiskDevice;
use gdk;
use gtk::{self, prelude::*, SelectionData};

// Implements drag and drop support for a GTK widget.
Expand All @@ -19,7 +18,7 @@ where

// Get the dropped data, if possible, when the active drag is valid.
widget.connect_drag_drop(|view, ctx, _x, _y, time| {
ctx.list_targets().last().map_or(false, |ref target| {
ctx.list_targets().last().map_or(false, |target| {
view.drag_get_data(ctx, target, time);
true
})
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::{
use usb_disk_probe::stream::UsbDiskProbe;

#[derive(Debug, Error)]
#[cfg_attr(rustfmt, rustfmt_skip)]
#[rustfmt::skip]
pub enum ImageError {
#[error("image could not be opened: {}", why)]
Open { why: io::Error },
Expand All @@ -45,7 +45,7 @@ pub enum ImageError {
}

#[derive(Debug, Error)]
#[cfg_attr(rustfmt, rustfmt_skip)]
#[rustfmt::skip]
pub enum DiskError {
#[error("failed to fetch devices from USB device stream: {}", _0)]
DeviceStream(anyhow::Error),
Expand Down
8 changes: 4 additions & 4 deletions src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<P: Progress> Task<P> {
}
CopyEvent::SourceFailure(why) => {
for (device, pb) in self.state.values_mut() {
pb.message(&device, "E", &format!("{}", why));
pb.message(device, "E", &format!("{}", why));
pb.finish();
}

Expand All @@ -88,7 +88,7 @@ impl<P: Progress> Task<P> {
async fn seek(&mut self) -> anyhow::Result<()> {
for (path, pb) in self.state.values_mut() {
pb.set(0);
pb.message(&path, "S", "");
pb.message(path, "S", "");
}

self.image.seek(SeekFrom::Start(0)).await?;
Expand All @@ -106,7 +106,7 @@ impl<P: Progress> Task<P> {
async fn validate(&mut self, buf: &mut [u8]) -> anyhow::Result<()> {
for (path, pb) in self.state.values_mut() {
pb.set(0);
pb.message(&path, "V", "");
pb.message(path, "V", "");
}

let copy_bufs = &mut Vec::new();
Expand All @@ -128,7 +128,7 @@ impl<P: Progress> Task<P> {
}
ValidationEvent::SourceFailure(why) => {
for (path, pb) in self.state.values_mut() {
pb.message(&path, "E", &format!("error reading from source: {}", why));
pb.message(path, "E", &format!("error reading from source: {}", why));
pb.finish();
}

Expand Down

0 comments on commit 626389a

Please sign in to comment.