Rust gimme JSON
This brings the code back to my original intent and strategy when I started building out this solution: gather all the JSON we may need under `client_state` and pass it back. 🎉
This commit is contained in:
@ -152,7 +152,7 @@ export class CoreDumpManager {
|
||||
* - NOTE: this function thows on parse errors from things like circular references
|
||||
* - It is also syncronous and could be more performant
|
||||
* - There is a whole rabbit hole to explore here if you like.
|
||||
* - This work for our use case.
|
||||
* - This works for our use case.
|
||||
* @param {object} obj - The object to clone.
|
||||
*/
|
||||
const deepClone = (obj: any) => JSON.parse(JSON.stringify(obj))
|
||||
@ -160,7 +160,7 @@ export class CoreDumpManager {
|
||||
console.warn('CoreDump: Gathering client state')
|
||||
|
||||
// Initialize the clientState object
|
||||
let clientState: ClientState = {
|
||||
let clientState = {
|
||||
engine_command_manager: {
|
||||
artifact_map: {},
|
||||
command_logs: [],
|
||||
@ -300,7 +300,9 @@ export class CoreDumpManager {
|
||||
// KCL programMemory
|
||||
console.log('CoreDump: KCL programMemory', kclManager?.programMemory)
|
||||
if (kclManager?.programMemory) {
|
||||
clientState.kcl_manager.programMemory = deepClone(kclManager.programMemory)
|
||||
clientState.kcl_manager.programMemory = deepClone(
|
||||
kclManager.programMemory
|
||||
)
|
||||
}
|
||||
|
||||
// KCL wasmInitFailed
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::coredump::{ClientState, CoreDump};
|
||||
use crate::coredump::CoreDump;
|
||||
use serde_json::Value as JValue;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CoreDumper {}
|
||||
@ -55,8 +56,8 @@ impl CoreDump for CoreDumper {
|
||||
Ok(crate::coredump::WebrtcStats::default())
|
||||
}
|
||||
|
||||
async fn get_client_state(&self) -> Result<ClientState> {
|
||||
Ok(ClientState::default())
|
||||
async fn get_client_state(&self) -> Result<JValue> {
|
||||
Ok(JValue::default())
|
||||
}
|
||||
|
||||
async fn screenshot(&self) -> Result<String> {
|
||||
|
||||
@ -29,7 +29,7 @@ pub trait CoreDump: Clone {
|
||||
|
||||
async fn get_webrtc_stats(&self) -> Result<WebrtcStats>;
|
||||
|
||||
async fn get_client_state(&self) -> Result<ClientState>;
|
||||
async fn get_client_state(&self) -> Result<JValue>;
|
||||
|
||||
/// Return a screenshot of the app.
|
||||
async fn screenshot(&self) -> Result<String>;
|
||||
@ -65,7 +65,7 @@ pub trait CoreDump: Clone {
|
||||
|
||||
/// Dump the app info.
|
||||
async fn dump(&self) -> Result<CoreDumpInfo> {
|
||||
let client_state = self.get_client_state().await?;
|
||||
let client_state: JValue = self.get_client_state().await?;
|
||||
let webrtc_stats = self.get_webrtc_stats().await?;
|
||||
let os = self.os().await?;
|
||||
let screenshot_url = self.upload_screenshot().await?;
|
||||
@ -118,7 +118,7 @@ pub struct CoreDumpInfo {
|
||||
pub pool: String,
|
||||
|
||||
/// The client state (singletons and xstate)
|
||||
pub client_state: ClientState,
|
||||
pub client_state: JValue,
|
||||
}
|
||||
|
||||
impl CoreDumpInfo {
|
||||
@ -207,68 +207,3 @@ pub struct WebrtcStats {
|
||||
/// Packet jitter for this synchronizing source, measured in seconds.
|
||||
pub jitter: f32,
|
||||
}
|
||||
|
||||
/// Client State Structures
|
||||
|
||||
/// Client State Singleton Structures
|
||||
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct EngineCommandManagerState {
|
||||
pub artifact_map: JValue,
|
||||
pub command_logs: JValue,
|
||||
pub default_planes: JValue,
|
||||
// engine_connection is currently only a partial copy
|
||||
// since most of engine connection information is in WebrtcStats
|
||||
// the connection state was missing
|
||||
pub engine_connection: EngineConnectionState,
|
||||
pub in_sequence: JValue,
|
||||
pub out_sequence: JValue,
|
||||
pub scene_command_artifacts: JValue,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct EngineConnectionState {
|
||||
/// #[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub state: EngineConnectionType,
|
||||
}
|
||||
|
||||
/// The Engine Connection Type structure.
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct EngineConnectionType {
|
||||
/// #[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(rename = "type")]
|
||||
pub type_field: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct ClientState {
|
||||
/// Singletons
|
||||
/// Internal state of the KclManager/KclSingleton object.
|
||||
pub engine_command_manager: EngineCommandManagerState,
|
||||
/// Internal state of the KclManager/KclSingleton object.
|
||||
pub kcl_manager: JValue,
|
||||
/// Internal state of the SceneInfra object.
|
||||
pub scene_infra: JValue,
|
||||
|
||||
/// XState
|
||||
/// Internal state of the AuthMachine xstate object.
|
||||
pub auth_machine: JValue,
|
||||
/// Internal state of the CommandBarMachine xstate object.
|
||||
pub command_bar_machine: JValue,
|
||||
/// Internal state of the FileMachine xstate object.
|
||||
pub file_machine: JValue,
|
||||
/// Internal state of the HomeMachine xstate object (for Tauri).
|
||||
pub home_machine: JValue,
|
||||
/// Internal state of the ModelingMachine xstate object.
|
||||
pub modeling_machine: JValue,
|
||||
/// Internal state of the SettingsMachine xstate object.
|
||||
pub settings_machine: JValue,
|
||||
}
|
||||
|
||||
@ -4,9 +4,10 @@ use anyhow::Result;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
use crate::{
|
||||
coredump::{ ClientState, CoreDump },
|
||||
coredump::CoreDump,
|
||||
wasm::JsFuture,
|
||||
};
|
||||
use serde_json::Value as JValue;
|
||||
|
||||
#[wasm_bindgen(module = "/../../lib/coredump.ts")]
|
||||
extern "C" {
|
||||
@ -129,7 +130,7 @@ impl CoreDump for CoreDumper {
|
||||
Ok(stats)
|
||||
}
|
||||
|
||||
async fn get_client_state(&self) -> Result<ClientState> {
|
||||
async fn get_client_state(&self) -> Result<JValue> {
|
||||
let promise = self
|
||||
.manager
|
||||
.get_client_state()
|
||||
@ -144,7 +145,7 @@ impl CoreDump for CoreDumper {
|
||||
.as_string()
|
||||
.ok_or_else(|| anyhow::anyhow!("Failed to get string from response from client stat: `{:?}`", value))?;
|
||||
|
||||
let client_state: ClientState =
|
||||
let client_state: JValue =
|
||||
serde_json::from_str(&s).map_err(|e| anyhow::anyhow!("Failed to parse client state: {:?}", e))?;
|
||||
|
||||
Ok(client_state)
|
||||
|
||||
Reference in New Issue
Block a user