Start to implement the ClienState struct

Signed-off-by: Paul R. Tagliamonte <paul@kittycad.io>
This commit is contained in:
Paul R. Tagliamonte
2024-05-13 14:01:55 -04:00
committed by Dan Shaw
parent 950f27ce2a
commit 0ac1cbfcf9
3 changed files with 29 additions and 16 deletions

View File

@ -2,7 +2,7 @@
use anyhow::Result; use anyhow::Result;
use crate::coredump::CoreDump; use crate::coredump::{AuthMachineState, ClientState, CoreDump};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct CoreDumper {} pub struct CoreDumper {}
@ -55,8 +55,8 @@ impl CoreDump for CoreDumper {
Ok(crate::coredump::WebrtcStats::default()) Ok(crate::coredump::WebrtcStats::default())
} }
async fn get_client_state(&self) -> Result<String> { async fn get_client_state(&self) -> Result<ClientState> {
Ok("{}".to_string()) Ok(ClientState::default())
} }
async fn screenshot(&self) -> Result<String> { async fn screenshot(&self) -> Result<String> {

View File

@ -27,7 +27,7 @@ pub trait CoreDump: Clone {
async fn get_webrtc_stats(&self) -> Result<WebrtcStats>; async fn get_webrtc_stats(&self) -> Result<WebrtcStats>;
async fn get_client_state(&self) -> Result<String>; async fn get_client_state(&self) -> Result<ClientState>;
/// Return a screenshot of the app. /// Return a screenshot of the app.
async fn screenshot(&self) -> Result<String>; async fn screenshot(&self) -> Result<String>;
@ -115,8 +115,7 @@ pub struct AppInfo {
pub pool: String, pub pool: String,
/// The client state (singletons and xstate) /// The client state (singletons and xstate)
///#[serde(skip_serializing_if = "Option::is_none")] pub client_state: ClientState,
pub client_state: String,
} }
impl AppInfo { impl AppInfo {
@ -205,3 +204,18 @@ pub struct WebrtcStats {
/// Packet jitter for this synchronizing source, measured in seconds. /// Packet jitter for this synchronizing source, measured in seconds.
pub jitter: f32, pub jitter: f32,
} }
#[derive(Default, Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[ts(export)]
#[serde(rename_all = "snake_case")]
pub struct AuthMachineState {
pub _unused: [u8; 0],
}
#[derive(Default, Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
#[ts(export)]
#[serde(rename_all = "snake_case")]
pub struct ClientState {
/// Internal state of the AuthMachine xstate object.
pub auth_machine: AuthMachineState,
}

View File

@ -3,7 +3,10 @@
use anyhow::Result; use anyhow::Result;
use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::prelude::wasm_bindgen;
use crate::{coredump::CoreDump, wasm::JsFuture}; use crate::{
coredump::{AuthMachineState, ClientState, CoreDump},
wasm::JsFuture,
};
#[wasm_bindgen(module = "/../../lib/coredump.ts")] #[wasm_bindgen(module = "/../../lib/coredump.ts")]
extern "C" { extern "C" {
@ -128,15 +131,11 @@ impl CoreDump for CoreDumper {
Ok(stats) Ok(stats)
} }
async fn get_client_state(&self) -> Result<String> { async fn get_client_state(&self) -> Result<ClientState> {
// Parse the value as a string. Ok(ClientState {
let client_state = "{ signletons: {}, xstate: {} }"; auth_machine: AuthMachineState { ..Default::default() },
..Default::default()
//self.manager })
// .get_client_state()
// .map_err(|e| anyhow::anyhow!("Failed to get response from get client state: {:?}", e));
Ok(client_state.to_string())
} }
async fn screenshot(&self) -> Result<String> { async fn screenshot(&self) -> Result<String> {