Open History to see the last commit
1import {
2 createAssetEnvironmentAtoms,
3 createProjectFaviconUrlAtomFamily,
4} from "@t3tools/client-runtime/state/assets";
5import { Atom } from "effect/unstable/reactivity";
6
7import { connectionAtomRuntime } from "../connection/runtime";
8import { projectFaviconCache } from "../assets/projectFaviconCache";
9import { isElectron } from "../env";
10import { primaryEnvironmentIdAtom } from "./primaryEnvironment";
11import { environmentSession } from "./session";
12
13const localMediaEnvironment = Atom.make((get) => {
14 if (!isElectron) return null;
15 const environmentId = get(primaryEnvironmentIdAtom);
16 if (environmentId === null) return null;
17 const connection = get(environmentSession.preparedConnectionValueAtom(environmentId));
18 // The session's bootstrap config clears on disconnect and refreshes on reconnect.
19 const config = get(environmentSession.initialConfigValueAtom(environmentId));
20 return connection._tag === "None" || config === null
21 ? null
22 : { environmentId, httpBaseUrl: connection.value.httpBaseUrl };
23});
24
25export const assetEnvironment = createAssetEnvironmentAtoms(
26 connectionAtomRuntime,
27 localMediaEnvironment,
28);
29
30export const projectFaviconUrlAtom = createProjectFaviconUrlAtomFamily({
31 imageCache: projectFaviconCache,
32 createUrl: assetEnvironment.createUrl,
33 preparedConnection: environmentSession.preparedConnectionValueAtom,
34});