fix and simulate engine disconnect when in sketch mode (#2524)

* fix and simulate engine disconnect when in sketch mode

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* Update e2e/playwright/test-utils.ts

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2024-05-24 16:11:49 -07:00
committed by GitHub
parent 1b72c7df85
commit f735cdc22e
3 changed files with 147 additions and 3 deletions

View File

@ -73,6 +73,10 @@ import { useSearchParams } from 'react-router-dom'
import { letEngineAnimateAndSyncCamAfter } from 'clientSideScene/CameraControls'
import { getVarNameModal } from 'hooks/useToolbarGuards'
import useHotkeyWrapper from 'lib/hotkeyWrapper'
import {
EngineConnectionState,
EngineConnectionStateType,
} from 'lang/std/engineConnection'
type MachineContext<T extends AnyStateMachine> = {
state: StateFrom<T>
@ -658,6 +662,19 @@ export const ModelingMachineProvider = ({
editorManager.selectionRanges = modelingState.context.selectionRanges
}, [modelingState.context.selectionRanges])
useEffect(() => {
const offlineCallback = () => {
// If we are in sketch mode we need to exit it.
// TODO: how do i check if we are in a sketch mode, I only want to call
// this then.
modelingSend({ type: 'Cancel' })
}
window.addEventListener('offline', offlineCallback)
return () => {
window.removeEventListener('offline', offlineCallback)
}
}, [modelingSend])
useStateMachineCommands({
machineId: 'modeling',
state: modelingState,