The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as HostProcess from "@t3tools/shared/HostProcess"; |
| 2 | import * as Context from "effect/Context"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as ChildProcess from "effect/process/ChildProcess"; |
| 6 | import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; |
| 7 | |
| 8 | export class DesktopPrimaryPaste extends Context.Service< |
| 9 | DesktopPrimaryPaste, |
| 10 | { |
| 11 | readonly enabled: boolean; |
| 12 | } |
| 13 | >()("@t3tools/desktop/app/DesktopPrimaryPaste") {} |
| 14 | |
| 15 | // Chrome applies gtk-enable-primary-paste from chrome/, which Electron does not include. |
| 16 | // GNOME applies the key's schema default (false since gsettings-desktop-schemas 50); elsewhere |
| 17 | // only a value the user set is a choice. `dconf read` prints nothing for an unset key, but it is |
| 18 | // an optional package (dconf-cli), so without it fall back to the effective value. |
| 19 | const gsettingsQuery = ChildProcess.make( |
| 20 | "gsettings", |
| 21 | ["get", "org.gnome.desktop.interface", "gtk-enable-primary-paste"], |
| 22 | { stdin: "ignore", stderr: "ignore" }, |
| 23 | ); |
| 24 | const dconfQuery = ChildProcess.make( |
| 25 | "dconf", |
| 26 | ["read", "/org/gnome/desktop/interface/gtk-enable-primary-paste"], |
| 27 | { stdin: "ignore", stderr: "ignore" }, |
| 28 | ); |
| 29 | |
| 30 | export const readGtkPrimaryPasteEnabled = Effect.gen(function* () { |
| 31 | const env = yield* HostProcess.Environment; |
| 32 | const spawner = yield* ChildProcessSpawner.ChildProcessSpawner; |
| 33 | const output = yield* env.XDG_CURRENT_DESKTOP?.split(":").includes("GNOME") |
| 34 | ? spawner.string(gsettingsQuery) |
| 35 | : spawner.string(dconfQuery).pipe(Effect.catch(() => spawner.string(gsettingsQuery))); |
| 36 | return output.trim() !== "false"; |
| 37 | }).pipe( |
| 38 | Effect.timeout("2 seconds"), |
| 39 | Effect.orElseSucceed(() => true), |
| 40 | ); |
| 41 | |
| 42 | const make = Effect.gen(function* () { |
| 43 | const platform = yield* HostProcess.Platform; |
| 44 | // Resolved before any window exists so the first preload never sees a provisional value. |
| 45 | const enabled = |
| 46 | platform === "darwin" || platform === "win32" ? true : yield* readGtkPrimaryPasteEnabled; |
| 47 | return DesktopPrimaryPaste.of({ enabled }); |
| 48 | }); |
| 49 | |
| 50 | export const layer = Layer.effect(DesktopPrimaryPaste, make); |