@@ -18,18 +18,11 @@ import { apiUrl, configureSimDeckClient } from "../api/config";
1818import {
1919 bootSimulator ,
2020 captureSimulatorScreenshot ,
21- dismissKeyboard ,
2221 launchSimulatorBundle ,
23- openAppSwitcher ,
2422 openSimulatorUrl ,
25- pressHome ,
26- pressSimulatorButton ,
2723 recordSimulatorScreen ,
28- rotateDigitalCrown ,
29- rotateRight ,
3024 simulatorControlSocketUrl ,
3125 shutdownSimulator ,
32- toggleAppearance ,
3326 uploadSimulatorApp ,
3427 type ControlMessage ,
3528} from "../api/controls" ;
@@ -2057,6 +2050,19 @@ export function AppShell({
20572050 return state ;
20582051 } , [ ] ) ;
20592052
2053+ useEffect ( ( ) => {
2054+ if ( ! selectedSimulator ?. isBooted ) {
2055+ closeControlSocket ( ) ;
2056+ return ;
2057+ }
2058+ ensureControlSocket ( selectedSimulator . udid ) ;
2059+ } , [
2060+ closeControlSocket ,
2061+ ensureControlSocket ,
2062+ selectedSimulator ?. isBooted ,
2063+ selectedSimulator ?. udid ,
2064+ ] ) ;
2065+
20602066 function sendControl ( udid : string , message : ControlMessage ) : boolean {
20612067 if ( isMoveControlMessage ( message ) ) {
20622068 pendingControlMoveRef . current = { message, udid } ;
@@ -2096,9 +2102,20 @@ export function AppShell({
20962102 if ( sendWebRtcControlMessage ( encoded , { dropIfBacklogged } ) ) {
20972103 return true ;
20982104 }
2105+ if ( sendControlSocketMessage ( udid , encoded , dropIfBacklogged ) ) {
2106+ return true ;
2107+ }
20992108 if ( remoteStream ) {
21002109 return false ;
21012110 }
2111+ return false ;
2112+ }
2113+
2114+ function sendControlSocketMessage (
2115+ udid : string ,
2116+ encoded : string ,
2117+ dropIfBacklogged : boolean ,
2118+ ) : boolean {
21022119 const state = ensureControlSocket ( udid ) ;
21032120 if ( state . socket . readyState === WebSocket . OPEN ) {
21042121 if (
@@ -2405,16 +2422,7 @@ export function AppShell({
24052422 usage,
24062423 } )
24072424 ) {
2408- void runAction (
2409- ( ) =>
2410- pressSimulatorButton ( selectedSimulator . udid , {
2411- button,
2412- phase,
2413- usagePage,
2414- usage,
2415- } ) ,
2416- false ,
2417- ) ;
2425+ setLocalError ( "Simulator control stream disconnected." ) ;
24182426 }
24192427 }
24202428
@@ -2430,10 +2438,7 @@ export function AppShell({
24302438 delta,
24312439 } )
24322440 ) {
2433- void runAction (
2434- ( ) => rotateDigitalCrown ( selectedSimulator . udid , { delta } ) ,
2435- false ,
2436- ) ;
2441+ setLocalError ( "Simulator control stream disconnected." ) ;
24372442 }
24382443 }
24392444
@@ -2703,10 +2708,7 @@ export function AppShell({
27032708 if (
27042709 ! sendControl ( selectedSimulator . udid , { type : "dismissKeyboard" } )
27052710 ) {
2706- void runAction (
2707- ( ) => dismissKeyboard ( selectedSimulator . udid ) ,
2708- false ,
2709- ) ;
2711+ setLocalError ( "Simulator control stream disconnected." ) ;
27102712 }
27112713 } }
27122714 onHome = { ( ) => {
@@ -2716,7 +2718,7 @@ export function AppShell({
27162718 setAccessibilitySelectedId ( "" ) ;
27172719 setAccessibilityHoveredId ( null ) ;
27182720 if ( ! sendControl ( selectedSimulator . udid , { type : "home" } ) ) {
2719- void runAction ( ( ) => pressHome ( selectedSimulator . udid ) , false ) ;
2721+ setLocalError ( "Simulator control stream disconnected." ) ;
27202722 }
27212723 } }
27222724 onInstallAppPrompt = { openInstallAppPicker }
@@ -2727,10 +2729,7 @@ export function AppShell({
27272729 setAccessibilitySelectedId ( "" ) ;
27282730 setAccessibilityHoveredId ( null ) ;
27292731 if ( ! sendControl ( selectedSimulator . udid , { type : "appSwitcher" } ) ) {
2730- void runAction (
2731- ( ) => openAppSwitcher ( selectedSimulator . udid ) ,
2732- false ,
2733- ) ;
2732+ setLocalError ( "Simulator control stream disconnected." ) ;
27342733 }
27352734 } }
27362735 onOpenBundlePrompt = { promptForBundleID }
@@ -2748,23 +2747,18 @@ export function AppShell({
27482747 }
27492748 const androidViewport = isAndroidSimulator ( selectedSimulator ) ;
27502749 beginZoomAnimation ( ) ;
2751- if ( androidViewport ) {
2752- void runAction ( async ( ) => {
2753- await rotateRight ( selectedSimulator . udid ) ;
2754- setRotationQuarterTurns ( 0 ) ;
2755- beginZoomAnimation ( ) ;
2756- await refresh ( ) ;
2757- } , false ) ;
2758- return ;
2759- }
27602750 if ( sendControl ( selectedSimulator . udid , { type : "rotateRight" } ) ) {
2761- setRotationQuarterTurns ( ( current ) => ( current + 1 ) % 4 ) ;
2751+ if ( androidViewport ) {
2752+ setRotationQuarterTurns ( 0 ) ;
2753+ window . setTimeout ( ( ) => {
2754+ void refresh ( ) ;
2755+ } , 250 ) ;
2756+ } else {
2757+ setRotationQuarterTurns ( ( current ) => ( current + 1 ) % 4 ) ;
2758+ }
27622759 return ;
27632760 }
2764- void runAction ( async ( ) => {
2765- await rotateRight ( selectedSimulator . udid ) ;
2766- setRotationQuarterTurns ( ( current ) => ( current + 1 ) % 4 ) ;
2767- } , false ) ;
2761+ setLocalError ( "Simulator control stream disconnected." ) ;
27682762 } }
27692763 onRecordScreen = { ( ) => {
27702764 void downloadSimulatorRecording ( ) ;
@@ -2789,10 +2783,7 @@ export function AppShell({
27892783 if (
27902784 ! sendControl ( selectedSimulator . udid , { type : "toggleAppearance" } )
27912785 ) {
2792- void runAction (
2793- ( ) => toggleAppearance ( selectedSimulator . udid ) ,
2794- false ,
2795- ) ;
2786+ setLocalError ( "Simulator control stream disconnected." ) ;
27962787 }
27972788 } }
27982789 onToggleDebug = { ( ) => setDebugVisible ( ( current ) => ! current ) }
0 commit comments