The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { ProjectFaviconTarget } from "@t3tools/client-runtime/project-favicon-cache"; |
| 2 | import { |
| 3 | createAssetEnvironmentAtoms, |
| 4 | createProjectFaviconUrlAtomFamily, |
| 5 | projectFaviconResource, |
| 6 | } from "@t3tools/client-runtime/state/assets"; |
| 7 | import { Atom } from "effect/reactivity"; |
| 8 | |
| 9 | import { connectionAtomRuntime } from "../connection/runtime"; |
| 10 | import { appAtomRegistry } from "../rpc/atomRegistry"; |
| 11 | import { projectFaviconCache } from "../assets/projectFaviconCache"; |
| 12 | import { isElectron } from "../env"; |
| 13 | import { primaryEnvironmentIdAtom } from "./primaryEnvironment"; |
| 14 | import { environmentProjectClonesAtom } from "./projectClones"; |
| 15 | import { environmentSession } from "./session"; |
| 16 | |
| 17 | const localMediaEnvironment = Atom.make((get) => { |
| 18 | if (!isElectron) return null; |
| 19 | const environmentId = get(primaryEnvironmentIdAtom); |
| 20 | if (environmentId === null) return null; |
| 21 | const connection = get(environmentSession.preparedConnectionValueAtom(environmentId)); |
| 22 | const config = get(environmentSession.initialConfigValueAtom(environmentId)); |
| 23 | return connection._tag === "None" || config === null |
| 24 | ? null |
| 25 | : { environmentId, httpBaseUrl: connection.value.httpBaseUrl }; |
| 26 | }); |
| 27 | |
| 28 | export const assetEnvironment = createAssetEnvironmentAtoms( |
| 29 | connectionAtomRuntime, |
| 30 | localMediaEnvironment, |
| 31 | ); |
| 32 | |
| 33 | export const projectFaviconUrlAtom = createProjectFaviconUrlAtomFamily({ |
| 34 | imageCache: projectFaviconCache, |
| 35 | createUrl: assetEnvironment.createUrl, |
| 36 | preparedConnection: environmentSession.preparedConnectionValueAtom, |
| 37 | projectClones: environmentProjectClonesAtom, |
| 38 | }); |
| 39 | |
| 40 | /** |
| 41 | * Asks the server for a project's icon again. Choosing the icon path a project had before would |
| 42 | * otherwise reuse that path's cached URL, which says "missing" if the file did not exist then. |
| 43 | */ |
| 44 | export function refreshProjectFaviconUrl(target: ProjectFaviconTarget) { |
| 45 | appAtomRegistry.refresh( |
| 46 | assetEnvironment.createUrl({ |
| 47 | environmentId: target.environmentId, |
| 48 | input: { resource: projectFaviconResource(target.cwd, target.faviconPath) }, |
| 49 | }), |
| 50 | ); |
| 51 | } |