import type { DesktopTheme } from "@t3tools/contracts";import * as Context from "effect/Context";import * as Effect from "effect/Effect";import * as Layer from "effect/Layer";import * as Scope from "effect/Scope"; import * as Electron from "electron"; export class ElectronTheme extends Context.Service< ElectronTheme, { readonly shouldUseDarkColors: Effect.Effect<boolean>; readonly setSource: (theme: DesktopTheme) => Effect.Effect<void>; readonly onUpdated: (listener: () => void) => Effect.Effect<void, never, Scope.Scope>; }>()("@t3tools/desktop/electron/ElectronTheme") {} export const make = ElectronTheme.of({ shouldUseDarkColors: Effect.sync(() => Electron.nativeTheme.shouldUseDarkColors), setSource: (theme) => Effect.suspend(() => { Electron.nativeTheme.themeSource = theme; return Effect.void; }), onUpdated: (listener) => Effect.acquireRelease( Effect.suspend(() => { Electron.nativeTheme.on("updated", listener); return Effect.void; }), () => Effect.suspend(() => { Electron.nativeTheme.removeListener("updated", listener); return Effect.void; }), ),}); export const layer = Layer.succeed(ElectronTheme, make);
import type { DesktopTheme } from "@t3tools/contracts";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Scope from "effect/Scope";
import * as Electron from "electron";
export class ElectronTheme extends Context.Service<
ElectronTheme,
{
readonly shouldUseDarkColors: Effect.Effect<boolean>;
readonly setSource: (theme: DesktopTheme) => Effect.Effect<void>;
readonly onUpdated: (listener: () => void) => Effect.Effect<void, never, Scope.Scope>;
}
>()("@t3tools/desktop/electron/ElectronTheme") {}
export const make = ElectronTheme.of({
shouldUseDarkColors: Effect.sync(() => Electron.nativeTheme.shouldUseDarkColors),
setSource: (theme) =>
Effect.suspend(() => {
Electron.nativeTheme.themeSource = theme;
return Effect.void;
}),
onUpdated: (listener) =>
Effect.acquireRelease(
Effect.suspend(() => {
Electron.nativeTheme.on("updated", listener);
return Effect.void;
}),
() =>
Effect.suspend(() => {
Electron.nativeTheme.removeListener("updated", listener);
return Effect.void;
}),
),
});
export const layer = Layer.succeed(ElectronTheme, make);