Repository navigation
fix(desktop): Niri/Hyprland - Linux secret storage backend #2916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juliusmarminge
merged 4 commits into
pingdotgg:main
from
mwolson:fix/linux-secret-store-backend-v2
Aug 3, 2026
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4f0e953
fix(desktop): Select Linux secret storage backend
mwolson a88e1a3
refactor(desktop): Colocate pre-ready Electron service
mwolson 94a54ea
refactor(desktop): Acquire shell filesystem from Effect
mwolson 454eb3d
Merge branch 'main' into fix/linux-secret-store-backend-v2
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // @effect-diagnostics nodeBuiltinImport:off - tests use POSIX path joining to match the Linux startup boundary. | ||
| import * as NodePath from "node:path"; | ||
| import { assert, describe, it } from "@effect/vitest"; | ||
|
|
||
| import { | ||
| resolveEarlyLinuxElectronOptions, | ||
| resolveEarlyLinuxPasswordStorePreference, | ||
| } from "./DesktopEarlyElectronStartup.ts"; | ||
|
|
||
| describe("DesktopEarlyElectronStartup", () => { | ||
| const joinPath = NodePath.posix.join; | ||
|
|
||
| it("reads the persisted linux password-store preference before Electron is ready", () => { | ||
| const preference = resolveEarlyLinuxPasswordStorePreference({ | ||
| env: { T3CODE_HOME: "/home/user/.t3-test" }, | ||
| homeDirectory: "/home/user", | ||
| joinPath, | ||
| readFileString: (path) => { | ||
| assert.equal(path, "/home/user/.t3-test/userdata/desktop-settings.json"); | ||
| return JSON.stringify({ linuxPasswordStore: "kwallet6" }); | ||
| }, | ||
| }); | ||
|
|
||
| assert.equal(preference, "kwallet6"); | ||
| }); | ||
|
|
||
| it("accepts JSONC in the early desktop settings file", () => { | ||
| const preference = resolveEarlyLinuxPasswordStorePreference({ | ||
| env: { T3CODE_HOME: "/home/user/.t3-test" }, | ||
| homeDirectory: "/home/user", | ||
| joinPath, | ||
| readFileString: () => `{ | ||
| // manually edited setting | ||
| "linuxPasswordStore": "gnome-libsecret", | ||
| }`, | ||
| }); | ||
|
|
||
| assert.equal(preference, "gnome-libsecret"); | ||
| }); | ||
|
|
||
| it("falls back to auto when the early settings document is missing or invalid", () => { | ||
| const preference = resolveEarlyLinuxPasswordStorePreference({ | ||
| env: {}, | ||
| homeDirectory: "/home/user", | ||
| joinPath, | ||
| readFileString: () => { | ||
| throw new Error("missing"); | ||
| }, | ||
| }); | ||
|
|
||
| assert.equal(preference, "auto"); | ||
| }); | ||
|
|
||
| it("preserves absolute root paths when resolving early settings", () => { | ||
| const preference = resolveEarlyLinuxPasswordStorePreference({ | ||
| env: { T3CODE_HOME: "/" }, | ||
| homeDirectory: "/home/user", | ||
| joinPath, | ||
| readFileString: (path) => { | ||
| assert.equal(path, "/userdata/desktop-settings.json"); | ||
| return JSON.stringify({ linuxPasswordStore: "kwallet6" }); | ||
| }, | ||
| }); | ||
|
|
||
| assert.equal(preference, "kwallet6"); | ||
| }); | ||
|
|
||
| it("resolves the early linux Electron switches", () => { | ||
| const options = resolveEarlyLinuxElectronOptions({ | ||
| env: { | ||
| T3CODE_HOME: "/home/user/.t3-test", | ||
| XDG_CURRENT_DESKTOP: "niri", | ||
| VITE_DEV_SERVER_URL: "http://127.0.0.1:5173", | ||
| }, | ||
| homeDirectory: "/home/user", | ||
| joinPath, | ||
| readFileString: (path) => { | ||
| assert.equal(path, "/home/user/.t3-test/userdata/desktop-settings.json"); | ||
| return JSON.stringify({ linuxPasswordStore: "auto" }); | ||
| }, | ||
| }); | ||
|
|
||
| assert.deepEqual(options, { | ||
| linuxWmClass: "t3code-dev", | ||
| passwordStore: "gnome-libsecret", | ||
| }); | ||
| }); | ||
|
|
||
| it("keeps implicit development state under ~/.t3/dev when T3CODE_HOME is unset", () => { | ||
| const preference = resolveEarlyLinuxPasswordStorePreference({ | ||
| env: { | ||
| VITE_DEV_SERVER_URL: "http://127.0.0.1:5173", | ||
| }, | ||
| homeDirectory: "/home/user", | ||
| joinPath, | ||
| readFileString: (path) => { | ||
| assert.equal(path, "/home/user/.t3/dev/desktop-settings.json"); | ||
| return JSON.stringify({ linuxPasswordStore: "kwallet" }); | ||
| }, | ||
| }); | ||
|
|
||
| assert.equal(preference, "kwallet"); | ||
| }); | ||
|
|
||
| it("treats whitespace-only T3CODE_HOME as unconfigured in development", () => { | ||
| const preference = resolveEarlyLinuxPasswordStorePreference({ | ||
| env: { | ||
| T3CODE_HOME: " ", | ||
| VITE_DEV_SERVER_URL: "http://127.0.0.1:5173", | ||
| }, | ||
| homeDirectory: "/home/user", | ||
| joinPath, | ||
| readFileString: (path) => { | ||
| assert.equal(path, "/home/user/.t3/dev/desktop-settings.json"); | ||
| return JSON.stringify({ linuxPasswordStore: "gnome-libsecret" }); | ||
| }, | ||
| }); | ||
|
|
||
| assert.equal(preference, "gnome-libsecret"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { fromLenientJson } from "@t3tools/shared/schemaJson"; | ||
| import * as Option from "effect/Option"; | ||
| import * as Schema from "effect/Schema"; | ||
|
|
||
| import { | ||
| DEFAULT_LINUX_PASSWORD_STORE, | ||
| normalizeLinuxPasswordStorePreference, | ||
| resolveLinuxPasswordStoreSwitch, | ||
| type LinuxPasswordStoreSwitch, | ||
| type LinuxPasswordStorePreference, | ||
| } from "../linuxSecretStorage.ts"; | ||
| import { | ||
| resolveDesktopBaseDir, | ||
| resolveDesktopStateDir, | ||
| type JoinPath, | ||
| } from "./DesktopStatePaths.ts"; | ||
|
|
||
| interface EarlyDesktopSettingsInput { | ||
| readonly env: NodeJS.ProcessEnv; | ||
| readonly homeDirectory: string; | ||
| readonly joinPath: JoinPath; | ||
| readonly readFileString: (path: string) => string; | ||
| } | ||
|
|
||
| type EarlyLinuxElectronOptionsInput = EarlyDesktopSettingsInput; | ||
|
|
||
| export interface EarlyLinuxElectronOptions { | ||
| readonly linuxWmClass: string; | ||
| readonly passwordStore: LinuxPasswordStoreSwitch | null; | ||
| } | ||
|
|
||
| const trimNonEmpty = (value: string | undefined): string | null => { | ||
| const trimmed = value?.trim(); | ||
| return trimmed && trimmed.length > 0 ? trimmed : null; | ||
| }; | ||
|
|
||
| const EarlyDesktopSettingsJson = fromLenientJson( | ||
| Schema.Struct({ | ||
| linuxPasswordStore: Schema.optionalKey(Schema.Unknown), | ||
| }), | ||
| ); | ||
| const decodeEarlyDesktopSettingsJson = Schema.decodeSync(EarlyDesktopSettingsJson); | ||
|
|
||
| const isDevelopmentEnvironment = (env: NodeJS.ProcessEnv): boolean => | ||
| trimNonEmpty(env.VITE_DEV_SERVER_URL) !== null; | ||
|
|
||
| function resolveEarlyDesktopSettingsPath(input: { | ||
| readonly env: NodeJS.ProcessEnv; | ||
| readonly homeDirectory: string; | ||
| readonly joinPath: JoinPath; | ||
| }): string { | ||
| const t3Home = Option.fromUndefinedOr(input.env.T3CODE_HOME); | ||
| const baseDir = resolveDesktopBaseDir({ | ||
| homeDirectory: input.homeDirectory, | ||
| joinPath: input.joinPath, | ||
| t3Home, | ||
| }); | ||
| const stateDir = resolveDesktopStateDir({ | ||
| baseDir, | ||
| isDevelopment: isDevelopmentEnvironment(input.env), | ||
| joinPath: input.joinPath, | ||
| t3Home, | ||
| }); | ||
| return input.joinPath(stateDir, "desktop-settings.json"); | ||
|
cursor[bot] marked this conversation as resolved.
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export function resolveEarlyLinuxPasswordStorePreference( | ||
| input: EarlyDesktopSettingsInput, | ||
| ): LinuxPasswordStorePreference { | ||
| const settingsPath = resolveEarlyDesktopSettingsPath(input); | ||
| try { | ||
| const parsed = decodeEarlyDesktopSettingsJson(input.readFileString(settingsPath)); | ||
| return normalizeLinuxPasswordStorePreference(parsed.linuxPasswordStore); | ||
| } catch { | ||
| return DEFAULT_LINUX_PASSWORD_STORE; | ||
| } | ||
| } | ||
|
|
||
| export function resolveEarlyLinuxElectronOptions( | ||
| input: EarlyLinuxElectronOptionsInput, | ||
| ): EarlyLinuxElectronOptions { | ||
| const preference = resolveEarlyLinuxPasswordStorePreference(input); | ||
| return { | ||
| linuxWmClass: isDevelopmentEnvironment(input.env) ? "t3code-dev" : "t3code", | ||
| passwordStore: resolveLinuxPasswordStoreSwitch({ | ||
| preference, | ||
| env: input.env, | ||
| }), | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.