File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,9 +7,9 @@ import { EMPTY_SHELL_STATE, type EnvironmentShellState } from "@t3tools/client-r
77import { EnvironmentId } from "@t3tools/contracts" ;
88import * as Option from "effect/Option" ;
99import { Atom , AtomRegistry } from "effect/reactivity" ;
10- import { describe , expect , it } from "vite-plus/test" ;
10+ import { describe , expect , it , vi } from "vite-plus/test" ;
1111
12- import { createAllEnvironmentProjectSnapshotsReadyAtom } from "./shell" ;
12+ import { createAllEnvironmentProjectSnapshotsReadyAtom , expectsPrimaryEnvironment } from "./shell" ;
1313
1414const LOCAL = EnvironmentId . make ( "local" ) ;
1515const REMOTE = EnvironmentId . make ( "remote" ) ;
@@ -135,3 +135,16 @@ describe("project snapshot readiness", () => {
135135 registry . dispose ( ) ;
136136 } ) ;
137137} ) ;
138+
139+ it ( "expects a primary environment only on desktops with the local environment enabled" , ( ) => {
140+ const desktop = ( enabled : boolean ) => {
141+ vi . stubGlobal ( "window" , { desktopBridge : { getLocalEnvironmentEnabled : ( ) => enabled } } ) ;
142+ try {
143+ return expectsPrimaryEnvironment ( ) ;
144+ } finally {
145+ vi . unstubAllGlobals ( ) ;
146+ }
147+ } ;
148+ expect ( desktop ( true ) ) . toBe ( true ) ;
149+ expect ( desktop ( false ) ) . toBe ( false ) ;
150+ } ) ;
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { AsyncResult, Atom } from "effect/reactivity";
2121import { environmentCatalog } from "../connection/catalog" ;
2222import { connectionAtomRuntime } from "../connection/runtime" ;
2323import { isHostedStaticApp } from "../hostedPairing" ;
24+ import { isLocalEnvironmentDisabled } from "../localEnvironment" ;
2425
2526export const shellEnvironment = createShellEnvironmentAtoms ( connectionAtomRuntime ) ;
2627export const environmentShell = createEnvironmentShellAtoms ( connectionAtomRuntime ) ;
@@ -126,9 +127,14 @@ export const allEnvironmentProjectSnapshotsReadyAtom =
126127 requiresPrimaryEnvironment : ! isHostedStaticApp ( ) ,
127128 } ) ;
128129
130+ /** Hosted clients and desktops with the local environment disabled never discover a primary. */
131+ export function expectsPrimaryEnvironment ( ) : boolean {
132+ return ! isHostedStaticApp ( ) && ! isLocalEnvironmentDisabled ( ) ;
133+ }
134+
129135export const allReachableShellsLiveAtom = Atom . make ( ( get ) => {
130136 const catalog = get ( environmentCatalog . catalogValueAtom ) ;
131- if ( ! catalogIsComplete ( catalog , ! isHostedStaticApp ( ) ) ) return false ;
137+ if ( ! catalogIsComplete ( catalog , expectsPrimaryEnvironment ( ) ) ) return false ;
132138 for ( const environmentId of enabledEnvironmentIds ( catalog ) ) {
133139 const shell = get ( environmentShell . stateValueAtom ( environmentId ) ) ;
134140 if ( shell . status === "live" && Option . isSome ( shell . snapshot ) ) continue ;
You can’t perform that action at this time.
0 commit comments