Skip to content

Commit

Permalink
refactor: fix some strict clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeStanger committed Dec 29, 2024
1 parent 87a6523 commit 5136637
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 60 deletions.
84 changes: 39 additions & 45 deletions src/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,26 @@ impl Clients {

#[cfg(feature = "workspaces")]
pub fn workspaces(&mut self) -> ClientResult<dyn compositor::WorkspaceClient> {
let client = match &self.workspaces {
Some(workspaces) => workspaces.clone(),
None => {
let client = compositor::Compositor::create_workspace_client(self)?;
self.workspaces.replace(client.clone());
client
}
let client = if let Some(workspaces) = &self.workspaces {
workspaces.clone()
} else {
let client = compositor::Compositor::create_workspace_client(self)?;
self.workspaces.replace(client.clone());
client
};

Ok(client)
}

#[cfg(feature = "sway")]
pub fn sway(&mut self) -> ClientResult<sway::Client> {
let client = match &self.sway {
Some(client) => client.clone(),
None => {
let client = await_sync(async { sway::Client::new().await })?;
let client = Arc::new(client);
self.sway.replace(client.clone());
client
}
let client = if let Some(client) = &self.sway {
client.clone()
} else {
let client = await_sync(async { sway::Client::new().await })?;
let client = Arc::new(client);
self.sway.replace(client.clone());
client
};

Ok(client)
Expand Down Expand Up @@ -134,55 +132,51 @@ impl Clients {

#[cfg(feature = "network_manager")]
pub fn network_manager(&mut self) -> ClientResult<networkmanager::Client> {
match &self.network_manager {
Some(client) => Ok(client.clone()),
None => {
let client = networkmanager::create_client()?;
self.network_manager = Some(client.clone());
Ok(client)
}
if let Some(client) = &self.network_manager {
Ok(client.clone())
} else {
let client = networkmanager::create_client()?;
self.network_manager = Some(client.clone());
Ok(client)
}
}

#[cfg(feature = "notifications")]
pub fn notifications(&mut self) -> ClientResult<swaync::Client> {
let client = match &self.notifications {
Some(client) => client.clone(),
None => {
let client = await_sync(async { swaync::Client::new().await })?;
let client = Arc::new(client);
self.notifications.replace(client.clone());
client
}
let client = if let Some(client) = &self.notifications {
client.clone()
} else {
let client = await_sync(async { swaync::Client::new().await })?;
let client = Arc::new(client);
self.notifications.replace(client.clone());
client
};

Ok(client)
}

#[cfg(feature = "tray")]
pub fn tray(&mut self) -> ClientResult<tray::Client> {
let client = match &self.tray {
Some(client) => client.clone(),
None => {
let client = await_sync(async { tray::Client::new().await })?;
let client = Arc::new(client);
self.tray.replace(client.clone());
client
}
let client = if let Some(client) = &self.tray {
client.clone()
} else {
let client = await_sync(async { tray::Client::new().await })?;
let client = Arc::new(client);
self.tray.replace(client.clone());
client
};

Ok(client)
}

#[cfg(feature = "upower")]
pub fn upower(&mut self) -> ClientResult<zbus::fdo::PropertiesProxy<'static>> {
let client = match &self.upower {
Some(client) => client.clone(),
None => {
let client = await_sync(async { upower::create_display_proxy().await })?;
self.upower.replace(client.clone());
client
}
let client = if let Some(client) = &self.upower {
client.clone()
} else {
let client = await_sync(async { upower::create_display_proxy().await })?;
self.upower.replace(client.clone());
client
};

Ok(client)
Expand Down
6 changes: 3 additions & 3 deletions src/gtk_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ pub trait IronbarLabelExt {

impl IronbarLabelExt for Label {
fn set_label_escaped(&self, label: &str) {
if !label.contains("<span") {
self.set_label(&markup_escape_text(label));
} else {
if label.contains("<span") {
self.set_label(label);
} else {
self.set_label(&markup_escape_text(label));
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/modules/keys.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use color_eyre::Result;
use gtk::prelude::*;
use serde::Deserialize;
use std::ops::Deref;
use tokio::sync::mpsc;

use super::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
Expand Down Expand Up @@ -183,19 +182,19 @@ impl Module<gtk::Box> for KeysModule {
if self.show_caps {
caps.add_class("key");
caps.add_class("caps");
container.add(caps.deref());
container.add(&*caps);
}

if self.show_num {
num.add_class("key");
num.add_class("num");
container.add(num.deref());
container.add(&*num);
}

if self.show_scroll {
scroll.add_class("key");
scroll.add_class("scroll");
container.add(scroll.deref());
container.add(&*scroll);
}

let icons = self.icons;
Expand Down
9 changes: 4 additions & 5 deletions src/modules/music/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::cell::RefMut;
use std::ops::Deref;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
Expand Down Expand Up @@ -200,8 +199,8 @@ impl Module<Button> for MusicModule {
label.truncate(truncate);
}

button_contents.add(icon_pause.deref());
button_contents.add(icon_play.deref());
button_contents.add(&*icon_pause);
button_contents.add(&*icon_play);
button_contents.add(&label);

{
Expand Down Expand Up @@ -328,7 +327,7 @@ impl Module<Button> for MusicModule {
volume_icon.add_class("icon");

volume_box.pack_start(&volume_slider, true, true, 0);
volume_box.pack_end(volume_icon.deref(), false, false, 0);
volume_box.pack_end(&*volume_icon, false, false, 0);

main_container.add(&album_image);
main_container.add(&info_box);
Expand Down Expand Up @@ -559,7 +558,7 @@ impl IconPrefixedLabel {
icon.add_class("icon-box");
label.add_class("label");

container.add(icon.deref());
container.add(&*icon);
container.add(&label);

Self { label, container }
Expand Down
3 changes: 1 addition & 2 deletions src/modules/tray/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ impl Module<gtk::Box> for TrayModule {
) -> Result<ModuleParts<gtk::Box>> {
let orientation = self
.direction
.map(Orientation::from)
.unwrap_or(info.bar_position.orientation());
.map_or(info.bar_position.orientation(), Orientation::from);

// We use a `Box` here instead of the (supposedly correct) `MenuBar`
// as the latter has issues on Sway with menus focus-stealing from the bar.
Expand Down
2 changes: 1 addition & 1 deletion src/modules/workspaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn reorder_workspaces(container: &gtk::Box, sort_order: SortOrder) {
let label = if sort_order == SortOrder::Label {
child
.downcast_ref::<gtk::Button>()
.and_then(|button| button.label())
.and_then(ButtonExt::label)
.unwrap_or_else(|| child.widget_name())
} else {
child.widget_name()
Expand Down

0 comments on commit 5136637

Please sign in to comment.