Skip to content

Commit

Permalink
Only run the applet when the web UI is ready (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 committed Oct 24, 2023
1 parent 17ff1ff commit 64b81e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/runner-host/crates/web-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ use serde::{Deserialize, Serialize};
#[serde(tag = "componentType", rename_all = "snake_case")]
pub enum Event {
#[serde(rename_all = "camelCase")]
Button { component_id: usize, state: ButtonState },
Button {
component_id: usize,
state: ButtonState,
},

BoardReady,
}

/// Commands for the hardware.
Expand Down
6 changes: 6 additions & 0 deletions crates/runner-host/crates/web-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ async fn handle(mut ws: WebSocket, client: ClientInput) {
],
};
cmd_sender.send(board_config).await.unwrap();
let board_ready = ws_receiver.next().await.unwrap().unwrap();
match serde_json::from_str(board_ready.to_str().unwrap()).unwrap() {
web_common::Event::BoardReady => (),
event => panic!("Expected BoardReady, got {event:?}"),
}
if client_sender.send(Client { sender: cmd_sender }).is_err() {
panic!("Could not send client.");
}
Expand Down Expand Up @@ -153,6 +158,7 @@ async fn handle(mut ws: WebSocket, client: ClientInput) {
}
Event::Button { pressed: matches!(state, ButtonState::Pressed) }
}
web_common::Event::BoardReady => panic!("Unexpected BoardReady event."),
};
if let Err(e) = event_sender.send(event).await {
log::warn!("Failed to send {:?}: {:?}", event, e);
Expand Down

0 comments on commit 64b81e7

Please sign in to comment.