Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 authored and jackpot51 committed Oct 8, 2021
1 parent 0bbeb12 commit cdafbb6
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 55 deletions.
14 changes: 7 additions & 7 deletions gtk/src/dialogs/fwupd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use std::sync::{mpsc::Sender, Arc};

/// An instance of the firmware update dialog specific to fwupd-managed system devices.
pub struct FwupdDialog<'a> {
pub device: &'a FwupdDevice,
pub entity: Entity,
pub has_battery: bool,
pub latest: &'a str,
pub device: &'a FwupdDevice,
pub entity: Entity,
pub has_battery: bool,
pub latest: &'a str,
pub needs_reboot: bool,
pub releases: &'a [FwupdRelease],
pub sender: &'a Sender<FirmwareEvent>,
pub widgets: &'a DeviceWidget,
pub releases: &'a [FwupdRelease],
pub sender: &'a Sender<FirmwareEvent>,
pub widgets: &'a DeviceWidget,
}

impl<'a> FwupdDialog<'a> {
Expand Down
12 changes: 6 additions & 6 deletions gtk/src/dialogs/system76.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::sync::mpsc::Sender;

/// An instance of the firmware update dialog specific to system76-managed system devices.
pub struct System76Dialog<'a> {
pub changelog: &'a System76Changelog,
pub digest: &'a System76Digest,
pub entity: Entity,
pub changelog: &'a System76Changelog,
pub digest: &'a System76Digest,
pub entity: Entity,
pub has_battery: bool,
pub latest: &'a str,
pub sender: &'a Sender<FirmwareEvent>,
pub widgets: &'a DeviceWidget,
pub latest: &'a str,
pub sender: &'a Sender<FirmwareEvent>,
pub widgets: &'a DeviceWidget,
}

impl<'a> System76Dialog<'a> {
Expand Down
14 changes: 9 additions & 5 deletions gtk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ pub(crate) enum ActivateEvent {

/// The complete firmware manager, as a widget structure
pub struct FirmwareWidget {
container: gtk::Container,
sender: Sender<FirmwareEvent>,
container: gtk::Container,
sender: Sender<FirmwareEvent>,
background: Option<JoinHandle<()>>,
is_admin: bool,
is_admin: bool,
}

/// An event which the GTK UI may propagate to the event loop in the main context.
Expand Down Expand Up @@ -206,7 +206,9 @@ impl FirmwareWidget {
}

/// Returns the primary container widget of this structure.
pub fn container(&self) -> &gtk::Container { self.container.upcast_ref::<gtk::Container>() }
pub fn container(&self) -> &gtk::Container {
self.container.upcast_ref::<gtk::Container>()
}

/// The main event loop for this widget.
///
Expand Down Expand Up @@ -423,7 +425,9 @@ impl FirmwareWidget {
}

impl Default for FirmwareWidget {
fn default() -> Self { Self::new() }
fn default() -> Self {
Self::new()
}
}

impl Drop for FirmwareWidget {
Expand Down
20 changes: 10 additions & 10 deletions gtk/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ use std::sync::mpsc::Sender;
/// Manages all state and state interactions with the UI.
pub(crate) struct State {
/// Components that have been associated with entities.
pub(crate) components: Components,
pub(crate) components: Components,
/// All devices will be created as an entity here
pub(crate) entities: Entities,
pub(crate) entities: Entities,
/// If this system has a battery.
pub(crate) has_battery: bool,
pub(crate) has_battery: bool,
/// Sends events to the progress signal
pub(crate) progress_sender: Sender<ActivateEvent>,
/// A sender to send firmware requests to the background thread
pub(crate) sender: Sender<FirmwareEvent>,
pub(crate) sender: Sender<FirmwareEvent>,
/// Events to be processed by the main event loop
pub(crate) ui_sender: glib::Sender<Event>,
pub(crate) ui_sender: glib::Sender<Event>,
/// Widgets that will be actively managed.
pub(crate) widgets: Widgets,
pub(crate) widgets: Widgets,
}

/// GTK widgets that are interacted with throughout the lifetime of the firmware widget.
pub(crate) struct Widgets {
/// Controls the display of error messages.
pub(crate) info_bar: gtk::InfoBar,
pub(crate) info_bar: gtk::InfoBar,
/// Error messages will be set in this label.
pub(crate) info_bar_label: gtk::Label,
/// Controls which view to display in the UI
pub(crate) stack: gtk::Stack,
pub(crate) stack: gtk::Stack,
/// The devices view shows a list of all supported devices.
pub(crate) view_devices: DevicesView,
pub(crate) view_devices: DevicesView,
/// The empty view is displayed when a scan found no devices.
pub(crate) view_empty: EmptyView,
pub(crate) view_empty: EmptyView,
}

/// Components are optional pieces of data that are assigned to entities
Expand Down
8 changes: 4 additions & 4 deletions gtk/src/views/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use std::num::NonZeroU8;
#[derive(Shrinkwrap)]
pub struct DevicesView {
#[shrinkwrap(main_field)]
container: gtk::Container,
container: gtk::Container,
device_firmware: gtk::ListBox,
device_header: gtk::Label,
sg: gtk::SizeGroup,
device_header: gtk::Label,
sg: gtk::SizeGroup,
system_firmware: gtk::ListBox,
system_header: gtk::Label,
system_header: gtk::Label,
}

impl DevicesView {
Expand Down
4 changes: 3 additions & 1 deletion gtk/src/views/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use gtk::prelude::*;
pub struct EmptyView(gtk::Container);

impl EmptyView {
pub fn new() -> Self { Self(error_view("firmware-manager-symbolic", &fl!("view-empty"))) }
pub fn new() -> Self {
Self(error_view("firmware-manager-symbolic", &fl!("view-empty")))
}
}

/// View displayed to users who lack administrative permissions.
Expand Down
12 changes: 6 additions & 6 deletions gtk/src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use gtk::prelude::*;
#[derive(Shrinkwrap)]
pub struct DeviceWidgetStack {
#[shrinkwrap(main_field)]
pub stack: gtk::Stack,
pub button: gtk::Button,
pub stack: gtk::Stack,
pub button: gtk::Button,
pub progress: gtk::ProgressBar,
pub waiting: gtk::Label,
pub waiting: gtk::Label,
}

impl DeviceWidgetStack {
Expand All @@ -33,9 +33,9 @@ pub struct DeviceWidget {
#[shrinkwrap(main_field)]
pub container: gtk::Container,
pub event_box: gtk::EventBox,
pub revealer: gtk::Revealer,
pub label: gtk::Label,
pub stack: DeviceWidgetStack,
pub revealer: gtk::Revealer,
pub label: gtk::Label,
pub stack: DeviceWidgetStack,
}

impl DeviceWidget {
Expand Down
12 changes: 6 additions & 6 deletions src/fwupd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use std::cmp::Ordering;
#[derive(Debug)]
pub struct FwupdSignal {
/// Generic information about the firmware.
pub info: FirmwareInfo,
pub info: FirmwareInfo,
/// Information specific to fwupd devices.
pub device: FwupdDevice,
pub device: FwupdDevice,
/// Tracks whether the firmware is upgradeable or not.
pub upgradeable: bool,
/// All releases that were found for the firmware.
pub releases: Vec<FwupdRelease>,
pub releases: Vec<FwupdRelease>,
}

/// Scan for supported devices from the fwupd DBus daemon.
Expand All @@ -40,9 +40,9 @@ pub fn fwupd_scan<F: Fn(FirmwareSignal)>(fwupd: &FwupdClient, sender: F) {

sender(FirmwareSignal::Fwupd(FwupdSignal {
info: FirmwareInfo {
name: [&device.vendor, " ", &device.name].concat().into(),
current: device.version.clone(),
latest: Some(latest.version.clone()),
name: [&device.vendor, " ", &device.name].concat().into(),
current: device.version.clone(),
latest: Some(latest.version.clone()),
install_duration: latest.install_duration,
},
device,
Expand Down
28 changes: 21 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,26 @@ pub struct Entities {

impl Entities {
/// Associate this entity as a system device
pub fn associate_system(&mut self, entity: Entity) { self.system.insert(entity, ()); }
pub fn associate_system(&mut self, entity: Entity) {
self.system.insert(entity, ());
}

/// Clear all entities from the world
///
/// Entities are automatically erased from secondary storages on lookup
pub fn clear(&mut self) { self.entities.clear(); }
pub fn clear(&mut self) {
self.entities.clear();
}

/// Create a new device entity.
pub fn create(&mut self) -> Entity { self.entities.insert(()) }
pub fn create(&mut self) -> Entity {
self.entities.insert(())
}

/// Check if an entity is a system device
pub fn is_system(&self, entity: Entity) -> bool { self.system.contains_key(entity) }
pub fn is_system(&self, entity: Entity) -> bool {
self.system.contains_key(entity)
}
}

/// Signals that the firmware manager core will send to a frontend.
Expand Down Expand Up @@ -266,13 +274,19 @@ fn read_trimmed(path: &str) -> io::Result<String> {
}

/// Convenience function for reading the product name from the DMI ID information.
fn product_name() -> io::Result<String> { read_trimmed("/sys/class/dmi/id/product_name") }
fn product_name() -> io::Result<String> {
read_trimmed("/sys/class/dmi/id/product_name")
}

/// Convenience function for reading the product version from the DMI ID information.
fn product_version() -> io::Result<String> { read_trimmed("/sys/class/dmi/id/product_version") }
fn product_version() -> io::Result<String> {
read_trimmed("/sys/class/dmi/id/product_version")
}

/// Convenience function for reading the system vendor from the DMI ID information.
fn sys_vendor() -> io::Result<String> { read_trimmed("/sys/class/dmi/id/sys_vendor") }
fn sys_vendor() -> io::Result<String> {
read_trimmed("/sys/class/dmi/id/sys_vendor")
}

/// Creates a string identifying system firmware by the board vendor and name.
pub(crate) fn system_board_identity() -> io::Result<String> {
Expand Down
4 changes: 3 additions & 1 deletion src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ fn time_exceeded(last: u64, current: u64, limit: u64) -> bool {
}

/// Convenience function for fetching the path to the timestamp file.
fn timestamp_path() -> Result<PathBuf, Error> { cache::cache("last_refresh").map_err(Error::Cache) }
fn timestamp_path() -> Result<PathBuf, Error> {
cache::cache("last_refresh").map_err(Error::Cache)
}

#[cfg(test)]
mod tests {
Expand Down
8 changes: 6 additions & 2 deletions src/version_sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub fn sort_versions_reverse<V: Versioned>(input: &mut [V]) {
}

impl Versioned for fwupd_dbus::Release {
fn version(&self) -> &str { &self.version }
fn version(&self) -> &str {
&self.version
}
}

#[cfg(test)]
Expand All @@ -30,7 +32,9 @@ mod tests {
}

impl Versioned for Foo {
fn version(&self) -> &str { &self.version }
fn version(&self) -> &str {
&self.version
}
}

fn test_input() -> Vec<Foo> {
Expand Down

0 comments on commit cdafbb6

Please sign in to comment.