1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3
4import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts";
5import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
6import * as IpcChannels from "../channels.ts";
7import { makeIpcMethod, makeSyncIpcMethod } from "../DesktopIpc.ts";
8
9export const getLocalEnvironmentEnabled = makeSyncIpcMethod({
10 channel: IpcChannels.GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL,
11 result: Schema.Boolean,
12 handler: Effect.fn("desktop.ipc.localEnvironment.getEnabled")(function* () {
13 const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
14 return (yield* appSettings.get).localEnvironmentEnabled;
15 }),
16});
17
18export const setLocalEnvironmentEnabled = makeIpcMethod({
19 channel: IpcChannels.SET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL,
20 payload: Schema.Boolean,
21 result: Schema.Void,
22 handler: Effect.fn("desktop.ipc.localEnvironment.setEnabled")(function* (enabled) {
23 const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
24 const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;
25 const change = yield* appSettings.setLocalEnvironmentEnabled(enabled);
26 if (change.changed) {
27 yield* lifecycle.relaunch(`localEnvironmentEnabled=${enabled}`);
28 }
29 }),
30});