Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental: Tokio async #1183

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix clippy lints, group blocks declaration
remi-dupre committed Apr 12, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit bb0d25148e25bb7c31aa22f3937c8bdea899ce21
167 changes: 65 additions & 102 deletions src/blocks.rs
Original file line number Diff line number Diff line change
@@ -39,46 +39,7 @@ pub mod watson;
pub mod weather;
pub mod xrandr;

use self::apt::*;
use self::backlight::*;
use self::base_block::*;
use self::battery::*;
use self::bluetooth::*;
use self::cpu::*;
use self::custom::*;
use self::custom_dbus::*;
use self::disk_space::*;
use self::docker::*;
use self::focused_window::*;
use self::github::*;
use self::hueshift::*;
use self::ibus::*;
use self::kdeconnect::*;
use self::keyboard_layout::*;
use self::load::*;
#[cfg(feature = "maildir")]
use self::maildir::*;
use self::memory::*;
use self::music::*;
use self::net::*;
use self::networkmanager::*;
use self::notify::*;
#[cfg(feature = "notmuch")]
use self::notmuch::*;
use self::nvidia_gpu::*;
use self::pacman::*;
use self::pomodoro::*;
use self::sound::*;
use self::speedtest::*;
use self::taskwarrior::*;
use self::temperature::*;
use self::template::*;
use self::time::*;
use self::toggle::*;
use self::uptime::*;
use self::watson::*;
use self::weather::*;
use self::xrandr::*;
use self::base_block::{BaseBlock, BaseBlockConfig};

use std::time::Duration;

@@ -104,9 +65,9 @@ impl Default for Update {
}
}

impl Into<Update> for Duration {
fn into(self) -> Update {
Update::Every(self)
impl From<Duration> for Update {
fn from(val: Duration) -> Self {
Update::Every(val)
}
}

@@ -211,72 +172,74 @@ macro_rules! block {
}};
}

macro_rules! create_block_macro {
(
$id: expr, $name: expr, $block_config: expr, $shared_config: expr, $update_request: expr;
$(
$( #[cfg(feature = $feature: literal)] )?
$mod: ident :: $block: ident;
)*
) => {
match $name {
$(
$( #[cfg(feature = $feature)] )?
stringify!($mod) => {
pub use $mod::$block;
block!($block, $id, $block_config, $shared_config, $update_request)
},
)*
other => Err(BlockError(other.to_string(), "Unknown block!".to_string())),
}
};
}

pub fn create_block(
id: usize,
name: &str,
mut block_config: Value,
mut shared_config: SharedConfig,
update_request: Sender<Task>,
) -> Result<Box<dyn Block>> {
match name {
create_block_macro! {
id, name, block_config, shared_config, update_request;

// Please keep these in alphabetical order.
"apt" => block!(Apt, id, block_config, shared_config, update_request),
"backlight" => block!(Backlight, id, block_config, shared_config, update_request),
"battery" => block!(Battery, id, block_config, shared_config, update_request),
"bluetooth" => block!(Bluetooth, id, block_config, shared_config, update_request),
"cpu" => block!(Cpu, id, block_config, shared_config, update_request),
"custom" => block!(Custom, id, block_config, shared_config, update_request),
"custom_dbus" => block!(CustomDBus, id, block_config, shared_config, update_request),
"disk_space" => block!(DiskSpace, id, block_config, shared_config, update_request),
"docker" => block!(Docker, id, block_config, shared_config, update_request), ///////
"focused_window" => block!(
FocusedWindow,
id,
block_config,
shared_config,
update_request
),
"github" => block!(Github, id, block_config, shared_config, update_request),
"hueshift" => block!(Hueshift, id, block_config, shared_config, update_request),
"ibus" => block!(IBus, id, block_config, shared_config, update_request),
"kdeconnect" => block!(KDEConnect, id, block_config, shared_config, update_request),
"keyboard_layout" => block!(
KeyboardLayout,
id,
block_config,
shared_config,
update_request
),
"load" => block!(Load, id, block_config, shared_config, update_request),
#[cfg(feature = "maildir")]
"maildir" => block!(Maildir, id, block_config, shared_config, update_request),
"memory" => block!(Memory, id, block_config, shared_config, update_request),
"music" => block!(Music, id, block_config, shared_config, update_request),
"net" => block!(Net, id, block_config, shared_config, update_request),
"networkmanager" => block!(
NetworkManager,
id,
block_config,
shared_config,
update_request
),
"notify" => block!(Notify, id, block_config, shared_config, update_request),
#[cfg(feature = "notmuch")]
"notmuch" => block!(Notmuch, id, block_config, shared_config, update_request),
"nvidia_gpu" => block!(NvidiaGpu, id, block_config, shared_config, update_request),
"pacman" => block!(Pacman, id, block_config, shared_config, update_request),
"pomodoro" => block!(Pomodoro, id, block_config, shared_config, update_request),
"sound" => block!(Sound, id, block_config, shared_config, update_request),
"speedtest" => block!(SpeedTest, id, block_config, shared_config, update_request),
"taskwarrior" => block!(Taskwarrior, id, block_config, shared_config, update_request),
"temperature" => block!(Temperature, id, block_config, shared_config, update_request),
"template" => block!(Template, id, block_config, shared_config, update_request),
"time" => block!(Time, id, block_config, shared_config, update_request), /////////
"toggle" => block!(Toggle, id, block_config, shared_config, update_request),
"uptime" => block!(Uptime, id, block_config, shared_config, update_request),
"watson" => block!(Watson, id, block_config, shared_config, update_request),
"weather" => block!(Weather, id, block_config, shared_config, update_request),
"xrandr" => block!(Xrandr, id, block_config, shared_config, update_request),
other => Err(BlockError(other.to_string(), "Unknown block!".to_string())),
apt::Apt;
backlight::Backlight;
battery::Battery;
bluetooth::Bluetooth;
cpu::Cpu;
custom::Custom;
custom_dbus::CustomDBus;
disk_space::DiskSpace;
docker::Docker;
focused_window::FocusedWindow;
github::Github;
hueshift::Hueshift;
ibus::IBus;
kdeconnect::KDEConnect;
keyboard_layout::KeyboardLayout;
load::Load;
#[cfg(feature="maildir")] maildir::Maildir;
memory::Memory;
music::Music;
net::Net;
networkmanager::NetworkManager;
notify::Notify;
#[cfg(feature="notmuch")] notmuch::Notmuch;
nvidia_gpu::NvidiaGpu;
pacman::Pacman;
pomodoro::Pomodoro;
sound::Sound;
speedtest::SpeedTest;
taskwarrior::Taskwarrior;
temperature::Temperature;
template::Template;
time::Time;
toggle::Toggle;
uptime::Uptime;
watson::Watson;
weather::Weather;
xrandr::Xrandr;
}
}
2 changes: 2 additions & 0 deletions src/blocks/kdeconnect.rs
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ use crate::util::battery_level_to_icon;
use crate::widgets::text::TextWidget;
use crate::widgets::{I3BarWidget, State};

#[allow(clippy::upper_case_acronyms)]
pub struct KDEConnect {
id: usize,
device_id: String,
@@ -39,6 +40,7 @@ pub struct KDEConnect {
shared_config: SharedConfig,
}

#[allow(clippy::upper_case_acronyms)]
#[derive(Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields, default)]
pub struct KDEConnectConfig {
3 changes: 1 addition & 2 deletions src/blocks/music.rs
Original file line number Diff line number Diff line change
@@ -690,8 +690,7 @@ impl Block for Music {
if players.len() <= 1 && self.current_song_widget.is_empty() && self.hide_when_empty {
vec![]
} else if players.len() > 0 && !self.current_song_widget.is_empty() {
let mut elements: Vec<&dyn I3BarWidget> = Vec::new();
elements.push(&self.current_song_widget);
let mut elements: Vec<&dyn I3BarWidget> = vec![&self.current_song_widget];
if let Some(ref prev) = self.prev {
elements.push(prev);
}
8 changes: 3 additions & 5 deletions src/blocks/net.rs
Original file line number Diff line number Diff line change
@@ -226,8 +226,7 @@ impl NetworkDevice {
.filter(|dev| dev.addr_info.is_some())
.flat_map(|dev| &dev.addr_info)
.flatten()
.filter_map(|addr| addr.local.clone())
.next();
.find_map(|addr| addr.local.clone());

Ok(match ip {
Some(addr) => Some(addr),
@@ -261,8 +260,7 @@ impl NetworkDevice {
.filter(|dev| dev.addr_info.is_some())
.flat_map(|dev| &dev.addr_info)
.flatten()
.filter_map(|addr| addr.local.clone())
.next();
.find_map(|addr| addr.local.clone());

Ok(match ip {
Some(addr) => Some(addr),
@@ -615,7 +613,7 @@ impl Block for Net {
let na_string = "N/A".to_string();

let values = map!(
"ssid" => Value::from_string(ssid.clone().unwrap_or(na_string)),
"ssid" => Value::from_string(ssid.unwrap_or(na_string)),
"signal_strength" => Value::from_integer(signal.unwrap_or(0)).percents(),
"frequency" => Value::from_float(freq.unwrap_or(0.)).hertz(),
"bitrate" => Value::from_string(self.bitrate.clone().unwrap_or_else(|| empty_string.clone())), // TODO: not a String?
6 changes: 3 additions & 3 deletions src/blocks/networkmanager.rs
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ enum DeviceType {
Wifi,
Modem,
Bridge,
TUN,
Tun,
Wireguard,
}

@@ -102,7 +102,7 @@ impl From<u32> for DeviceType {
2 => DeviceType::Wifi,
8 => DeviceType::Modem,
13 => DeviceType::Bridge,
16 => DeviceType::TUN,
16 => DeviceType::Tun,
29 => DeviceType::Wireguard,
_ => DeviceType::Unknown,
}
@@ -116,7 +116,7 @@ impl DeviceType {
DeviceType::Wifi => Some("net_wireless".to_string()),
DeviceType::Modem => Some("net_modem".to_string()),
DeviceType::Bridge => Some("net_bridge".to_string()),
DeviceType::TUN => Some("net_bridge".to_string()),
DeviceType::Tun => Some("net_bridge".to_string()),
DeviceType::Wireguard => Some("net_vpn".to_string()),
_ => None,
}
3 changes: 1 addition & 2 deletions src/blocks/nvidia_gpu.rs
Original file line number Diff line number Diff line change
@@ -330,8 +330,7 @@ impl Block for NvidiaGpu {
}

fn view(&self) -> Vec<&dyn I3BarWidget> {
let mut widgets: Vec<&dyn I3BarWidget> = Vec::new();
widgets.push(&self.name_widget);
let mut widgets: Vec<&dyn I3BarWidget> = vec![&self.name_widget];

if self.gpu_enabled {
if let Some(ref utilization_widget) = self.show_utilization {
8 changes: 4 additions & 4 deletions src/blocks/pacman.rs
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ pub enum Watched {
None,
Pacman,
/// cf `Pacman::aur_command`
AUR(String),
Aur(String),
/// cf `Pacman::aur_command`
Both(String),
}
@@ -121,7 +121,7 @@ impl PacmanConfig {
"pacman",
"{aur} found in format string but no aur_command supplied",
)?;
Ok(Watched::AUR(aur_command))
Ok(Watched::Aur(aur_command))
} else {
Ok(Watched::None)
}
@@ -338,7 +338,7 @@ impl Block for Pacman {

(formatting_map, warning, critical, pacman_count)
}
Watched::AUR(aur_command) => {
Watched::Aur(aur_command) => {
let aur_available_updates = get_aur_available_updates(&aur_command)?;
let aur_count = get_update_count(&aur_available_updates);
let formatting_map = map!(
@@ -446,7 +446,7 @@ mod tests {
Some("aur cmd".to_string()),
);
assert!(watched.is_ok());
assert_eq!(watched.unwrap(), Watched::AUR("aur cmd".to_string()));
assert_eq!(watched.unwrap(), Watched::Aur("aur cmd".to_string()));
let watched = PacmanConfig::watched(
"foo {pacman} {aur} bar",
"foo {pacman} {aur} bar",