Nadro/adhoc/system io machine (#6352)

* chore: saving off skeleton

* fix: saving skeleton

* chore: skeleton for loading projects from project directory path

* chore: cleaning up useless state transition to be an on event direct to action state

* fix: new structure for web vs desktop vs react machine provider code

* chore: saving off skeleton

* fix: skeleton logic for react? going to move it from a string to obj.string

* fix: trying to prevent error element unmount on global react components. This is bricking JS state

* fix: we are so back

* chore: implemented navigating to specfic KCL file

* chore: implementing renaming project

* chore: deleting project

* fix: auto fixes

* fix: old debug/testing file oops

* chore: generic create new file

* chore: skeleton for web create file provide

* chore: basic machine vitest... need to figure out how to get window.electron implemented in vitest?

* chore: save off progress before deleting other project implementation, a few missing features still

* chore: trying a different init skeleton? most likely will migrate

* chore: first attempt of purging projects context provider

* chore: enabling toast for some machine state

* chore: enabling more toast success and error

* chore: writing read write state to the system io based on the project path

* fix: tsc fixes

* fix: use file system watcher, navigate to project after creation via the requestProjectName

* chore: open project command, hooks vs snapshot context helpers

* chore: implemented open and create project for e2e testing. They are hard coded in poor spot for now.

* fix: codespell fixes

* chore: implementing more project commands

* chore: PR improvements for root.tsx

* chore: leaving comment about new Router.tsx layout

* fix: removing debugging code

* fix: rewriting component for readability

* fix: improving web initialization

* chore: implementing import file from url which is not actually that?

* fix: clearing search params on import file from url

* fix: fixed two e2e tests, forgot needsReview when making new command

* fix: fixing some import from url business logic to pass e2e tests

* chore: script for diffing circular deps +/-

* fix: formatting

* fix: massive fix for circular depsga!

* fix: trying to fix some errors and auto fmt

* fix: updating deps

* fix: removing debugging code

* fix: big clean up

* fix: more deletion

* fix: tsc cleanup

* fix: TSC TSC TSC TSC!

* fix: typo fix

* fix: clear query params on web only, desktop not required

* fix: removing unused code

* fmt

* Bring back `trap` removed in merge

* Use explicit types instead of `any`s on arg configs

* Add project commands directly to command palette

* fix: deleting debugging code, from PR review

* fix: this got added back(?)

* fix: using referred type

* fix: more PR clean up

* fix: big block comment for xstate architecture decision

* fix: more pr comment fixes

* fix: merge conflict just added them back why dude

* fix: more PR comments

* fix: big ciruclar deps fix, commandBarActor in appActor

---------

Co-authored-by: Frank Noirot <frankjohnson1993@gmail.com>
This commit is contained in:
Kevin Nadro
2025-04-24 13:32:49 -05:00
committed by GitHub
parent 95f2caacab
commit 305d613d40
93 changed files with 1704 additions and 1250 deletions

View File

@ -1,7 +1,7 @@
import { engineCommandManager, sceneInfra } from '@src/lib/singletons'
import type { MutableRefObject } from 'react'
import type { ActorRefFrom } from 'xstate'
import { assign, fromPromise, setup } from 'xstate'
import type { AppMachineContext } from '@src/lib/types'
export enum EngineStreamState {
Off = 'off',
@ -79,9 +79,13 @@ export const engineStreamMachine = setup({
actors: {
[EngineStreamTransition.Play]: fromPromise(
async ({
input: { context, params },
input: { context, params, rootContext },
}: {
input: { context: EngineStreamContext; params: { zoomToFit: boolean } }
input: {
context: EngineStreamContext
params: { zoomToFit: boolean }
rootContext: AppMachineContext
}
}) => {
const canvas = context.canvasRef.current
if (!canvas) return false
@ -98,7 +102,7 @@ export const engineStreamMachine = setup({
return
}
await sceneInfra.camControls.restoreRemoteCameraStateAndTriggerSync()
await rootContext.sceneInfra.camControls.restoreRemoteCameraStateAndTriggerSync()
video.style.display = 'block'
canvas.style.display = 'none'
@ -108,9 +112,9 @@ export const engineStreamMachine = setup({
),
[EngineStreamTransition.Pause]: fromPromise(
async ({
input: { context },
input: { context, rootContext },
}: {
input: { context: EngineStreamContext }
input: { context: EngineStreamContext; rootContext: AppMachineContext }
}) => {
const video = context.videoRef.current
if (!video) return
@ -123,7 +127,7 @@ export const engineStreamMachine = setup({
await holdOntoVideoFrameInCanvas(video, canvas)
video.style.display = 'none'
await sceneInfra.camControls.saveRemoteCameraState()
await rootContext.sceneInfra.camControls.saveRemoteCameraState()
// Make sure we're on the next frame for no flickering between canvas
// and the video elements.
@ -138,16 +142,20 @@ export const engineStreamMachine = setup({
context.mediaStream = null
video.srcObject = null
engineCommandManager.tearDown({ idleMode: true })
rootContext.engineCommandManager.tearDown({ idleMode: true })
})()
)
}
),
[EngineStreamTransition.StartOrReconfigureEngine]: fromPromise(
async ({
input: { context, event },
input: { context, event, rootContext },
}: {
input: { context: EngineStreamContext; event: any }
input: {
context: EngineStreamContext
event: any
rootContext: AppMachineContext
}
}) => {
if (!context.authToken) return
@ -172,10 +180,10 @@ export const engineStreamMachine = setup({
...event.settings,
}
engineCommandManager.settings = settingsNext
rootContext.engineCommandManager.settings = settingsNext
window.requestAnimationFrame(() => {
engineCommandManager.start({
rootContext.engineCommandManager.start({
setMediaStream: event.onMediaStream,
setIsStreamReady: (isStreamReady: boolean) => {
event.setAppState({ isStreamReady })
@ -225,7 +233,12 @@ export const engineStreamMachine = setup({
reenter: true,
invoke: {
src: EngineStreamTransition.StartOrReconfigureEngine,
input: (args) => args,
input: (args) => ({
context: args.context,
rootContext: args.self.system.get('root').getSnapshot().context,
params: { zoomToFit: args.context.zoomToFit },
event: args.event,
}),
},
on: {
// Transition requested by engineConnection
@ -246,6 +259,7 @@ export const engineStreamMachine = setup({
src: EngineStreamTransition.Play,
input: (args) => ({
context: args.context,
rootContext: args.self.system.get('root').getSnapshot().context,
params: { zoomToFit: args.context.zoomToFit },
}),
},
@ -261,7 +275,11 @@ export const engineStreamMachine = setup({
[EngineStreamState.Reconfiguring]: {
invoke: {
src: EngineStreamTransition.StartOrReconfigureEngine,
input: (args) => args,
input: (args) => ({
context: args.context,
rootContext: args.self.system.get('root').getSnapshot().context,
event: args.event,
}),
onDone: {
target: EngineStreamState.Playing,
},
@ -270,7 +288,10 @@ export const engineStreamMachine = setup({
[EngineStreamState.Paused]: {
invoke: {
src: EngineStreamTransition.Pause,
input: (args) => args,
input: (args) => ({
context: args.context,
rootContext: args.self.system.get('root').getSnapshot().context,
}),
},
on: {
[EngineStreamTransition.StartOrReconfigureEngine]: {
@ -282,7 +303,11 @@ export const engineStreamMachine = setup({
reenter: true,
invoke: {
src: EngineStreamTransition.StartOrReconfigureEngine,
input: (args) => args,
input: (args) => ({
context: args.context,
rootContext: args.self.system.get('root').getSnapshot().context,
event: args.event,
}),
},
on: {
// The stream can be paused as it's resuming.