Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d5fce53
fix(desktop): include standard Linux AppImage icons
mwolson Apr 24, 2026
bfc4a7c
fix(desktop): select Linux secret storage backend
mwolson May 5, 2026
5cce063
Merge branch 'main' into fix/linux-secret-store-backend
juliusmarminge May 6, 2026
8ad0cc9
fix(web): preserve credential error after rollback failure
mwolson May 6, 2026
b133f59
refactor(web): simplify saved environment rollback error handling
mwolson May 6, 2026
23c7528
Merge remote-tracking branch 'upstream/main' into fix/linux-secret-st…
mwolson May 8, 2026
58ada8b
Merge remote-tracking branch 'upstream/main' into fix/linux-secret-st…
mwolson May 8, 2026
afc9110
Configure Linux desktop startup before Electron ready
mwolson May 9, 2026
b7c2e20
Harden saved SSH environment sessions
mwolson May 9, 2026
5f1fe13
Remove saved environments atomically
mwolson May 9, 2026
1676dd3
Merge remote-tracking branch 'upstream/main' into fix/linux-secret-st…
mwolson May 9, 2026
6fd6ad1
Preserve root paths in early desktop startup
mwolson May 9, 2026
46d0228
Address desktop Effect startup review
mwolson May 9, 2026
2489efc
Merge remote-tracking branch 'upstream/main' into fix/linux-secret-st…
mwolson May 9, 2026
a0a2a94
Tighten desktop pre-ready imports
mwolson May 9, 2026
4e4cc84
Sort desktop settings test fixture
mwolson May 9, 2026
27eadcd
Preserve desktop pre-ready layer ordering
mwolson May 9, 2026
6c34906
Isolate desktop pre-ready platform reads
mwolson May 9, 2026
0f7c19d
Accept JSONC in early desktop settings
mwolson May 9, 2026
749bc07
Remove prescriptive Electron startup guidance
mwolson May 10, 2026
4d69158
Guard missing desktop bridge SSH cleanup
mwolson May 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,32 @@ jobs:
shell: pwsh
run: |
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$installPath = & $vswhere -products * -latest -property installationPath
$setupExe = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\setup.exe"
$proc = Start-Process -FilePath $setupExe `
-ArgumentList "modify", "--installPath", "`"$installPath`"", "--add", `
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64.Spectre", "--quiet", "--norestart" `
-Wait -PassThru -NoNewWindow
if ($null -eq $proc -or $proc.ExitCode -ne 0) {
$code = if ($null -ne $proc) { $proc.ExitCode } else { 1 }
Write-Error "Visual Studio Installer failed with exit code $code"
exit $code
}
$installPath = & $vswhere -products * -latest -property installationPath
$setupExe = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\setup.exe"
$proc = Start-Process -FilePath $setupExe `
-ArgumentList "modify", "--installPath", "`"$installPath`"", "--add", `
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64.Spectre", "--quiet", "--norestart" `
-Wait -PassThru -NoNewWindow
if ($null -eq $proc -or $proc.ExitCode -ne 0) {
$code = if ($null -ne $proc) { $proc.ExitCode } else { 1 }
Write-Error "Visual Studio Installer failed with exit code $code"
exit $code
}

- name: Install ImageMagick
if: matrix.platform == 'linux'
shell: bash
run: |
if ! command -v magick >/dev/null 2>&1 && ! command -v convert >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y imagemagick
fi

if command -v magick >/dev/null 2>&1; then
magick -version
else
convert -version
fi

- name: Prepare Azure Trusted Signing
if: matrix.platform == 'win'
Expand Down
25 changes: 23 additions & 2 deletions apps/desktop/src/app/DesktopApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import * as NetService from "@t3tools/shared/Net";
import * as ElectronApp from "../electron/ElectronApp.ts";
import * as ElectronDialog from "../electron/ElectronDialog.ts";
import * as ElectronProtocol from "../electron/ElectronProtocol.ts";
import * as ElectronSafeStorage from "../electron/ElectronSafeStorage.ts";
import { installDesktopIpcHandlers } from "../ipc/DesktopIpcHandlers.ts";
import { resolveLinuxPasswordStoreSwitch } from "../linuxSecretStorage.ts";
import * as DesktopAppIdentity from "./DesktopAppIdentity.ts";
import * as DesktopApplicationMenu from "../window/DesktopApplicationMenu.ts";
import * as DesktopBackendManager from "../backend/DesktopBackendManager.ts";
Expand Down Expand Up @@ -191,17 +193,26 @@ const startup = Effect.gen(function* () {
const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;
const shellEnvironment = yield* DesktopShellEnvironment.DesktopShellEnvironment;
const desktopSettings = yield* DesktopAppSettings.DesktopAppSettings;
const safeStorage = yield* ElectronSafeStorage.ElectronSafeStorage;
const updates = yield* DesktopUpdates.DesktopUpdates;
const environment = yield* DesktopEnvironment.DesktopEnvironment;

yield* shellEnvironment.installIntoProcess;
const userDataPath = yield* appIdentity.resolveUserDataPath;
yield* electronApp.setPath("userData", userDataPath);
yield* logStartupInfo("runtime logging configured", { logDir: environment.logDir });
yield* desktopSettings.load;
const settings = yield* desktopSettings.load;

if (environment.platform === "linux") {
yield* electronApp.appendCommandLineSwitch("class", environment.linuxWmClass);
const passwordStore = resolveLinuxPasswordStoreSwitch({
preference: settings.linuxPasswordStore,
env: process.env,
});
yield* logStartupInfo("linux password store configured", {
passwordStore: passwordStore ?? "electron-default",
xdgCurrentDesktop: process.env.XDG_CURRENT_DESKTOP ?? null,
xdgSessionDesktop: process.env.XDG_SESSION_DESKTOP ?? null,
});
}

yield* appIdentity.configure;
Expand All @@ -212,6 +223,16 @@ const startup = Effect.gen(function* () {
Effect.catchCause((cause) => fatalStartupCause("whenReady", cause)),
);
yield* logStartupInfo("app ready");
if (environment.platform === "linux") {
const selectedBackend = yield* safeStorage.selectedStorageBackend;
const encryptionAvailable = yield* safeStorage.isEncryptionAvailable.pipe(
Effect.catch(() => Effect.succeed(false)),
);
yield* logStartupInfo("safe storage ready", {
backend: Option.getOrElse(selectedBackend, () => "unknown"),
encryptionAvailable,
});
}
yield* appIdentity.configure;
yield* applicationMenu.configure;
yield* electronProtocol.registerDesktopFileProtocol;
Expand Down
70 changes: 70 additions & 0 deletions apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { assert, describe, it } from "@effect/vitest";

import {
resolveEarlyLinuxElectronOptions,
resolveEarlyLinuxPasswordStorePreference,
} from "./DesktopEarlyElectronStartup.ts";

describe("DesktopEarlyElectronStartup", () => {
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",
readFileString: (path) => {
assert.equal(path, "/home/user/.t3-test/userdata/desktop-settings.json");
return JSON.stringify({ linuxPasswordStore: "kwallet6" });
},
});

assert.equal(preference, "kwallet6");
});

it("falls back to auto when the early settings document is missing or invalid", () => {
const preference = resolveEarlyLinuxPasswordStorePreference({
env: {},
homeDirectory: "/home/user",
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",
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 and DBus fallback", () => {
const options = resolveEarlyLinuxElectronOptions({
env: {
T3CODE_HOME: "/home/user/.t3-test",
XDG_CURRENT_DESKTOP: "niri",
XDG_RUNTIME_DIR: "/run/user/1000",
VITE_DEV_SERVER_URL: "http://127.0.0.1:5173",
},
exists: (path) => path === "/run/user/1000/bus",
homeDirectory: "/home/user",
readFileString: (path) => {
assert.equal(path, "/home/user/.t3-test/dev/desktop-settings.json");
return JSON.stringify({ linuxPasswordStore: "auto" });
},
uid: 1000,
});

assert.deepEqual(options, {
dbusSessionBusAddress: "unix:path=/run/user/1000/bus",
linuxWmClass: "t3code-dev",
passwordStore: "gnome-libsecret",
});
});
});
128 changes: 128 additions & 0 deletions apps/desktop/src/app/DesktopEarlyElectronStartup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// @effect-diagnostics nodeBuiltinImport:off
import * as Fs from "node:fs";
Comment thread
mwolson marked this conversation as resolved.
Outdated
import * as NodeOS from "node:os";

import * as Electron from "electron";

import * as ElectronProtocol from "../electron/ElectronProtocol.ts";
import {
DEFAULT_LINUX_PASSWORD_STORE,
normalizeLinuxPasswordStorePreference,
resolveLinuxPasswordStoreSwitch,
type LinuxPasswordStoreSwitch,
type LinuxPasswordStorePreference,
} from "../linuxSecretStorage.ts";
import { resolveDefaultLinuxDbusSessionBusAddress } from "../shell/DesktopShellEnvironment.ts";
import { resolveDesktopBaseDir, resolveDesktopStateDir } from "./DesktopStatePaths.ts";

interface EarlyDesktopSettingsInput {
readonly env: NodeJS.ProcessEnv;
readonly homeDirectory: string;
readonly readFileString: (path: string) => string;
}

interface EarlyLinuxElectronOptionsInput extends EarlyDesktopSettingsInput {
readonly exists: (path: string) => boolean;
readonly uid: number | undefined;
}

export interface EarlyLinuxElectronOptions {
readonly dbusSessionBusAddress: string | null;
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 isDevelopmentEnvironment = (env: NodeJS.ProcessEnv): boolean =>
trimNonEmpty(env.VITE_DEV_SERVER_URL) !== null;

const joinLinuxPath = (first: string, ...segments: string[]): string => {
const normalizedFirst = first.replace(/\/+$/u, "");
const normalizedSegments = segments.map((segment) => segment.replace(/^\/+|\/+$/gu, ""));
if (first.length > 0 && normalizedFirst.length === 0 && first.startsWith("/")) {
const normalizedPath = normalizedSegments.filter((segment) => segment.length > 0).join("/");
return normalizedPath.length > 0 ? `/${normalizedPath}` : "/";
}
return [normalizedFirst, ...normalizedSegments].filter((segment) => segment.length > 0).join("/");
};
Comment thread
cursor[bot] marked this conversation as resolved.

function resolveEarlyDesktopSettingsPath(input: {
readonly env: NodeJS.ProcessEnv;
readonly homeDirectory: string;
}): string {
const baseDir = resolveDesktopBaseDir({
homeDirectory: input.homeDirectory,
joinPath: joinLinuxPath,
t3Home: input.env.T3CODE_HOME,
});
const stateDir = resolveDesktopStateDir({
baseDir,
isDevelopment: isDevelopmentEnvironment(input.env),
joinPath: joinLinuxPath,
});
return joinLinuxPath(stateDir, "desktop-settings.json");
}

export function resolveEarlyLinuxPasswordStorePreference(
input: EarlyDesktopSettingsInput,
): LinuxPasswordStorePreference {
const settingsPath = resolveEarlyDesktopSettingsPath(input);
try {
const parsed = JSON.parse(input.readFileString(settingsPath)) as unknown;
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
return DEFAULT_LINUX_PASSWORD_STORE;
}
return normalizeLinuxPasswordStorePreference(
(parsed as { readonly linuxPasswordStore?: unknown }).linuxPasswordStore,
);
} catch {
return DEFAULT_LINUX_PASSWORD_STORE;
}
}

export function resolveEarlyLinuxElectronOptions(
input: EarlyLinuxElectronOptionsInput,
): EarlyLinuxElectronOptions {
const preference = resolveEarlyLinuxPasswordStorePreference(input);
return {
dbusSessionBusAddress:
trimNonEmpty(input.env.DBUS_SESSION_BUS_ADDRESS) === null
? resolveDefaultLinuxDbusSessionBusAddress({
env: input.env,
exists: input.exists,
uid: input.uid,
})
: null,
linuxWmClass: isDevelopmentEnvironment(input.env) ? "t3code-dev" : "t3code",
passwordStore: resolveLinuxPasswordStoreSwitch({
preference,
env: input.env,
}),
};
}

export function configureElectronBeforeReady(): void {
if (process.platform === "linux") {
const options = resolveEarlyLinuxElectronOptions({
env: process.env,
exists: Fs.existsSync,
homeDirectory: NodeOS.homedir(),
readFileString: (path) => Fs.readFileSync(path, "utf8"),
uid: process.getuid?.(),
});
if (options.dbusSessionBusAddress !== null) {
process.env.DBUS_SESSION_BUS_ADDRESS = options.dbusSessionBusAddress;
}
if (options.passwordStore !== null) {
Electron.app.commandLine.appendSwitch("password-store", options.passwordStore);
}

Electron.app.commandLine.appendSwitch("class", options.linuxWmClass);
}

ElectronProtocol.registerDesktopSchemePrivilegesSync();
}
9 changes: 7 additions & 2 deletions apps/desktop/src/app/DesktopEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type DesktopSettings,
resolveDefaultDesktopSettings,
} from "../settings/DesktopAppSettings.ts";
import { resolveDesktopBaseDir, resolveDesktopStateDir } from "./DesktopStatePaths.ts";
import * as DesktopConfig from "./DesktopConfig.ts";
import { isNightlyDesktopVersion } from "../updates/updateChannels.ts";

Expand Down Expand Up @@ -151,15 +152,19 @@ const makeDesktopEnvironment = Effect.fn("desktop.environment.make")(function* (
: input.platform === "darwin"
? path.join(homeDirectory, "Library", "Application Support")
: Option.getOrElse(config.xdgConfigHome, () => path.join(homeDirectory, ".config"));
const baseDir = Option.getOrElse(config.t3Home, () => path.join(homeDirectory, ".t3"));
const baseDir = resolveDesktopBaseDir({
homeDirectory,
joinPath: path.join,
t3Home: Option.getOrNull(config.t3Home),
Comment thread
mwolson marked this conversation as resolved.
Outdated
});
const rootDir = path.resolve(input.dirname, "../../..");
const appRoot = input.isPackaged ? input.appPath : rootDir;
const branding = resolveDesktopAppBranding({
isDevelopment,
appVersion: input.appVersion,
});
const displayName = branding.displayName;
const stateDir = path.join(baseDir, isDevelopment ? "dev" : "userdata");
const stateDir = resolveDesktopStateDir({ baseDir, isDevelopment, joinPath: path.join });
const userDataDirName = isDevelopment ? "t3code-dev" : "t3code";
const legacyUserDataDirName = isDevelopment ? "T3 Code (Dev)" : "T3 Code (Alpha)";
const resourcesPath = input.resourcesPath;
Expand Down
24 changes: 24 additions & 0 deletions apps/desktop/src/app/DesktopStatePaths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export type JoinPath = (first: string, ...segments: string[]) => string;

export function resolveDesktopBaseDir(input: {
readonly homeDirectory: string;
readonly joinPath: JoinPath;
readonly t3Home: string | null | undefined;
}): string {
if (typeof input.t3Home === "string") {
const trimmed = input.t3Home.trim();
if (trimmed.length > 0) {
return trimmed;
}
}

return input.joinPath(input.homeDirectory, ".t3");
}

export function resolveDesktopStateDir(input: {
readonly baseDir: string;
readonly isDevelopment: boolean;
readonly joinPath: JoinPath;
}): string {
return input.joinPath(input.baseDir, input.isDevelopment ? "dev" : "userdata");
}
11 changes: 9 additions & 2 deletions apps/desktop/src/electron/ElectronProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export function normalizeDesktopProtocolPathname(rawPath: string): Option.Option
return Option.some(segments.join("/"));
}

const registerDesktopSchemePrivileges = Effect.sync(() => {
/**
* Must run synchronously during process bootstrap, before Electron emits `ready`.
*/
export function registerDesktopSchemePrivilegesSync(): void {
Electron.protocol.registerSchemesAsPrivileged([
{
scheme: DESKTOP_SCHEME,
Expand All @@ -81,7 +84,11 @@ const registerDesktopSchemePrivileges = Effect.sync(() => {
},
},
]);
}).pipe(Effect.withSpan("desktop.electron.protocol.registerSchemePrivileges"));
}

export const registerDesktopSchemePrivileges = Effect.sync(
registerDesktopSchemePrivilegesSync,
).pipe(Effect.withSpan("desktop.electron.protocol.registerSchemePrivileges"));

export const layerSchemePrivileges = Layer.effectDiscard(registerDesktopSchemePrivileges);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way the layers were setup this ran before electron setup. not sure if you changed some layer structure so that's no longer the case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that ordering is still preserved. main.ts now calls configureElectronBeforeReady() synchronously at module startup, before building the Effect runtime/layers and before NodeRuntime.runMain.

I kept only the pre-ready Electron requirements there: registerSchemesAsPrivileged plus the Linux command-line switches. The file protocol handler still registers later after whenReady.


Expand Down
Loading
Loading