Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/web/src/localEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export function isLocalEnvironmentDisabled(): boolean {
return window.desktopBridge?.getLocalEnvironmentEnabled() === false;
return (
typeof window !== "undefined" && window.desktopBridge?.getLocalEnvironmentEnabled() === false
);
}
17 changes: 15 additions & 2 deletions apps/web/src/state/shell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { EMPTY_SHELL_STATE, type EnvironmentShellState } from "@t3tools/client-r
import { EnvironmentId } from "@t3tools/contracts";
import * as Option from "effect/Option";
import { Atom, AtomRegistry } from "effect/reactivity";
import { describe, expect, it } from "vite-plus/test";
import { describe, expect, it, vi } from "vite-plus/test";

import { createAllEnvironmentProjectSnapshotsReadyAtom } from "./shell";
import { createAllEnvironmentProjectSnapshotsReadyAtom, expectsPrimaryEnvironment } from "./shell";

const LOCAL = EnvironmentId.make("local");
const REMOTE = EnvironmentId.make("remote");
Expand Down Expand Up @@ -135,3 +135,16 @@ describe("project snapshot readiness", () => {
registry.dispose();
});
});

it("expects a primary environment only on desktops with the local environment enabled", () => {
const desktop = (enabled: boolean) => {
vi.stubGlobal("window", { desktopBridge: { getLocalEnvironmentEnabled: () => enabled } });
try {
return expectsPrimaryEnvironment();
} finally {
vi.unstubAllGlobals();
}
};
expect(desktop(true)).toBe(true);
expect(desktop(false)).toBe(false);
});
8 changes: 7 additions & 1 deletion apps/web/src/state/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { AsyncResult, Atom } from "effect/reactivity";
import { environmentCatalog } from "../connection/catalog";
import { connectionAtomRuntime } from "../connection/runtime";
import { isHostedStaticApp } from "../hostedPairing";
import { isLocalEnvironmentDisabled } from "../localEnvironment";

export const shellEnvironment = createShellEnvironmentAtoms(connectionAtomRuntime);
export const environmentShell = createEnvironmentShellAtoms(connectionAtomRuntime);
Expand Down Expand Up @@ -123,9 +124,14 @@ export const allEnvironmentProjectSnapshotsReadyAtom =
createAllEnvironmentProjectSnapshotsReadyAtom({
catalogValueAtom: environmentCatalog.catalogValueAtom,
shellStateValueAtom: environmentShell.stateValueAtom,
requiresPrimaryEnvironment: !isHostedStaticApp(),
requiresPrimaryEnvironment: expectsPrimaryEnvironment(),
});

/** Hosted clients and desktops with the local environment disabled never discover a primary. */
export function expectsPrimaryEnvironment(): boolean {
return !isHostedStaticApp() && !isLocalEnvironmentDisabled();
}

export const allReachableShellsLiveAtom = Atom.make((get) => {
const catalog = get(environmentCatalog.catalogValueAtom);
if (!catalogIsComplete(catalog, !isHostedStaticApp())) return false;
Expand Down
Loading