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

main
ts 81 lines 2.43 KB
Raw
1 import { assert, describe, it } from "@effect/vitest";
2 import * as Effect from "effect/Effect";
3 import { vi } from "vite-plus/test";
4
5 import type { LinuxColorScheme } from "./LinuxColorScheme.ts";
6
7 const { nativeTheme } = vi.hoisted(() => ({
8 nativeTheme: { themeSource: "system" as "system" | "light" | "dark" },
9 }));
10
11 vi.mock("electron", () => ({ nativeTheme }));
12
13 import * as ElectronTheme from "./ElectronTheme.ts";
14
15 function setup() {
16 nativeTheme.themeSource = "system";
17 const portal: { report: (scheme: LinuxColorScheme) => void; stopped: boolean } = {
18 report: () => undefined,
19 stopped: false,
20 };
21 const watch = (onChange: (scheme: LinuxColorScheme) => void) => {
22 portal.report = onChange;
23 return {
24 stop: () => {
25 portal.stopped = true;
26 },
27 };
28 };
29 return { portal, watch };
30 }
31
32 describe("ElectronTheme", () => {
33 it.effect("resolves the system appearance from the desktop color scheme as it changes", () =>
34 Effect.gen(function* () {
35 const { portal, watch } = setup();
36 const theme = yield* ElectronTheme.makeWith(watch);
37 yield* theme.setSource("system");
38
39 portal.report("dark");
40 assert.equal(nativeTheme.themeSource, "dark");
41 portal.report("light");
42 assert.equal(nativeTheme.themeSource, "light");
43 portal.report(null);
44 assert.equal(nativeTheme.themeSource, "system");
45 }),
46 );
47
48 it.effect("keeps an explicit appearance over the desktop color scheme", () =>
49 Effect.gen(function* () {
50 const { portal, watch } = setup();
51 const theme = yield* ElectronTheme.makeWith(watch);
52 portal.report("dark");
53
54 yield* theme.setSource("light");
55 portal.report("dark");
56 assert.equal(nativeTheme.themeSource, "light");
57
58 yield* theme.setSource("system");
59 assert.equal(nativeTheme.themeSource, "dark");
60 }),
61 );
62
63 it.effect("stops following the desktop when the layer is released", () =>
64 Effect.gen(function* () {
65 const { portal, watch } = setup();
66 yield* ElectronTheme.makeWith(watch).pipe(Effect.scoped);
67 assert.isTrue(portal.stopped);
68 }),
69 );
70
71 it.effect("leaves the system appearance to Electron when the portal is unavailable", () =>
72 Effect.gen(function* () {
73 setup();
74 const theme = yield* ElectronTheme.makeWith(() => {
75 throw new Error("no session bus");
76 });
77 yield* theme.setSource("system");
78 assert.equal(nativeTheme.themeSource, "system");
79 }),
80 );
81 });