From 2f74df5cc2127f1c1b888c585e7f16d48b86886e Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Sat, 21 Oct 2023 16:02:12 +0200 Subject: [PATCH] Fix Clippy lints. --- src/greeter.rs | 14 ++++++++------ src/ipc.rs | 2 +- src/keyboard.rs | 10 +++++----- src/power.rs | 2 +- src/ui/mod.rs | 2 +- src/ui/power.rs | 2 +- src/ui/sessions.rs | 6 +++--- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/greeter.rs b/src/greeter.rs index 297e87f..828cfe1 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -22,7 +22,9 @@ use tokio::{ use zeroize::Zeroize; use crate::{ - info::{get_issue, get_last_session, get_last_session_path, get_last_user_name, get_last_user_session, get_last_user_session_path, get_last_user_username, get_min_max_uids, get_users}, + info::{ + get_issue, get_last_session, get_last_session_path, get_last_user_name, get_last_user_session, get_last_user_session_path, get_last_user_username, get_min_max_uids, get_sessions, get_users, + }, power::PowerOption, ui::{ common::menu::Menu, @@ -102,7 +104,7 @@ pub struct Greeter { pub greeting: Option, pub message: Option, - pub power_commands: Menu, + pub powers: Menu, pub power_command: Option, pub power_command_notify: Arc, pub power_setsid: bool, @@ -124,7 +126,7 @@ impl Greeter { greeter.set_locale(); - greeter.power_commands = Menu { + greeter.powers = Menu { title: fl!("title_power"), options: Default::default(), selected: 0, @@ -133,7 +135,7 @@ impl Greeter { greeter.parse_options().await; greeter.sessions = Menu { title: fl!("title_session"), - options: crate::info::get_sessions(&greeter).unwrap_or_default(), + options: get_sessions(&greeter).unwrap_or_default(), selected: 0, }; @@ -421,13 +423,13 @@ impl Greeter { self.greeting = get_issue(); } - self.power_commands.options.push(Power { + self.powers.options.push(Power { action: PowerOption::Shutdown, label: fl!("shutdown"), command: self.config().opt_str("power-shutdown"), }); - self.power_commands.options.push(Power { + self.powers.options.push(Power { action: PowerOption::Reboot, label: fl!("reboot"), command: self.config().opt_str("power-reboot"), diff --git a/src/ipc.rs b/src/ipc.rs index b347af2..50abc81 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -128,7 +128,7 @@ impl Ipc { if let Some(Session { session_type, .. }) = session { if *session_type != SessionType::None { - env.push(format!("XDG_SESSION_TYPE={}", session_type.to_xdg_session_type())); + env.push(format!("XDG_SESSION_TYPE={}", session_type.as_xdg_session_type())); } if *session_type == SessionType::X11 { diff --git a/src/keyboard.rs b/src/keyboard.rs index f80837f..d058709 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -96,8 +96,8 @@ pub async fn handle(greeter: Arc>, events: &mut Events, ipc: Ipc } if let Mode::Power = greeter.mode { - if greeter.power_commands.selected > 0 { - greeter.power_commands.selected -= 1; + if greeter.powers.selected > 0 { + greeter.powers.selected -= 1; } } } @@ -116,8 +116,8 @@ pub async fn handle(greeter: Arc>, events: &mut Events, ipc: Ipc } if let Mode::Power = greeter.mode { - if greeter.power_commands.selected < greeter.power_commands.options.len() - 1 { - greeter.power_commands.selected += 1; + if greeter.powers.selected < greeter.powers.options.len() - 1 { + greeter.powers.selected += 1; } } } @@ -218,7 +218,7 @@ pub async fn handle(greeter: Arc>, events: &mut Events, ipc: Ipc } Mode::Power => { - let power_command = greeter.power_commands.options.get(greeter.power_commands.selected).cloned(); + let power_command = greeter.powers.options.get(greeter.powers.selected).cloned(); if let Some(command) = power_command { power(&mut greeter, command.action); diff --git a/src/power.rs b/src/power.rs index 8153fd5..beac722 100644 --- a/src/power.rs +++ b/src/power.rs @@ -12,7 +12,7 @@ pub enum PowerOption { } pub fn power(greeter: &mut Greeter, option: PowerOption) { - let command = match greeter.power_commands.options.iter().find(|opt| opt.action == option) { + let command = match greeter.powers.options.iter().find(|opt| opt.action == option) { None => None, Some(Power { command: Some(args), .. }) => { diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 512ade0..a5865bc 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -111,7 +111,7 @@ pub async fn draw(greeter: Arc>, terminal: &mut Term) -> Result< let cursor = match greeter.mode { Mode::Command => self::command::draw(&mut greeter, f).ok(), Mode::Sessions => greeter.sessions.draw(&greeter, f).ok(), - Mode::Power => greeter.power_commands.draw(&greeter, f).ok(), + Mode::Power => greeter.powers.draw(&greeter, f).ok(), Mode::Users => greeter.users.draw(&greeter, f).ok(), Mode::Processing => self::processing::draw(&mut greeter, f).ok(), _ => self::prompt::draw(&mut greeter, f).ok(), diff --git a/src/ui/power.rs b/src/ui/power.rs index 44acb4d..b1f6d09 100644 --- a/src/ui/power.rs +++ b/src/ui/power.rs @@ -1,6 +1,6 @@ use crate::{power::PowerOption, ui::common::menu::MenuItem}; -#[derive(Default, Clone)] +#[derive(SmartDefault, Clone)] pub struct Power { pub action: PowerOption, pub label: String, diff --git a/src/ui/sessions.rs b/src/ui/sessions.rs index bf6e1ab..4247475 100644 --- a/src/ui/sessions.rs +++ b/src/ui/sessions.rs @@ -6,17 +6,17 @@ use super::common::menu::MenuItem; pub enum SessionType { X11, Wayland, - TTY, + Tty, #[default] None, } impl SessionType { - pub fn to_xdg_session_type(&self) -> &'static str { + pub fn as_xdg_session_type(&self) -> &'static str { match self { SessionType::X11 => "x11", SessionType::Wayland => "wayland", - SessionType::TTY => "tty", + SessionType::Tty => "tty", SessionType::None => "unspecified", } }