The best way to control Claude Code, Codex and more from any computer or phone

main
ts 47 lines 2.06 KB
Raw
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";
9 import { makeIpcMethod, makeSyncIpcMethod } from "../DesktopIpc.ts";
10
11 export const getLocalEnvironmentEnabled = makeSyncIpcMethod({
12 channel: IpcChannels.GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL,
13 result: Schema.Boolean,
14 handler: Effect.fn("desktop.ipc.localEnvironment.getEnabled")(function* () {
15 const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
16 return (yield* appSettings.get).localEnvironmentEnabled;
17 }),
18 });
19
20 export const setLocalEnvironmentEnabled = makeIpcMethod({
21 channel: IpcChannels.SET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL,
22 payload: Schema.Boolean,
23 result: Schema.Void,
24 handler: Effect.fn("desktop.ipc.localEnvironment.setEnabled")(function* (enabled) {
25 const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
26 const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;
27 const change = yield* appSettings.setLocalEnvironmentEnabled(enabled);
28 if (change.changed) {
29 yield* lifecycle.relaunch(`localEnvironmentEnabled=${enabled}`);
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 });