Skip to content

Commit

Permalink
Fix Clippy lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed Oct 21, 2023
1 parent 1594e09 commit 2f74df5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
14 changes: 8 additions & 6 deletions src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -102,7 +104,7 @@ pub struct Greeter {
pub greeting: Option<String>,
pub message: Option<String>,

pub power_commands: Menu<Power>,
pub powers: Menu<Power>,
pub power_command: Option<Command>,
pub power_command_notify: Arc<Notify>,
pub power_setsid: bool,
Expand All @@ -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,
Expand All @@ -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,
};

Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ pub async fn handle(greeter: Arc<RwLock<Greeter>>, 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;
}
}
}
Expand All @@ -116,8 +116,8 @@ pub async fn handle(greeter: Arc<RwLock<Greeter>>, 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;
}
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ pub async fn handle(greeter: Arc<RwLock<Greeter>>, 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);
Expand Down
2 changes: 1 addition & 1 deletion src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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), .. }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub async fn draw(greeter: Arc<RwLock<Greeter>>, 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(),
Expand Down
2 changes: 1 addition & 1 deletion src/ui/power.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/ui/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}
Expand Down

0 comments on commit 2f74df5

Please sign in to comment.