@@ -995,18 +995,19 @@ export function AppShell({
995995 return state ;
996996 } , [ ] ) ;
997997
998- function sendControl ( udid : string , message : ControlMessage ) {
998+ function sendControl ( udid : string , message : ControlMessage ) : boolean {
999999 setLocalError ( "" ) ;
10001000 const encoded = JSON . stringify ( message ) ;
10011001 if ( sendWebRtcControlMessage ( encoded ) ) {
1002- return ;
1002+ return true ;
10031003 }
10041004 const state = ensureControlSocket ( udid ) ;
10051005 if ( state . socket . readyState === WebSocket . OPEN ) {
10061006 state . socket . send ( encoded ) ;
10071007 } else {
10081008 state . pending . push ( encoded ) ;
10091009 }
1010+ return true ;
10101011 }
10111012
10121013 useEffect ( ( ) => closeControlSocket , [ closeControlSocket ] ) ;
@@ -1297,28 +1298,47 @@ export function AppShell({
12971298 if ( ! selectedSimulator ) {
12981299 return ;
12991300 }
1300- void runAction ( ( ) => dismissKeyboard ( selectedSimulator . udid ) , false ) ;
1301+ if (
1302+ ! sendControl ( selectedSimulator . udid , { type : "dismissKeyboard" } )
1303+ ) {
1304+ void runAction (
1305+ ( ) => dismissKeyboard ( selectedSimulator . udid ) ,
1306+ false ,
1307+ ) ;
1308+ }
13011309 } }
13021310 onHome = { ( ) => {
13031311 if ( ! selectedSimulator ) {
13041312 return ;
13051313 }
13061314 setAccessibilitySelectedId ( "" ) ;
13071315 setAccessibilityHoveredId ( null ) ;
1308- void runAction ( ( ) => pressHome ( selectedSimulator . udid ) , false ) ;
1316+ if ( ! sendControl ( selectedSimulator . udid , { type : "home" } ) ) {
1317+ void runAction ( ( ) => pressHome ( selectedSimulator . udid ) , false ) ;
1318+ }
13091319 } }
13101320 onOpenAppSwitcher = { ( ) => {
13111321 if ( ! selectedSimulator ) {
13121322 return ;
13131323 }
13141324 setAccessibilitySelectedId ( "" ) ;
13151325 setAccessibilityHoveredId ( null ) ;
1316- void runAction ( ( ) => openAppSwitcher ( selectedSimulator . udid ) , false ) ;
1326+ if ( ! sendControl ( selectedSimulator . udid , { type : "appSwitcher" } ) ) {
1327+ void runAction (
1328+ ( ) => openAppSwitcher ( selectedSimulator . udid ) ,
1329+ false ,
1330+ ) ;
1331+ }
13171332 } }
13181333 onRotateLeft = { ( ) => {
13191334 if ( ! selectedSimulator ) {
13201335 return ;
13211336 }
1337+ if ( sendControl ( selectedSimulator . udid , { type : "rotateLeft" } ) ) {
1338+ setRotationQuarterTurns ( ( current ) => ( current + 3 ) % 4 ) ;
1339+ setStreamStamp ( Date . now ( ) ) ;
1340+ return ;
1341+ }
13221342 void runAction ( async ( ) => {
13231343 await rotateLeft ( selectedSimulator . udid ) ;
13241344 setRotationQuarterTurns ( ( current ) => ( current + 3 ) % 4 ) ;
@@ -1331,6 +1351,11 @@ export function AppShell({
13311351 if ( ! selectedSimulator ) {
13321352 return ;
13331353 }
1354+ if ( sendControl ( selectedSimulator . udid , { type : "rotateRight" } ) ) {
1355+ setRotationQuarterTurns ( ( current ) => ( current + 1 ) % 4 ) ;
1356+ setStreamStamp ( Date . now ( ) ) ;
1357+ return ;
1358+ }
13341359 void runAction ( async ( ) => {
13351360 await rotateRight ( selectedSimulator . udid ) ;
13361361 setRotationQuarterTurns ( ( current ) => ( current + 1 ) % 4 ) ;
@@ -1355,7 +1380,10 @@ export function AppShell({
13551380 if ( ! selectedSimulator ) {
13561381 return ;
13571382 }
1358- void runAction ( ( ) => toggleAppearance ( selectedSimulator . udid ) ) ;
1383+ const encoded = JSON . stringify ( { type : "toggleAppearance" } ) ;
1384+ if ( ! sendWebRtcControlMessage ( encoded ) ) {
1385+ void runAction ( ( ) => toggleAppearance ( selectedSimulator . udid ) ) ;
1386+ }
13591387 } }
13601388 onToggleDebug = { ( ) => setDebugVisible ( ( current ) => ! current ) }
13611389 onToggleHierarchy = { ( ) => {
0 commit comments