Exit when session is started
This commit is contained in:
parent
f374bd1cc5
commit
6b1aded756
1 changed files with 48 additions and 21 deletions
69
src/main.rs
69
src/main.rs
|
|
@ -138,8 +138,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
sessions
|
sessions
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{:?}", sessions);
|
|
||||||
|
|
||||||
let flags = Flags { users, sessions };
|
let flags = Flags { users, sessions };
|
||||||
|
|
||||||
let settings = Settings::default()
|
let settings = Settings::default()
|
||||||
|
|
@ -172,9 +170,7 @@ async fn request(socket: Arc<UnixStream>, request: Request) -> Message {
|
||||||
let mut bytes = Vec::<u8>::with_capacity(4096);
|
let mut bytes = Vec::<u8>::with_capacity(4096);
|
||||||
match socket.try_read_buf(&mut bytes) {
|
match socket.try_read_buf(&mut bytes) {
|
||||||
Ok(0) => break,
|
Ok(0) => break,
|
||||||
Ok(count) => {
|
Ok(_count) => {
|
||||||
log::info!("read {} bytes", count);
|
|
||||||
|
|
||||||
let mut cursor = io::Cursor::new(bytes);
|
let mut cursor = io::Cursor::new(bytes);
|
||||||
let response = Response::read_from(&mut cursor).unwrap();
|
let response = Response::read_from(&mut cursor).unwrap();
|
||||||
log::info!("{:?}", response);
|
log::info!("{:?}", response);
|
||||||
|
|
@ -184,24 +180,39 @@ async fn request(socket: Arc<UnixStream>, request: Request) -> Message {
|
||||||
auth_message,
|
auth_message,
|
||||||
} => match auth_message_type {
|
} => match auth_message_type {
|
||||||
AuthMessageType::Secret => {
|
AuthMessageType::Secret => {
|
||||||
return Message::Input(InputState::Auth(
|
return Message::Input(InputState::Auth {
|
||||||
true,
|
secret: true,
|
||||||
auth_message,
|
prompt: auth_message,
|
||||||
String::new(),
|
value: String::new(),
|
||||||
))
|
})
|
||||||
}
|
}
|
||||||
AuthMessageType::Visible => {
|
AuthMessageType::Visible => {
|
||||||
return Message::Input(InputState::Auth(
|
return Message::Input(InputState::Auth {
|
||||||
false,
|
secret: false,
|
||||||
auth_message,
|
prompt: auth_message,
|
||||||
String::new(),
|
value: String::new(),
|
||||||
))
|
})
|
||||||
}
|
}
|
||||||
_ => todo!("unsupported auth_message_type {:?}", auth_message_type),
|
_ => todo!("unsupported auth_message_type {:?}", auth_message_type),
|
||||||
},
|
},
|
||||||
Response::Success => {
|
Response::Success => match request {
|
||||||
return Message::Login;
|
Request::CreateSession { .. } => {
|
||||||
}
|
// User has no auth required, proceed to login
|
||||||
|
return Message::Login;
|
||||||
|
}
|
||||||
|
Request::PostAuthMessageResponse { .. } => {
|
||||||
|
// All auth is completed, proceed to login
|
||||||
|
return Message::Login;
|
||||||
|
}
|
||||||
|
Request::StartSession { .. } => {
|
||||||
|
// Session has been started, exit greeter
|
||||||
|
return Message::Exit;
|
||||||
|
}
|
||||||
|
Request::CancelSession => {
|
||||||
|
//TODO: restart whole process
|
||||||
|
return Message::None;
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
log::error!("unhandled response");
|
log::error!("unhandled response");
|
||||||
break;
|
break;
|
||||||
|
|
@ -243,7 +254,11 @@ pub enum SocketState {
|
||||||
pub enum InputState {
|
pub enum InputState {
|
||||||
None,
|
None,
|
||||||
Username,
|
Username,
|
||||||
Auth(bool, String, String),
|
Auth {
|
||||||
|
secret: bool,
|
||||||
|
prompt: String,
|
||||||
|
value: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Messages that are used specifically by our [`App`].
|
/// Messages that are used specifically by our [`App`].
|
||||||
|
|
@ -256,6 +271,7 @@ pub enum Message {
|
||||||
Username(String),
|
Username(String),
|
||||||
Auth(String),
|
Auth(String),
|
||||||
Login,
|
Login,
|
||||||
|
Exit,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [`App`] stores application-specific state.
|
/// The [`App`] stores application-specific state.
|
||||||
|
|
@ -403,6 +419,9 @@ impl cosmic::Application for App {
|
||||||
}
|
}
|
||||||
_ => todo!("socket not open but attempting to log in"),
|
_ => todo!("socket not open but attempting to log in"),
|
||||||
},
|
},
|
||||||
|
Message::Exit => {
|
||||||
|
return iced::window::close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
|
|
@ -448,14 +467,22 @@ impl cosmic::Application for App {
|
||||||
}
|
}
|
||||||
row.into()
|
row.into()
|
||||||
}
|
}
|
||||||
InputState::Auth(secret, prompt, value) => {
|
InputState::Auth {
|
||||||
|
secret,
|
||||||
|
prompt,
|
||||||
|
value,
|
||||||
|
} => {
|
||||||
let mut column = widget::column::with_capacity(2)
|
let mut column = widget::column::with_capacity(2)
|
||||||
.spacing(12.0)
|
.spacing(12.0)
|
||||||
.width(iced::Length::Fixed(400.0));
|
.width(iced::Length::Fixed(400.0));
|
||||||
column = column.push(widget::text(prompt));
|
column = column.push(widget::text(prompt));
|
||||||
let text_input = widget::text_input("", &value)
|
let text_input = widget::text_input("", &value)
|
||||||
.on_input(|value| {
|
.on_input(|value| {
|
||||||
Message::Input(InputState::Auth(*secret, prompt.clone(), value))
|
Message::Input(InputState::Auth {
|
||||||
|
secret: *secret,
|
||||||
|
prompt: prompt.clone(),
|
||||||
|
value,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.on_submit(Message::Auth(value.clone()));
|
.on_submit(Message::Auth(value.clone()));
|
||||||
if *secret {
|
if *secret {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue