The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): published themes reach the app when it uses this machine's service (#26324)
Co-authored-by: notcompromised <peyton.lamb111@gmail.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Yash Singh <saiansh2525@gmail.com>
Peyton Lamb committed
Nov 7, 2026 at 05:19 UTC
67fdc53823894f96e5946da80fac5b6c34c0487d
15 files changed
+168
-37
apps/desktop/src/ipc/DesktopIpcHandlers.ts
+2
@@ -6,6 +6,7 @@ import { installNotificationBadge } from "./methods/notificationBadge.ts";
6
import { getClientSettings, setClientSettings } from "./methods/clientSettings.ts";
7
import { getConnectionCatalog, setConnectionCatalog } from "./methods/connectionCatalog.ts";
8
import {
9
+ getHostEnvironmentId,
10
getLocalEnvironmentEnabled,
11
setLocalEnvironmentEnabled,
12
} from "./methods/localEnvironment.ts";
@@ -100,6 +101,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
101
yield* ipc.handleSync(getLocalEnvironmentBootstraps);
102
yield* ipc.handleSync(getLocalEnvironmentEnabled);
103
yield* ipc.handle(setLocalEnvironmentEnabled);
104
+ yield* ipc.handle(getHostEnvironmentId);
105
yield* ipc.handle(getLocalEnvironmentBearerToken);
106
107
yield* ipc.handle(getClientSettings);
apps/desktop/src/ipc/channels.ts
+1
@@ -38,6 +38,7 @@ export const GET_PREFERRED_SYSTEM_LANGUAGES_CHANNEL = "desktop:get-preferred-sys
38
export const GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL = "desktop:get-local-environment-bootstraps";
39
export const GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL = "desktop:get-local-environment-enabled";
40
export const SET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL = "desktop:set-local-environment-enabled";
41
+export const GET_HOST_ENVIRONMENT_ID_CHANNEL = "desktop:get-host-environment-id";
42
export const GET_LOCAL_ENVIRONMENT_BEARER_TOKEN_CHANNEL =
43
"desktop:get-local-environment-bearer-token";
44
export const GET_CLIENT_SETTINGS_CHANNEL = "desktop:get-client-settings";
apps/desktop/src/ipc/methods/localEnvironment.test.ts
+28
-1
@@ -1,4 +1,7 @@
1
import { assert, describe, it } from "@effect/vitest";
2
+import * as NodeServices from "@effect/platform-node/NodeServices";
3
+import * as FileSystem from "effect/FileSystem";
4
+import * as Path from "effect/Path";
5
import * as Effect from "effect/Effect";
6
import * as Layer from "effect/Layer";
7
@@ -10,7 +13,11 @@ import * as ElectronApp from "../../electron/ElectronApp.ts";
13
import * as ElectronTheme from "../../electron/ElectronTheme.ts";
14
import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
15
import * as DesktopWindow from "../../window/DesktopWindow.ts";
13
-import { getLocalEnvironmentEnabled, setLocalEnvironmentEnabled } from "./localEnvironment.ts";
16
+import {
17
+ getHostEnvironmentId,
18
+ getLocalEnvironmentEnabled,
19
+ setLocalEnvironmentEnabled,
20
+} from "./localEnvironment.ts";
21
22
const layerUnusedLifecycleRuntime = Layer.mergeAll(
23
DesktopShutdown.layer,
@@ -27,6 +34,26 @@ const layerUnusedLifecycleRuntime = Layer.mergeAll(
34
);
35
36
describe("local environment IPC", () => {
37
+ it.effect("reads the shared home identity without creating one", () =>
38
+ Effect.gen(function* () {
39
+ const fs = yield* FileSystem.FileSystem;
40
+ const path = yield* Path.Path;
41
+ const stateDir = yield* fs.makeTempDirectoryScoped();
42
+ const environment = DesktopEnvironment.DesktopEnvironment.of({
43
+ path,
44
+ stateDir,
45
+ } as DesktopEnvironment.DesktopEnvironment["Service"]);
46
+ const read = getHostEnvironmentId
47
+ .handler(undefined)
48
+ .pipe(Effect.provideService(DesktopEnvironment.DesktopEnvironment, environment));
49
+ assert.strictEqual(yield* read, null);
50
+ assert.isFalse(yield* fs.exists(path.join(stateDir, "environment-id")));
51
+ yield* fs.writeFileString(path.join(stateDir, "environment-id"), " service-id\n");
52
+ assert.strictEqual(yield* read, "service-id");
53
+ yield* fs.writeFileString(path.join(stateDir, "environment-id"), "\n");
54
+ assert.strictEqual(yield* read, null);
55
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
56
+ );
57
it.effect("relaunches only when the setting changes and keeps other settings", () => {
58
const relaunchReasons: Array<string> = [];
59
const layer = Layer.mergeAll(
apps/desktop/src/ipc/methods/localEnvironment.ts
+17
@@ -1,6 +1,8 @@
1
import * as Effect from "effect/Effect";
2
+import * as FileSystem from "effect/FileSystem";
3
import * as Schema from "effect/Schema";
4
5
+import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts";
6
import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts";
7
import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
8
import * as IpcChannels from "../channels.ts";
@@ -28,3 +30,18 @@ export const setLocalEnvironmentEnabled = makeIpcMethod({
30
}
31
}),
32
});
33
+
34
+// A background service sharing this app's T3 home records its environment ID in the same state dir.
35
+export const getHostEnvironmentId = makeIpcMethod({
36
+ channel: IpcChannels.GET_HOST_ENVIRONMENT_ID_CHANNEL,
37
+ payload: Schema.Void,
38
+ result: Schema.NullOr(Schema.String),
39
+ handler: Effect.fn("desktop.ipc.localEnvironment.getHostEnvironmentId")(function* () {
40
+ const environment = yield* DesktopEnvironment.DesktopEnvironment;
41
+ const fileSystem = yield* FileSystem.FileSystem;
42
+ const contents = yield* fileSystem
43
+ .readFileString(environment.path.join(environment.stateDir, "environment-id"))
44
+ .pipe(Effect.orElseSucceed(() => ""));
45
+ return contents.trim() || null;
46
+ }),
47
+});
apps/desktop/src/preload.ts
+1
@@ -126,6 +126,7 @@ contextBridge.exposeInMainWorld("desktopBridge", {
126
ipcRenderer.sendSync(IpcChannels.GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL) !== false,
127
setLocalEnvironmentEnabled: (enabled) =>
128
ipcRenderer.invoke(IpcChannels.SET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL, enabled),
129
+ getHostEnvironmentId: () => ipcRenderer.invoke(IpcChannels.GET_HOST_ENVIRONMENT_ID_CHANNEL),
130
getClientSettings: () => ipcRenderer.invoke(IpcChannels.GET_CLIENT_SETTINGS_CHANNEL),
131
setClientSettings: (settings) =>
132
ipcRenderer.invoke(IpcChannels.SET_CLIENT_SETTINGS_CHANNEL, settings),
apps/web/src/appInit.tsx
+2
@@ -32,6 +32,7 @@ import {
32
import { startDefaultThemeAdoption } from "./hooks/useDefaultTheme";
33
import { startEnvironmentThemeRepaint } from "./hooks/useEnvironmentTheme";
34
import { readLocalStorageValue, subscribeLocalStorageKey } from "./hooks/useLocalStorage";
35
+import { startHostEnvironmentLookup } from "./state/primaryEnvironment";
36
import {
37
getClientSettings,
38
startModelPreferencesMigration,
@@ -180,6 +181,7 @@ export function startAppServices(): AppRouter {
181
182
startClientAppearance();
183
startDocumentTitle();
184
+ startHostEnvironmentLookup();
185
startEnvironmentThemeRepaint();
186
startBrowserChromeThemeSync(router);
187
startDefaultThemeAdoption();
apps/web/src/hooks/useDefaultTheme.ts
+7
-7
@@ -1,6 +1,6 @@
1
import { appAtomRegistry } from "../rpc/atomRegistry";
2
-import { primaryEnvironmentIdAtom } from "../state/primaryEnvironment";
3
-import { primaryServerSettingsAtom } from "../state/server";
2
+import { themeEnvironmentIdAtom } from "../state/primaryEnvironment";
3
+import { themeServerSettingsAtom } from "../state/server";
4
import { getThemeDefinition, singleAppearanceOf, subscribeToCustomThemes } from "../themePalette";
5
import { setAppearanceMode, setTheme } from "./useTheme";
6
@@ -45,9 +45,9 @@ function writeAppliedGeneration(storageKey: string, generation: string): void {
45
46
function adoptDefaultTheme(): void {
47
if (typeof window === "undefined") return;
48
- const environmentId = appAtomRegistry.get(primaryEnvironmentIdAtom);
48
+ const environmentId = appAtomRegistry.get(themeEnvironmentIdAtom);
49
if (environmentId === null) return;
50
- const { defaultTheme, defaultThemeSetAt } = appAtomRegistry.get(primaryServerSettingsAtom);
50
+ const { defaultTheme, defaultThemeSetAt } = appAtomRegistry.get(themeServerSettingsAtom);
51
const definition = getThemeDefinition(defaultTheme);
52
const storageKey = `${APPLIED_DEFAULT_THEME_STORAGE_PREFIX}${environmentId}`;
53
const generation = defaultThemeToApply({
@@ -68,15 +68,15 @@ function adoptDefaultTheme(): void {
68
}
69
70
/**
71
- * Applies the primary environment's default theme once per generation. Start it after the
71
+ * Applies the theme environment's default theme once per generation. Start it after the
72
* environment theme sync so a first-run client adopting the environment's own theme finds it
73
* already in the library; it re-checks when published or custom palettes change, so a theme
74
* that resolves late still applies.
75
*/
76
export function startDefaultThemeAdoption(): () => void {
77
const unsubscribes = [
78
- appAtomRegistry.subscribe(primaryEnvironmentIdAtom, adoptDefaultTheme),
79
- appAtomRegistry.subscribe(primaryServerSettingsAtom, adoptDefaultTheme),
78
+ appAtomRegistry.subscribe(themeEnvironmentIdAtom, adoptDefaultTheme),
79
+ appAtomRegistry.subscribe(themeServerSettingsAtom, adoptDefaultTheme),
80
subscribeToCustomThemes(adoptDefaultTheme),
81
];
82
adoptDefaultTheme();
apps/web/src/hooks/useEnvironmentTheme.test.ts
+1
-1
@@ -9,7 +9,7 @@ const publishedThemes = vi.hoisted(() => ({
9
vi.mock(import("../state/server"), async () => {
10
const { Atom } = await import("effect/reactivity");
11
publishedThemes.atom = Atom.make<ReadonlyArray<EnvironmentTheme>>([]);
12
- return { primaryServerEnvironmentThemesAtom: publishedThemes.atom } as never;
12
+ return { themeServerEnvironmentThemesAtom: publishedThemes.atom } as never;
13
});
14
const refreshTheme = vi.hoisted(() => vi.fn());
15
vi.mock(import("./useTheme"), () => ({ refreshTheme }) as never);
apps/web/src/state/primaryEnvironment.test.ts
new
+41
@@ -0,0 +1,41 @@
1
+import { EnvironmentId } from "@t3tools/contracts";
2
+import { Atom, AtomRegistry } from "effect/reactivity";
3
+import { describe, expect, it } from "vite-plus/test";
4
+
5
+import { createThemeEnvironmentIdAtom } from "./primaryEnvironment";
6
+
7
+const PRIMARY = EnvironmentId.make("primary");
8
+const SERVICE = EnvironmentId.make("service");
9
+const REMOTE = EnvironmentId.make("remote");
10
+
11
+function themeEnvironmentId(input: {
12
+ primary: EnvironmentId | null;
13
+ host: string | null;
14
+ catalog: ReadonlyArray<EnvironmentId>;
15
+}) {
16
+ const atom = createThemeEnvironmentIdAtom({
17
+ primaryEnvironmentIdAtom: Atom.make(input.primary),
18
+ hostEnvironmentIdAtom: Atom.make(input.host),
19
+ catalogValueAtom: Atom.make({ entries: new Map(input.catalog.map((id) => [id, null])) }),
20
+ });
21
+ return AtomRegistry.make().get(atom);
22
+}
23
+
24
+describe("themeEnvironmentIdAtom", () => {
25
+ it("prefers the primary environment over this machine's background service", () => {
26
+ expect(
27
+ themeEnvironmentId({ primary: PRIMARY, host: "service", catalog: [PRIMARY, SERVICE] }),
28
+ ).toBe(PRIMARY);
29
+ });
30
+
31
+ it("uses the connected background service sharing the app's T3 home when there is no primary", () => {
32
+ expect(themeEnvironmentId({ primary: null, host: "service", catalog: [REMOTE, SERVICE] })).toBe(
33
+ SERVICE,
34
+ );
35
+ });
36
+
37
+ it("uses no environment when that service is not among the connections", () => {
38
+ expect(themeEnvironmentId({ primary: null, host: "service", catalog: [REMOTE] })).toBeNull();
39
+ expect(themeEnvironmentId({ primary: null, host: null, catalog: [REMOTE] })).toBeNull();
40
+ });
41
+});
apps/web/src/state/primaryEnvironment.ts
+37
@@ -1,6 +1,8 @@
1
+import type { EnvironmentId } from "@t3tools/contracts";
2
import { Atom } from "effect/reactivity";
3
4
import { environmentCatalog } from "../connection/catalog";
5
+import { appAtomRegistry } from "../rpc/atomRegistry";
6
7
export const primaryEnvironmentIdAtom = Atom.make((get) => {
8
for (const [environmentId, entry] of get(environmentCatalog.catalogValueAtom).entries) {
@@ -10,3 +12,38 @@ export const primaryEnvironmentIdAtom = Atom.make((get) => {
12
}
13
return null;
14
}).pipe(Atom.withLabel("web-primary-environment-id"));
15
+
16
+const hostEnvironmentIdAtom = Atom.make<string | null>(null).pipe(
17
+ Atom.keepAlive,
18
+ Atom.withLabel("web-host-environment-id"),
19
+);
20
+
21
+// Without a primary, only the service sharing the desktop app's T3 home supplies themes.
22
+export function createThemeEnvironmentIdAtom(input: {
23
+ readonly primaryEnvironmentIdAtom: Atom.Atom<EnvironmentId | null>;
24
+ readonly hostEnvironmentIdAtom: Atom.Atom<string | null>;
25
+ readonly catalogValueAtom: Atom.Atom<{ readonly entries: ReadonlyMap<EnvironmentId, unknown> }>;
26
+}) {
27
+ return Atom.make((get) => {
28
+ const primaryEnvironmentId = get(input.primaryEnvironmentIdAtom);
29
+ if (primaryEnvironmentId !== null) return primaryEnvironmentId;
30
+ const hostEnvironmentId = get(input.hostEnvironmentIdAtom);
31
+ for (const environmentId of get(input.catalogValueAtom).entries.keys()) {
32
+ if (environmentId === hostEnvironmentId) return environmentId;
33
+ }
34
+ return null;
35
+ }).pipe(Atom.withLabel("web-theme-environment-id"));
36
+}
37
+
38
+export const themeEnvironmentIdAtom = createThemeEnvironmentIdAtom({
39
+ primaryEnvironmentIdAtom,
40
+ hostEnvironmentIdAtom,
41
+ catalogValueAtom: environmentCatalog.catalogValueAtom,
42
+});
43
+
44
+export function startHostEnvironmentLookup(): void {
45
+ void window.desktopBridge
46
+ ?.getHostEnvironmentId?.()
47
+ .then((environmentId) => appAtomRegistry.set(hostEnvironmentIdAtom, environmentId))
48
+ .catch(() => {});
49
+}
apps/web/src/state/server.ts
+13
-4
@@ -26,7 +26,7 @@ import { isConnectedWithConfig } from "../components/settings/scopedSettings";
26
import { environmentCatalog } from "../connection/catalog";
27
import { connectionAtomRuntime } from "../connection/runtime";
28
import { environmentAtomList } from "./environmentAtomList";
29
-import { primaryEnvironmentIdAtom } from "./primaryEnvironment";
29
+import { primaryEnvironmentIdAtom, themeEnvironmentIdAtom } from "./primaryEnvironment";
30
import { environmentSession } from "./session";
31
import { reuseProvidersIgnoringCheckedAt } from "./serverProviders.logic";
32
@@ -173,10 +173,19 @@ export const primaryServerAvailableEditorsAtom = Atom.make(
173
174
const EMPTY_ENVIRONMENT_THEMES: ReadonlyArray<EnvironmentTheme> = [];
175
176
-export const primaryServerEnvironmentThemesAtom = Atom.make(
176
+const themeServerConfigAtom = Atom.make((get): ServerConfig | null => {
177
+ const environmentId = get(themeEnvironmentIdAtom);
178
+ return environmentId === null ? null : get(serverEnvironment.configValueAtom(environmentId));
179
+}).pipe(Atom.withLabel("web-theme-server-config"));
180
+
181
+export const themeServerEnvironmentThemesAtom = Atom.make(
182
(get): ReadonlyArray<EnvironmentTheme> =>
178
- get(primaryServerConfigAtom)?.environmentThemes ?? EMPTY_ENVIRONMENT_THEMES,
179
-).pipe(Atom.withLabel("web-primary-server-environment-themes"));
183
+ get(themeServerConfigAtom)?.environmentThemes ?? EMPTY_ENVIRONMENT_THEMES,
184
+).pipe(Atom.withLabel("web-theme-server-environment-themes"));
185
+
186
+export const themeServerSettingsAtom = Atom.make(
187
+ (get): ServerSettings => get(themeServerConfigAtom)?.settings ?? DEFAULT_SERVER_SETTINGS,
188
+).pipe(Atom.withLabel("web-theme-server-settings"));
189
190
export const providersIgnoringCheckedAtAtom = Atom.family((environmentId: EnvironmentId) =>
191
Atom.make((get): ReadonlyArray<ServerProvider> =>
apps/web/src/themePalette.ts
+2
-2
@@ -30,7 +30,7 @@ import {
30
} from "./lib/contextChipAccents";
31
32
import { appAtomRegistry, subscribeAtomChanges } from "./rpc/atomRegistry";
33
-import { primaryServerEnvironmentThemesAtom } from "./state/server";
33
+import { themeServerEnvironmentThemesAtom } from "./state/server";
34
35
export { EMBER_THEME, GROVE_THEME, IRIS_THEME, OCEAN_THEME, T3_CHAT_THEME, THEME_COLOR_ROLES };
36
export type { ThemeAppearance, ThemeColorRole, ThemeColors, ThemeDefinition, ThemeVariants };
@@ -315,7 +315,7 @@ export function publishedThemeDefinitions(
315
// Every reconnect snapshot delivers a fresh but usually identical array; keeping the
316
// previous one skips regenerating palettes and repainting the document for it.
317
const publishedThemesAtom = Atom.make((get): ReadonlyArray<EnvironmentTheme> => {
318
- const next = get(primaryServerEnvironmentThemesAtom);
318
+ const next = get(themeServerEnvironmentThemesAtom);
319
const previous = Option.getOrNull(get.self<ReadonlyArray<EnvironmentTheme>>());
320
return previous !== null && Equal.equals(previous, next) ? previous : next;
321
}).pipe(Atom.withLabel("web-published-environment-themes"));
docs/user/appearance.md
+3
-1
@@ -57,7 +57,9 @@ change. Export your theme as JSON to share it.
57
## Environment themes
58
59
Environment themes and defaults come from the server serving your web app or the desktop app's
60
-main local environment. app.t3.codes and additional connections do not use them.
60
+main local environment. With the desktop app's local environment off, they come from the
61
+[background service](./background-service.md) on the same machine while the app is connected to
62
+it. app.t3.codes and other connections do not use them.
63
64
Select a published theme in **Settings → Appearance** to follow its palette as the server updates
65
it. **Duplicate** makes an independent copy you can edit. A saved custom theme with the same ID
packages/contracts/src/ipc.ts
+2
@@ -1053,6 +1053,8 @@ export interface DesktopBridge {
1053
getLocalEnvironmentBootstraps: () => readonly DesktopEnvironmentBootstrap[];
1054
getLocalEnvironmentEnabled: () => boolean;
1055
setLocalEnvironmentEnabled: (enabled: boolean) => Promise<void>;
1056
+ /** The environment ID recorded in this app's T3 home, such as its own machine's background service. */
1057
+ getHostEnvironmentId?: () => Promise<string | null>;
1058
getLocalEnvironmentBearerToken: () => Promise<string>;
1059
getClientSettings: () => Promise<ClientSettings | null>;
1060
setClientSettings: (settings: ClientSettings) => Promise<void>;
packages/effect-acp/src/protocol.ts
+11
-21
@@ -178,6 +178,13 @@ const makeStrictNdJsonRpcParser = () => {
178
const codec = RpcSerialization.jsonRpc().makeUnsafe();
179
const decoder = new TextDecoder();
180
let buffer = "";
181
+ const decodeLine = (line: string): ReadonlyArray<AcpDecodedWireMessage> =>
182
+ codec.decode(line).map((message) => ({
183
+ message: normalizeAcpJsonRpcError(
184
+ message as RpcMessage.FromClientEncoded | RpcMessage.FromServerEncoded,
185
+ ),
186
+ lineLength: line.length,
187
+ }));
188
return {
189
// Every message in a batch line is charged the whole line.
190
decode: (bytes: Uint8Array | string): ReadonlyArray<AcpDecodedWireMessage> => {
@@ -190,21 +197,14 @@ const makeStrictNdJsonRpcParser = () => {
197
}
198
const lines = (buffer + chunk.slice(0, lastNewline)).split("\n");
199
buffer = chunk.slice(lastNewline + 1);
193
- return lines.flatMap((line) =>
194
- codec.decode(line).map((message) => ({
195
- message: normalizeAcpJsonRpcError(
196
- message as RpcMessage.FromClientEncoded | RpcMessage.FromServerEncoded,
197
- ),
198
- lineLength: line.length,
199
- })),
200
- );
200
+ return lines.flatMap(decodeLine);
201
},
202
// A truncated final line is left to the exit status, which explains a crash better.
203
- end: (): ReadonlyArray<unknown> => {
203
+ end: (): ReadonlyArray<AcpDecodedWireMessage> => {
204
const line = buffer + decoder.decode();
205
buffer = "";
206
try {
207
- return line.trim() === "" ? [] : codec.decode(line);
207
+ return line.trim() === "" ? [] : decodeLine(line);
208
} catch {
209
return [];
210
}
@@ -807,17 +807,7 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
807
),
808
),
809
Effect.andThen(
810
- Effect.suspend(() =>
811
- Effect.forEach(
812
- (
813
- parser.end() as ReadonlyArray<
814
- RpcMessage.FromClientEncoded | RpcMessage.FromServerEncoded
815
- >
816
- ).map(normalizeAcpJsonRpcError),
817
- routeDecodedMessage,
818
- { discard: true },
819
- ),
820
- ),
810
+ Effect.suspend(() => Effect.forEach(parser.end(), routeDecodedMessage, { discard: true })),
811
),
812
// Anything that ends the reader, including a defect in a callback it runs,
813
// terminates the connection so pending requests fail instead of hanging.