-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further refinement of backend-frontend communication
- Loading branch information
1 parent
3030aa0
commit 491832f
Showing
6 changed files
with
185 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,64 @@ | ||
use crate::Settings; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Messages sent by the backend app thread. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] | ||
pub enum BackendMsg { | ||
ReadingSettings, | ||
QueryAppResponse(State), | ||
Response(BackendResponse), | ||
} | ||
|
||
impl BackendMsg { | ||
/// JS Event name used by the frontend. | ||
pub const fn event_name() -> &'static str { | ||
"chipbox-app-message" | ||
} | ||
} | ||
|
||
/// Messages sent by the backend app thread in response to frontend queries. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] | ||
pub enum BackendResponse { | ||
/// Respond with current `BackendAppState`. | ||
BackendAppState(BackendAppState), | ||
/// Respond with current `Settings`. | ||
Settings(Option<Settings>), | ||
} | ||
|
||
/// Messages sent by the frontend app thread. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] | ||
pub enum FrontendMsg { | ||
QueryApp, | ||
/// Query information from the backend. | ||
Query(FrontendQuery), | ||
} | ||
|
||
/// Messages sent by the frontend app thread requesting information from the backend. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] | ||
pub enum FrontendQuery { | ||
/// Query current `BackendAppState`. | ||
BackendAppState, | ||
/// Query current `Settings`. | ||
Settings, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Default)] | ||
pub enum AwaitConfig { | ||
/// Reason why the user config is not ready. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy, Default)] | ||
pub enum AwaitConfigReason { | ||
#[default] | ||
/// It's the first time the application has been started. | ||
/// The user has not yet configured the application. | ||
NoConfig, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] | ||
pub enum State { | ||
/// Minimal description of the current state of the backend. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy, Default)] | ||
pub enum BackendAppState { | ||
/// Backend is currently reading user config. | ||
#[default] | ||
ReadingSettings, | ||
AwaitConfig(AwaitConfig), | ||
/// User config has been read, but no valid configuration was found. | ||
AwaitConfig { reason: AwaitConfigReason }, | ||
/// User config was read and is valid. | ||
Idle, | ||
/// Backend is ready to edit a project. | ||
Editor, | ||
} |
Oops, something went wrong.