add frontend app state enum

This commit is contained in:
Joe Ardent 2025-07-07 17:48:25 -07:00
parent 5e4e31d64f
commit 91beef2657
2 changed files with 23 additions and 6 deletions

View file

@ -27,7 +27,7 @@ pub const LISTENING_SOCKET_ADDR: SocketAddrV4 =
type ShutdownSender = mpsc::Sender<()>; type ShutdownSender = mpsc::Sender<()>;
/// Contains the main network and application state for an application session. /// Contains the main network and backend state for an application session.
#[derive(Clone)] #[derive(Clone)]
pub struct JoecalState { pub struct JoecalState {
pub device: Device, pub device: Device,
@ -48,11 +48,11 @@ impl JoecalState {
Ok(Self { Ok(Self {
device, device,
client: reqwest::Client::new(),
socket: socket.into(),
peers: Default::default(), peers: Default::default(),
sessions: Default::default(), sessions: Default::default(),
running_state: Default::default(), running_state: Default::default(),
socket: socket.into(),
client: reqwest::Client::new(),
stop_tx: Default::default(), stop_tx: Default::default(),
}) })
} }

View file

@ -59,6 +59,14 @@ async fn main() -> error::Result<()> {
struct App { struct App {
state: JoecalState, state: JoecalState,
rstate: RunningState, rstate: RunningState,
screen: CurrentScreen,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum CurrentScreen {
Main,
Sending,
Receiving,
} }
impl App { impl App {
@ -66,6 +74,7 @@ impl App {
App { App {
state: state.clone(), state: state.clone(),
rstate: *state.running_state.lock().await, rstate: *state.running_state.lock().await,
screen: CurrentScreen::Main,
} }
} }
@ -101,8 +110,8 @@ impl App {
async fn handle_key_event(&mut self, key_event: KeyEvent) { async fn handle_key_event(&mut self, key_event: KeyEvent) {
match key_event.code { match key_event.code {
KeyCode::Char('q') => self.exit().await, KeyCode::Char('q') => self.exit().await,
KeyCode::Char('s') => {} KeyCode::Char('s') => self.send().await,
KeyCode::Char('r') => {} KeyCode::Char('r') => self.recv().await,
KeyCode::Char('d') => {} KeyCode::Char('d') => {}
_ => {} _ => {}
} }
@ -111,6 +120,14 @@ impl App {
async fn exit(&self) { async fn exit(&self) {
self.state.stop().await; self.state.stop().await;
} }
async fn send(&mut self) {
self.screen = CurrentScreen::Sending;
}
async fn recv(&mut self) {
self.screen = CurrentScreen::Receiving;
}
} }
impl Widget for &App { impl Widget for &App {
@ -131,7 +148,7 @@ impl Widget for &App {
.title_bottom(instructions.centered()) .title_bottom(instructions.centered())
.border_set(border::THICK); .border_set(border::THICK);
let rs = format!("{:?}", self.rstate); let rs = format!("{:?}", self.screen);
let state_text = Text::from(vec![Line::from(vec!["runstate: ".into(), rs.yellow()])]); let state_text = Text::from(vec![Line::from(vec!["runstate: ".into(), rs.yellow()])]);
Paragraph::new(state_text) Paragraph::new(state_text)