| 1 | use crossterm::event::{KeyCode, KeyEvent}; |
| 2 | use nmrs::WifiSecurity; |
| 3 | |
| 4 | use crate::{ |
| 5 | action::{Action, ConnectRequest}, |
| 6 | app::{App, Focus}, |
| 7 | ui::popup::Popups, |
| 8 | }; |
| 9 | |
| 10 | pub fn handle(app: &mut App, key: KeyEvent) { |
| 11 | let Focus::Popup(popup) = &mut app.focus else { |
| 12 | return; |
| 13 | }; |
| 14 | |
| 15 | match popup { |
| 16 | Popups::Password(input, network) => match key.code { |
| 17 | // Connect |
| 18 | KeyCode::Enter => { |
| 19 | app.action.send(Action::Connect(Box::new(ConnectRequest { |
| 20 | ssid: network.ssid.clone(), |
| 21 | interface: None, |
| 22 | credentials: WifiSecurity::WpaPsk { |
| 23 | psk: input.value.clone(), |
| 24 | }, |
| 25 | }))); |
| 26 | |
| 27 | popup.close(&app.action, app.last_focus.clone()); |
| 28 | } |
| 29 | |
| 30 | // Hide the password |
| 31 | KeyCode::Tab => { |
| 32 | input.hidden = !input.hidden; |
| 33 | } |
| 34 | KeyCode::Char(to_insert) => input.enter_char(to_insert), |
| 35 | KeyCode::Backspace => input.delete_char(), |
| 36 | KeyCode::Left => input.move_cursor_left(), |
| 37 | KeyCode::Right => input.move_cursor_right(), |
| 38 | KeyCode::Esc => { |
| 39 | popup.close(&app.action, app.last_focus.clone()); |
| 40 | } |
| 41 | _ => {} |
| 42 | }, |
| 43 | } |
| 44 | } |
