Skip to content

Commit

Permalink
Fixed a few inconsistencies with the session matcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed Oct 21, 2023
1 parent 1812f1e commit 9aa63fa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl SessionType {
}
}

#[derive(SmartDefault)]
#[derive(SmartDefault, Clone)]
pub struct Session {
pub name: String,
pub command: String,
Expand Down
7 changes: 6 additions & 1 deletion src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ impl Ipc {
let _ = command;
let _ = env;

crate::exit(greeter, AuthStatus::Success).await;
self
.send(Request::StartSession {
cmd: vec!["true".to_string()],
env: vec![],
})
.await;
}
}
}
Expand Down
33 changes: 16 additions & 17 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ pub async fn handle(greeter: Arc<RwLock<Greeter>>, events: &mut Events, ipc: Ipc
crate::exit(&mut greeter, AuthStatus::Cancel).await;
}

KeyEvent { code: KeyCode::Esc, .. } => {
Ipc::cancel(&mut greeter).await;
greeter.reset(false).await;
}
KeyEvent { code: KeyCode::Esc, .. } => match greeter.mode {
Mode::Users | Mode::Command | Mode::Sessions | Mode::Power => {
greeter.mode = greeter.previous_mode;
}

_ => {
Ipc::cancel(&mut greeter).await;
greeter.reset(false).await;
}
},

KeyEvent { code: KeyCode::Left, .. } => greeter.cursor_offset -= 1,
KeyEvent { code: KeyCode::Right, .. } => greeter.cursor_offset += 1,
Expand Down Expand Up @@ -170,9 +176,7 @@ pub async fn handle(greeter: Arc<RwLock<Greeter>>, events: &mut Events, ipc: Ipc
}

Mode::Command => {
let cmd = &greeter.command;

greeter.selected_session = greeter.sessions.iter().position(|Session { command, .. }| Some(command) == cmd.as_ref()).unwrap_or(0);
greeter.selected_session = 0;
greeter.command = Some(greeter.new_command.clone());

if greeter.remember_session {
Expand All @@ -195,22 +199,18 @@ pub async fn handle(greeter: Arc<RwLock<Greeter>>, events: &mut Events, ipc: Ipc
}

Mode::Sessions => {
let session = match greeter.sessions.get(greeter.selected_session) {
Some(Session { name, path, command, .. }) => Some((name.clone(), path.clone(), command.clone())),
_ => None,
};

if let Some((_, path, command)) = session {
greeter.session_path = path.clone();
let session = greeter.sessions.get(greeter.selected_session).cloned();

if let Some(Session { path, command, .. }) = session {
if greeter.remember_session {
if let Some(path) = path {
write_last_session_path(&path);
if let Some(ref path) = path {
write_last_session_path(path);
}

write_last_session(&command);
}

greeter.session_path = path.clone();
greeter.command = Some(command.clone());
}

Expand Down Expand Up @@ -308,7 +308,6 @@ async fn validate_username(greeter: &mut Greeter, ipc: &Ipc) {
}

if let Ok(command) = get_last_user_session(&greeter.username) {
greeter.selected_session = greeter.sessions.iter().position(|session| session.command == command).unwrap_or(0);
greeter.command = Some(command);
}
}
Expand Down

0 comments on commit 9aa63fa

Please sign in to comment.