Compare commits

...

2 Commits

Author SHA1 Message Date
Jan-Bulthuis 0ae682ef8b Made exit indirect and added timeout after successfull login 2025-02-21 20:49:38 +01:00
Jan-Bulthuis d94aa35576 Updated init command 2025-02-21 20:46:10 +01:00
3 changed files with 19 additions and 11 deletions

View File

@ -52,7 +52,7 @@ pub fn gather_sessions(user: &User) -> Vec<Session> {
true => gather_hm_sessions(&hm_profile),
false => vec![Session {
name: String::from("Shell"),
init: user.shell.clone(),
init: user.shell.to_str().unwrap().to_owned(),
}],
}
}
@ -105,7 +105,11 @@ fn gather_session_data(path: &PathBuf) -> Session {
let session_path = path.join("session");
let name = read_to_string(session_path.join("name")).unwrap();
let init = session_path.join("init");
let init = format!(
"{} && {}",
path.join("activate").display(),
session_path.join("init").display()
);
Session { name, init }
}

View File

@ -30,7 +30,7 @@ pub fn login(
return Ok(LoginResult::Success);
} else {
starting = true;
let cmd = vec![session.init.to_str().unwrap().to_owned()];
let cmd = vec![session.init.clone()];
let env = vec![];
Request::StartSession { cmd, env }.write_to(&mut stream)?;
}

View File

@ -29,7 +29,7 @@ fn main() -> io::Result<()> {
}
struct App {
start_time: Instant,
exit: bool,
exit_time: Option<Instant>,
error: bool,
focus: Focus,
status: Status,
@ -111,7 +111,7 @@ impl Display for User {
#[derive(PartialEq, Eq, Clone)]
struct Session {
name: String,
init: PathBuf,
init: String,
}
impl Display for Session {
@ -123,7 +123,7 @@ impl Display for Session {
impl Default for App {
fn default() -> Self {
let start_time = Instant::now();
let exit = false;
let exit_time = None;
let error = false;
let focus = Focus::User;
let status = Status::Nothing;
@ -141,7 +141,7 @@ impl Default for App {
Self {
start_time,
exit,
exit_time,
error,
focus,
status,
@ -155,7 +155,10 @@ impl Default for App {
impl App {
pub fn run(&mut self, terminal: &mut DefaultTerminal) -> io::Result<()> {
self.start_time = Instant::now();
while !self.exit {
while match self.exit_time {
Some(exit_time) => Instant::now() < exit_time,
None => true,
} {
terminal.draw(|frame| self.draw(frame))?;
self.handle_events()?;
}
@ -307,7 +310,7 @@ impl App {
}
fn exit(&mut self) {
self.exit = true;
self.exit_time = Some(Instant::now());
}
fn submit(&mut self) {
@ -325,11 +328,12 @@ impl App {
{
LoginResult::Success => {
self.error = false;
self.status = Status::Success
self.status = Status::Success;
self.exit_time = Some(Instant::now() + Duration::from_millis(300));
}
LoginResult::Failure => {
self.error = true;
self.status = Status::Error
self.status = Status::Error;
}
};
}