99} from "react" ;
1010
1111import { ApiError , accessTokenFromLocation , pairBrowser } from "../api/client" ;
12+ import { apiUrl , configureSimDeckClient } from "../api/config" ;
1213import {
1314 bootSimulator ,
1415 dismissKeyboard ,
@@ -61,7 +62,6 @@ import {
6162} from "../features/viewport/viewportMath" ;
6263import {
6364 DEVICE_SCREEN_WIDTH ,
64- STREAM_ORIGIN ,
6565 ZOOM_ANIMATION_MS ,
6666 ZOOM_STEP ,
6767} from "../shared/constants" ;
@@ -102,7 +102,7 @@ function buildScreenMaskUrl(udid: string, stamp: number): string {
102102}
103103
104104function buildAuthenticatedAssetUrl ( path : string , stamp : number ) : string {
105- const url = new URL ( path , ` ${ STREAM_ORIGIN || window . location . origin } /` ) ;
105+ const url = new URL ( apiUrl ( path ) , window . location . href ) ;
106106 url . searchParams . set ( "stamp" , String ( stamp ) ) ;
107107 const token = accessTokenFromLocation ( ) ;
108108 if ( token ) {
@@ -172,10 +172,26 @@ type SimulatorTransition = {
172172 udid : string ;
173173} ;
174174
175- export function AppShell ( ) {
175+ export interface AppShellProps {
176+ apiRoot ?: string ;
177+ fixedSimulatorUDID ?: string | null ;
178+ hideSimulatorSelection ?: boolean ;
179+ pairingEnabled ?: boolean ;
180+ }
181+
182+ export function AppShell ( {
183+ apiRoot = "" ,
184+ fixedSimulatorUDID = null ,
185+ hideSimulatorSelection = false ,
186+ pairingEnabled = true ,
187+ } : AppShellProps = { } ) {
188+ configureSimDeckClient ( { apiRoot } ) ;
176189 const [ initialUiState ] = useState ( readPersistedUiState ) ;
177190 const [ initialSelectedUDID ] = useState (
178- ( ) => readDeviceQueryParam ( ) ?? initialUiState . selectedUDID ,
191+ ( ) =>
192+ fixedSimulatorUDID ??
193+ readDeviceQueryParam ( ) ??
194+ initialUiState . selectedUDID ,
179195 ) ;
180196 const initialViewportState = initialSelectedUDID
181197 ? viewportStateForUDID ( initialUiState , initialSelectedUDID )
@@ -301,6 +317,14 @@ export function AppShell() {
301317 } ) ;
302318
303319 const selectedSimulator =
320+ ( fixedSimulatorUDID
321+ ? ( simulators . find (
322+ ( simulator ) => simulator . udid === fixedSimulatorUDID ,
323+ ) ??
324+ simulators . find ( ( simulator ) =>
325+ simulatorMatchesIdentifier ( simulator , fixedSimulatorUDID ) ,
326+ ) )
327+ : null ) ??
304328 simulators . find ( ( simulator ) => simulator . udid === selectedUDID ) ??
305329 simulators . find ( ( simulator ) =>
306330 simulatorMatchesIdentifier ( simulator , selectedUDID ) ,
@@ -354,6 +378,7 @@ export function AppShell() {
354378 ! selectedSimulator ||
355379 ! streamError ||
356380 readDeviceQueryParam ( ) ||
381+ fixedSimulatorUDID ||
357382 ! isStreamAttachFailure ( streamError )
358383 ) {
359384 return ;
@@ -377,7 +402,13 @@ export function AppShell() {
377402 `${ selectedSimulator . name } did not expose a live simulator screen. Switched to ${ nextSimulator . name } .` ,
378403 ) ;
379404 }
380- } , [ failedStreamUDIDs , selectedSimulator , simulators , streamError ] ) ;
405+ } , [
406+ failedStreamUDIDs ,
407+ fixedSimulatorUDID ,
408+ selectedSimulator ,
409+ simulators ,
410+ streamError ,
411+ ] ) ;
381412 const shouldRenderChrome =
382413 selectedSimulator != null && shouldRenderNativeChrome ( selectedSimulator ) ;
383414 const viewportChromeProfile = shouldRenderChrome ? chromeProfile : null ;
@@ -499,10 +530,14 @@ export function AppShell() {
499530 } , [ accessibilitySelectedId , selectedSimulator ?. udid ] ) ;
500531
501532 useEffect ( ( ) => {
502- if ( selectedSimulator && selectedSimulator . udid !== selectedUDID ) {
533+ if (
534+ ! fixedSimulatorUDID &&
535+ selectedSimulator &&
536+ selectedSimulator . udid !== selectedUDID
537+ ) {
503538 setSelectedUDID ( selectedSimulator . udid ) ;
504539 }
505- } , [ selectedSimulator , selectedUDID ] ) ;
540+ } , [ fixedSimulatorUDID , selectedSimulator , selectedUDID ] ) ;
506541
507542 useEffect ( ( ) => {
508543 const nextViewportState = selectedSimulator
@@ -805,7 +840,9 @@ export function AppShell() {
805840 } ) ;
806841
807842 const pairingRequired =
808- listError === AUTH_REQUIRED_MESSAGE && ! accessTokenFromLocation ( ) ;
843+ pairingEnabled &&
844+ listError === AUTH_REQUIRED_MESSAGE &&
845+ ! accessTokenFromLocation ( ) ;
809846 const error = pairingRequired
810847 ? localError || streamError
811848 : localError || streamError || listError ;
@@ -1221,6 +1258,7 @@ export function AppShell() {
12211258 error = { error }
12221259 filteredSimulators = { filteredSimulators }
12231260 hierarchyVisible = { hierarchyVisible }
1261+ hideSimulatorSelection = { hideSimulatorSelection }
12241262 isLoading = { isLoading }
12251263 menuOpen = { menuOpen }
12261264 menuRef = { menuRef }
0 commit comments