@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 69 lines 2.03 KB
Raw
1 export type LinuxPasswordStorePreference =
2 | "auto"
3 | "gnome-libsecret"
4 | "kwallet"
5 | "kwallet5"
6 | "kwallet6";
7 export type LinuxPasswordStoreSwitch = Exclude<LinuxPasswordStorePreference, "auto">;
8
9 export const DEFAULT_LINUX_PASSWORD_STORE: LinuxPasswordStorePreference = "auto";
10
11 // Chromium matches desktop names case-sensitively and stops at the first recognized value.
12 const ELECTRON_LIBSECRET_DESKTOPS = new Set([
13 "Deepin",
14 "GNOME",
15 "Pantheon",
16 "UKUI",
17 "Unity",
18 "X-Cinnamon",
19 "XFCE",
20 ]);
21 // Chromium selects a KWallet generation for KDE from KDE_SESSION_VERSION, so it needs no help.
22 const ELECTRON_KDE_DESKTOP = "KDE";
23 // Chromium recognizes LXQt and still selects basic text for it, so it does need a forced backend.
24 const ELECTRON_UNPROTECTED_DESKTOPS = new Set(["LXQt"]);
25
26 export function normalizeLinuxPasswordStorePreference(
27 value: unknown,
28 ): LinuxPasswordStorePreference {
29 return value === "gnome-libsecret" ||
30 value === "kwallet" ||
31 value === "kwallet5" ||
32 value === "kwallet6"
33 ? value
34 : DEFAULT_LINUX_PASSWORD_STORE;
35 }
36
37 export function resolveLinuxPasswordStoreSwitch(input: {
38 readonly preference: LinuxPasswordStorePreference;
39 readonly env: NodeJS.ProcessEnv;
40 }): LinuxPasswordStoreSwitch | null {
41 if (input.preference !== "auto") {
42 return input.preference;
43 }
44
45 return electronSelectsProtectedBackend(input.env) ? null : "gnome-libsecret";
46 }
47
48 // DESKTOP_SESSION and legacy KDE markers can be stale, so only trust exact XDG_CURRENT_DESKTOP values.
49
50 function electronSelectsProtectedBackend(env: NodeJS.ProcessEnv): boolean {
51 for (const name of splitDesktopNameList(env.XDG_CURRENT_DESKTOP)) {
52 const trimmed = name.trim();
53 if (trimmed.length === 0) {
54 continue;
55 }
56 if (trimmed === ELECTRON_KDE_DESKTOP || ELECTRON_LIBSECRET_DESKTOPS.has(trimmed)) {
57 return true;
58 }
59 if (ELECTRON_UNPROTECTED_DESKTOPS.has(trimmed)) {
60 return false;
61 }
62 }
63
64 return false;
65 }
66
67 function splitDesktopNameList(value: string | undefined): string[] {
68 return value?.split(":") ?? [];
69 }