From ca15ab763f7dff74d2f7e75dbab3119b148d143c Mon Sep 17 00:00:00 2001 From: SaahiilM <47355754+SaahiilM@users.noreply.github.com> Date: Wed, 4 Nov 2026 12:36:48 -0500 Subject: [PATCH 1/9] fix(desktop): disable GPU acceleration on NVIDIA Wayland MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Linux with NVIDIA proprietary drivers inside a Wayland session, Electron's GPU process segfaults before the app can recover. The updater's .desktop entry carries no --disable-gpu, so taskbar/Desktop pins hit a crash loop; only a manual launcher flag avoids it. Detect Linux + Wayland + NVIDIA in pre-ready Electron setup and append --disable-gpu before app.ready, with an opt-out via desktop-settings.json disableGpuAcceleration=false. Explicit --enable-gpu / --disable-gpu always win. No change on X11, AMD/Intel, or non-Wayland sessions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- .../app/DesktopEarlyElectronStartup.test.ts | 74 +++++++++++++++++++ .../src/app/DesktopEarlyElectronStartup.ts | 29 ++++++++ .../src/app/DesktopPreReadyPlatform.test.ts | 4 + .../src/app/DesktopPreReadyPlatform.ts | 12 +++ 4 files changed, 119 insertions(+) diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts index 6d40bd128b77f..75cb6d5258ab1 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts @@ -6,6 +6,7 @@ import { restoreEarlyLinuxDeviceScaleFactor, resolveEarlyLinuxPasswordStorePreference, resolveLinuxDisableFeaturesSwitch, + shouldDisableGpuOnNvidiaWayland, } from "./DesktopEarlyElectronStartup.ts"; describe("DesktopEarlyElectronStartup", () => { @@ -196,4 +197,77 @@ describe("Linux device scale persistence failures", () => { assert.deepEqual(reads, []); assert.deepEqual(applied, []); }); + + describe("shouldDisableGpuOnNvidiaWayland", () => { + const base = { + homeDirectory: "/home/user", + joinPath: NodePath.posix.join, + existsSync: (path: string) => path === "/dev/nvidiactl", + readFileString: () => "{}", + hasSwitch: () => false, + }; + + it("is true on NVIDIA Wayland with no explicit GPU switch", () => { + assert.isTrue( + shouldDisableGpuOnNvidiaWayland({ ...base, env: { XDG_SESSION_TYPE: "wayland" } }), + ); + }); + + it("is false on X11", () => { + assert.isFalse( + shouldDisableGpuOnNvidiaWayland({ ...base, env: { XDG_SESSION_TYPE: "x11" } }), + ); + }); + + it("is false without NVIDIA devices", () => { + assert.isFalse( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "wayland" }, + existsSync: () => false, + }), + ); + }); + + it("is false when --disable-gpu or --enable-gpu was passed explicitly", () => { + for (const name of ["disable-gpu", "enable-gpu"]) { + assert.isFalse( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "wayland" }, + hasSwitch: (switchName) => switchName === name, + }), + ); + } + }); + + it("is false when the user opts out via disableGpuAcceleration=false", () => { + assert.isFalse( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "wayland" }, + readFileString: () => JSON.stringify({ disableGpuAcceleration: false }), + }), + ); + }); + + it("is true when the setting is explicit true or missing file", () => { + assert.isTrue( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "wayland" }, + readFileString: () => JSON.stringify({ disableGpuAcceleration: true }), + }), + ); + assert.isTrue( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "wayland" }, + readFileString: () => { + throw new Error("missing"); + }, + }), + ); + }); + }); }); diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts index 3c571bcf02b1f..0aa0d173a6c3a 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts @@ -40,6 +40,7 @@ const trimNonEmpty = (value: string | undefined): string | null => { const EarlyDesktopSettingsJson = fromLenientJson( Schema.Struct({ + disableGpuAcceleration: Schema.optionalKey(Schema.Boolean), linuxPasswordStore: Schema.optionalKey(Schema.Unknown), }), ); @@ -80,6 +81,34 @@ export function resolveEarlyLinuxPasswordStorePreference( } } +const isWaylandSession = (env: NodeJS.ProcessEnv): boolean => + (trimNonEmpty(env.XDG_SESSION_TYPE) ?? "").toLowerCase() === "wayland"; + +const isNvidiaPresent = (existsSync: (path: string) => boolean): boolean => + existsSync("/dev/nvidiactl") || existsSync("/dev/nvidia0"); + +export function shouldDisableGpuOnNvidiaWayland(input: { + readonly env: NodeJS.ProcessEnv; + readonly homeDirectory: string; + readonly joinPath: JoinPath; + readonly existsSync: (path: string) => boolean; + readonly readFileString: (path: string) => string; + readonly hasSwitch: (name: string) => boolean; +}): boolean { + if (!isWaylandSession(input.env)) return false; + if (input.hasSwitch("disable-gpu") || input.hasSwitch("enable-gpu")) return false; + const settingsPath = resolveEarlyDesktopSettingsPath({ + env: input.env, + homeDirectory: input.homeDirectory, + joinPath: input.joinPath, + }); + try { + const parsed = decodeEarlyDesktopSettingsJson(input.readFileString(settingsPath)); + if (parsed.disableGpuAcceleration === false) return false; + } catch {} + return isNvidiaPresent(input.existsSync); +} + const WAYLAND_COLOR_MANAGER_FEATURE = "WaylandWpColorManagerV1"; const featureListNames = (value: string | null): ReadonlyArray => diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts index f2b176ee3761f..2a94f29231116 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts @@ -16,6 +16,7 @@ const { copyFileSyncMock, execFileSyncMock, readFileSyncMock, + existsSyncMock, } = vi.hoisted(() => ({ appendSwitchMock: vi.fn(), getSwitchValueMock: vi.fn(), @@ -27,6 +28,7 @@ const { copyFileSyncMock: vi.fn(), execFileSyncMock: vi.fn(), readFileSyncMock: vi.fn(), + existsSyncMock: vi.fn(), })); vi.mock("electron", () => ({ @@ -51,6 +53,7 @@ vi.mock("node:fs", () => ({ mkdirSync: mkdirSyncMock, writeFileSync: writeFileSyncMock, copyFileSync: copyFileSyncMock, + existsSync: existsSyncMock, })); vi.mock("node:child_process", () => ({ @@ -71,6 +74,7 @@ describe("DesktopPreReadyPlatform", () => { copyFileSyncMock.mockReset(); execFileSyncMock.mockReset(); readFileSyncMock.mockReset().mockReturnValue("{}"); + existsSyncMock.mockReset().mockReturnValue(false); }); it.effect("persists Linux scaling synchronously across relaunches and settings rewrites", () => { diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.ts index d77544f54b69a..1fc0934e65c78 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.ts @@ -121,6 +121,18 @@ export const make = Effect.gen(function* () { } catch {} // Chromium caches portal identity; set it before any asynchronous initialization. Electron.app.setDesktopName(linux.linuxDesktopEntryName); + if ( + DesktopEarlyElectronStartup.shouldDisableGpuOnNvidiaWayland({ + env: process.env, + homeDirectory, + joinPath: NodePath.posix.join, + existsSync: (path) => NodeFS.existsSync(path), + readFileString: (path) => NodeFS.readFileSync(path, "utf8"), + hasSwitch: (name) => Electron.app.commandLine.hasSwitch(name), + }) + ) { + Electron.app.commandLine.appendSwitch("disable-gpu"); + } if (linux.passwordStore !== null && linuxPasswordStoreCommandLine === null) { Electron.app.commandLine.appendSwitch("password-store", linux.passwordStore); } From ef0661d3c0086a50c9f766f37be489c916601723 Mon Sep 17 00:00:00 2001 From: SaahiilM <47355754+SaahiilM@users.noreply.github.com> Date: Wed, 4 Nov 2026 12:36:48 -0500 Subject: [PATCH 2/9] fix(desktop): persist disableGpuAcceleration opt-out in settings model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NVIDIA Wayland fallback read disableGpuAcceleration from desktop-settings.json, but DesktopAppSettings normalize/encode dropped the unknown field, so any unrelated settings write (window bounds, server exposure, etc.) erased the opt-out and the fallback re-armed. Add disableGpuAcceleration to DesktopSettings (boolean | undefined, default undefined = no preference, keeps the early-startup default), DesktopSettingsDocument, normalizeDesktopSettingsDocument, and toDesktopSettingsDocument. Only explicit values are written. Regression test covers: false survives setMainWindowBounds, setServerExposureMode, and setWslBackendEnabled writes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- .../src/settings/DesktopAppSettings.test.ts | 28 +++++++++++++++++++ .../src/settings/DesktopAppSettings.ts | 7 +++++ 2 files changed, 35 insertions(+) diff --git a/apps/desktop/src/settings/DesktopAppSettings.test.ts b/apps/desktop/src/settings/DesktopAppSettings.test.ts index 7e4b530083097..80261f261c583 100644 --- a/apps/desktop/src/settings/DesktopAppSettings.test.ts +++ b/apps/desktop/src/settings/DesktopAppSettings.test.ts @@ -146,6 +146,31 @@ describe("DesktopSettings", () => { ), ); + it.effect("preserves disableGpuAcceleration:false across unrelated settings writes", () => + withSettings( + Effect.gen(function* () { + const environment = yield* DesktopEnvironment.DesktopEnvironment; + const fileSystem = yield* FileSystem.FileSystem; + const settings = yield* DesktopAppSettings.DesktopAppSettings; + yield* fileSystem.makeDirectory(environment.stateDir, { recursive: true }); + yield* fileSystem.writeFileString( + environment.desktopSettingsPath, + `${JSON.stringify({ disableGpuAcceleration: false })}\n`, + ); + assert.equal((yield* settings.load).disableGpuAcceleration, false); + yield* settings.setMainWindowBounds({ x: 10, y: 20, width: 900, height: 600 }, true); + yield* settings.setServerExposureMode("network-accessible"); + const reloaded = yield* settings.load; + assert.equal(reloaded.disableGpuAcceleration, false); + assert.equal(reloaded.serverExposureMode, "network-accessible"); + const raw = yield* fileSystem.readFileString(environment.desktopSettingsPath); + assert.include(raw, `"disableGpuAcceleration":false`); + yield* settings.setWslBackendEnabled(true); + assert.equal((yield* settings.load).disableGpuAcceleration, false); + }), + ), + ); + it.effect("falls back to defaults when the settings file is malformed", () => withSettings( Effect.gen(function* () { @@ -179,6 +204,7 @@ describe("DesktopSettings", () => { ); assert.deepEqual(yield* settings.load, { + disableGpuAcceleration: undefined, linuxPasswordStore: "auto", localEnvironmentEnabled: true, mainWindowBounds: { x: 120, y: 80, width: 1280, height: 900 }, @@ -297,6 +323,7 @@ describe("DesktopSettings", () => { }); assert.deepEqual(yield* settings.load, { + disableGpuAcceleration: undefined, linuxPasswordStore: "auto", localEnvironmentEnabled: true, mainWindowBounds: null, @@ -326,6 +353,7 @@ describe("DesktopSettings", () => { }); assert.deepEqual(yield* settings.load, { + disableGpuAcceleration: undefined, linuxPasswordStore: "auto", localEnvironmentEnabled: true, mainWindowBounds: null, diff --git a/apps/desktop/src/settings/DesktopAppSettings.ts b/apps/desktop/src/settings/DesktopAppSettings.ts index 6cd34322d98c2..d72032bf8f533 100644 --- a/apps/desktop/src/settings/DesktopAppSettings.ts +++ b/apps/desktop/src/settings/DesktopAppSettings.ts @@ -26,6 +26,7 @@ import { desktopUpdateChannelOf } from "@t3tools/shared/cliRelease"; import { isValidDistroName } from "../wsl/wslPathParsing.ts"; export interface DesktopSettings { + readonly disableGpuAcceleration: boolean | undefined; readonly localEnvironmentEnabled: boolean; readonly linuxPasswordStore: LinuxPasswordStorePreference; readonly mainWindowBounds: DesktopWindowBounds | null; @@ -64,6 +65,7 @@ export const DEFAULT_MAIN_WINDOW_SIZE = { } as const; export const DEFAULT_DESKTOP_SETTINGS: DesktopSettings = { + disableGpuAcceleration: undefined, localEnvironmentEnabled: true, linuxPasswordStore: DEFAULT_LINUX_PASSWORD_STORE, mainWindowBounds: null, @@ -86,6 +88,7 @@ const DesktopWindowBoundsDocument = Schema.Struct({ }); const DesktopSettingsDocument = Schema.Struct({ + disableGpuAcceleration: Schema.optionalKey(Schema.Boolean), localEnvironmentEnabled: Schema.optionalKey(Schema.Boolean), linuxPasswordStore: Schema.optionalKey(Schema.Unknown), mainWindowBounds: Schema.optionalKey(Schema.NullOr(DesktopWindowBoundsDocument)), @@ -215,6 +218,7 @@ function normalizeDesktopSettingsDocument( (parsed.wslBackendEnabled === undefined && parsed.wslMode === "wsl"); return { + disableGpuAcceleration: parsed.disableGpuAcceleration, localEnvironmentEnabled: parsed.localEnvironmentEnabled !== false, linuxPasswordStore: normalizeLinuxPasswordStorePreference(parsed.linuxPasswordStore), mainWindowBounds, @@ -239,6 +243,9 @@ function toDesktopSettingsDocument( ): DesktopSettingsDocument { const document: Mutable = {}; + if (settings.disableGpuAcceleration !== defaults.disableGpuAcceleration) { + document.disableGpuAcceleration = settings.disableGpuAcceleration as boolean; + } if (settings.localEnvironmentEnabled !== defaults.localEnvironmentEnabled) { document.localEnvironmentEnabled = settings.localEnvironmentEnabled; } From 6ecee772d7bf7026fba15a4301a97b581cd25bb1 Mon Sep 17 00:00:00 2001 From: SaahiilM <47355754+SaahiilM@users.noreply.github.com> Date: Wed, 4 Nov 2026 12:36:48 -0500 Subject: [PATCH 3/9] fix(desktop): honor explicit ozone-platform in NVIDIA Wayland GPU fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A user launching with --ozone-platform=x11 inside a Wayland session was still getting --disable-gpu appended because the fallback only checked XDG_SESSION_TYPE. Pass the selected Ozone switch value from DesktopPreReadyPlatform and prefer it over the session variable, falling back to XDG_SESSION_TYPE when no flag is present. Tests cover X11 override in a Wayland session and explicit Wayland with absent session variable. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- .../src/app/DesktopEarlyElectronStartup.test.ts | 17 +++++++++++++++++ .../src/app/DesktopEarlyElectronStartup.ts | 7 ++++--- apps/desktop/src/app/DesktopPreReadyPlatform.ts | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts index 75cb6d5258ab1..9cbd1a4b90fb5 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts @@ -200,6 +200,7 @@ describe("Linux device scale persistence failures", () => { describe("shouldDisableGpuOnNvidiaWayland", () => { const base = { + ozonePlatform: null, homeDirectory: "/home/user", joinPath: NodePath.posix.join, existsSync: (path: string) => path === "/dev/nvidiactl", @@ -219,6 +220,22 @@ describe("Linux device scale persistence failures", () => { ); }); + it("respects an explicit --ozone-platform=x11 override in a Wayland session", () => { + assert.isFalse( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "wayland" }, + ozonePlatform: "x11", + }), + ); + }); + + it("respects an explicit --ozone-platform=wayland when the session variable is absent", () => { + assert.isTrue( + shouldDisableGpuOnNvidiaWayland({ ...base, env: {}, ozonePlatform: "wayland" }), + ); + }); + it("is false without NVIDIA devices", () => { assert.isFalse( shouldDisableGpuOnNvidiaWayland({ diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts index 0aa0d173a6c3a..eaa7f2467cc89 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts @@ -81,21 +81,22 @@ export function resolveEarlyLinuxPasswordStorePreference( } } -const isWaylandSession = (env: NodeJS.ProcessEnv): boolean => - (trimNonEmpty(env.XDG_SESSION_TYPE) ?? "").toLowerCase() === "wayland"; +const isWaylandPlatform = (env: NodeJS.ProcessEnv, ozonePlatform: string | null): boolean => + (ozonePlatform ?? trimNonEmpty(env.XDG_SESSION_TYPE) ?? "").toLowerCase() === "wayland"; const isNvidiaPresent = (existsSync: (path: string) => boolean): boolean => existsSync("/dev/nvidiactl") || existsSync("/dev/nvidia0"); export function shouldDisableGpuOnNvidiaWayland(input: { readonly env: NodeJS.ProcessEnv; + readonly ozonePlatform: string | null; readonly homeDirectory: string; readonly joinPath: JoinPath; readonly existsSync: (path: string) => boolean; readonly readFileString: (path: string) => string; readonly hasSwitch: (name: string) => boolean; }): boolean { - if (!isWaylandSession(input.env)) return false; + if (!isWaylandPlatform(input.env, input.ozonePlatform)) return false; if (input.hasSwitch("disable-gpu") || input.hasSwitch("enable-gpu")) return false; const settingsPath = resolveEarlyDesktopSettingsPath({ env: input.env, diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.ts index 1fc0934e65c78..538e7eada89c1 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.ts @@ -124,6 +124,7 @@ export const make = Effect.gen(function* () { if ( DesktopEarlyElectronStartup.shouldDisableGpuOnNvidiaWayland({ env: process.env, + ozonePlatform: readCommandLineSwitchValue(Electron.app.commandLine, "ozone-platform"), homeDirectory, joinPath: NodePath.posix.join, existsSync: (path) => NodeFS.existsSync(path), From 817fad6626ed95d50a168852a87f619f9a2c1edb Mon Sep 17 00:00:00 2001 From: SaahiilM <47355754+SaahiilM@users.noreply.github.com> Date: Wed, 4 Nov 2026 12:36:48 -0500 Subject: [PATCH 4/9] fix(desktop): detect Wayland via WAYLAND_DISPLAY and live socket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Electron can auto-select Wayland when a Wayland display is reachable even if XDG_SESSION_TYPE is missing or x11. Add WAYLAND_DISPLAY and live wayland-N socket (XDG_RUNTIME_DIR cross-checked against /proc/net/unix) as fallback signals after the explicit ozone switch and session type. Explicit ozone-platform still wins. Tests cover WAYLAND_DISPLAY and live-socket detection. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- .../app/DesktopEarlyElectronStartup.test.ts | 26 ++++++++ .../src/app/DesktopEarlyElectronStartup.ts | 62 ++++++++++++++++++- .../src/app/DesktopPreReadyPlatform.test.ts | 4 ++ .../src/app/DesktopPreReadyPlatform.ts | 10 +++ 4 files changed, 99 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts index 9cbd1a4b90fb5..08e57778cf300 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts @@ -236,6 +236,32 @@ describe("Linux device scale persistence failures", () => { ); }); + it("detects Wayland via WAYLAND_DISPLAY when session variables are absent", () => { + assert.isTrue( + shouldDisableGpuOnNvidiaWayland({ ...base, env: { WAYLAND_DISPLAY: "wayland-0" } }), + ); + }); + + it("detects Wayland via live runtime socket when session variables are absent", () => { + assert.isTrue( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: {}, + hasLiveWaylandSocket: () => true, + }), + ); + }); + + it("stays false when no Wayland signal is present at all", () => { + assert.isFalse( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: {}, + hasLiveWaylandSocket: () => false, + }), + ); + }); + it("is false without NVIDIA devices", () => { assert.isFalse( shouldDisableGpuOnNvidiaWayland({ diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts index eaa7f2467cc89..caefaee485672 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts @@ -81,12 +81,64 @@ export function resolveEarlyLinuxPasswordStorePreference( } } -const isWaylandPlatform = (env: NodeJS.ProcessEnv, ozonePlatform: string | null): boolean => - (ozonePlatform ?? trimNonEmpty(env.XDG_SESSION_TYPE) ?? "").toLowerCase() === "wayland"; +const isWaylandPlatform = ( + env: NodeJS.ProcessEnv, + ozonePlatform: string | null, + hasLiveWaylandSocket: () => boolean, +): boolean => { + const explicit = (ozonePlatform ?? "").toLowerCase(); + if (explicit === "wayland") return true; + if (explicit) return false; + if ((trimNonEmpty(env.XDG_SESSION_TYPE) ?? "").toLowerCase() === "wayland") return true; + if (trimNonEmpty(env.WAYLAND_DISPLAY) !== null) return true; + return hasLiveWaylandSocket(); +}; + +const WAYLAND_SOCKET_NAME = /^wayland-\d+$/; +const WAYLAND_SOCKET_LINE = /\s(\/.*)$/; + +const hasLiveWaylandDisplay = (input: { + readonly env: NodeJS.ProcessEnv; + readonly readdirSync: (path: string) => ReadonlyArray<{ name: string; isSocket: () => boolean }>; + readonly readUnixSockets: () => string; + readonly joinPath: (first: string, second: string) => string; +}): boolean => { + const runtimeDirectory = trimNonEmpty(input.env.XDG_RUNTIME_DIR); + if (runtimeDirectory === null) return false; + let liveSockets: ReadonlySet; + let socketNames: ReadonlyArray; + try { + liveSockets = new Set( + input + .readUnixSockets() + .split("\n") + .flatMap((line) => line.match(WAYLAND_SOCKET_LINE)?.[1] ?? []), + ); + socketNames = input + .readdirSync(runtimeDirectory) + .filter((entry) => WAYLAND_SOCKET_NAME.test(entry.name) && entry.isSocket()) + .map((entry) => entry.name); + } catch { + return false; + } + return socketNames.some((name) => liveSockets.has(input.joinPath(runtimeDirectory, name))); +}; const isNvidiaPresent = (existsSync: (path: string) => boolean): boolean => existsSync("/dev/nvidiactl") || existsSync("/dev/nvidia0"); +export const makeHasLiveWaylandSocket = + (input: { + readonly env: NodeJS.ProcessEnv; + readonly readdirSync: ( + path: string, + ) => ReadonlyArray<{ name: string; isSocket: () => boolean }>; + readonly readUnixSockets: () => string; + readonly joinPath: (first: string, second: string) => string; + }): (() => boolean) => + () => + hasLiveWaylandDisplay(input); + export function shouldDisableGpuOnNvidiaWayland(input: { readonly env: NodeJS.ProcessEnv; readonly ozonePlatform: string | null; @@ -95,8 +147,12 @@ export function shouldDisableGpuOnNvidiaWayland(input: { readonly existsSync: (path: string) => boolean; readonly readFileString: (path: string) => string; readonly hasSwitch: (name: string) => boolean; + readonly hasLiveWaylandSocket?: () => boolean; }): boolean { - if (!isWaylandPlatform(input.env, input.ozonePlatform)) return false; + if ( + !isWaylandPlatform(input.env, input.ozonePlatform, input.hasLiveWaylandSocket ?? (() => false)) + ) + return false; if (input.hasSwitch("disable-gpu") || input.hasSwitch("enable-gpu")) return false; const settingsPath = resolveEarlyDesktopSettingsPath({ env: input.env, diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts index 2a94f29231116..d99799bb49378 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts @@ -17,6 +17,7 @@ const { execFileSyncMock, readFileSyncMock, existsSyncMock, + readdirSyncMock, } = vi.hoisted(() => ({ appendSwitchMock: vi.fn(), getSwitchValueMock: vi.fn(), @@ -29,6 +30,7 @@ const { execFileSyncMock: vi.fn(), readFileSyncMock: vi.fn(), existsSyncMock: vi.fn(), + readdirSyncMock: vi.fn(), })); vi.mock("electron", () => ({ @@ -54,6 +56,7 @@ vi.mock("node:fs", () => ({ writeFileSync: writeFileSyncMock, copyFileSync: copyFileSyncMock, existsSync: existsSyncMock, + readdirSync: readdirSyncMock, })); vi.mock("node:child_process", () => ({ @@ -75,6 +78,7 @@ describe("DesktopPreReadyPlatform", () => { execFileSyncMock.mockReset(); readFileSyncMock.mockReset().mockReturnValue("{}"); existsSyncMock.mockReset().mockReturnValue(false); + readdirSyncMock.mockReset().mockReturnValue([]); }); it.effect("persists Linux scaling synchronously across relaunches and settings rewrites", () => { diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.ts index 538e7eada89c1..cc8ae297fd610 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.ts @@ -130,6 +130,16 @@ export const make = Effect.gen(function* () { existsSync: (path) => NodeFS.existsSync(path), readFileString: (path) => NodeFS.readFileSync(path, "utf8"), hasSwitch: (name) => Electron.app.commandLine.hasSwitch(name), + hasLiveWaylandSocket: DesktopEarlyElectronStartup.makeHasLiveWaylandSocket({ + env: process.env, + readdirSync: (directory) => + NodeFS.readdirSync(directory, { withFileTypes: true }).map((entry) => ({ + name: entry.name, + isSocket: () => entry.isSocket(), + })), + readUnixSockets: () => NodeFS.readFileSync("/proc/net/unix", "utf8"), + joinPath: NodePath.posix.join, + }), }) ) { Electron.app.commandLine.appendSwitch("disable-gpu"); From 8f79f401109656977bf4196007ae32e219be9e90 Mon Sep 17 00:00:00 2001 From: SaahiilM <47355754+SaahiilM@users.noreply.github.com> Date: Wed, 4 Nov 2026 12:36:49 -0500 Subject: [PATCH 5/9] test(desktop): cover pre-ready disable-gpu wiring end to end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Helper unit tests alone would not catch a removed or miswired caller. Build DesktopPreReadyPlatform.layer under NVIDIA Wayland mocks and assert appendSwitch receives disable-gpu, plus the disableGpuAcceleration:false opt-out leaves it unappended. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- .../src/app/DesktopPreReadyPlatform.test.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts index d99799bb49378..dfc286fbbc3f5 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts @@ -81,6 +81,38 @@ describe("DesktopPreReadyPlatform", () => { readdirSyncMock.mockReset().mockReturnValue([]); }); + it.effect.each([ + { settings: "{}", label: "disables GPU on NVIDIA Wayland", expected: true }, + { + settings: JSON.stringify({ disableGpuAcceleration: false }), + label: "honors disableGpuAcceleration:false opt-out", + expected: false, + }, + ])("pre-ready GPU switch: $label", ({ settings, expected }) => { + vi.stubEnv("T3CODE_HOME", "/isolated"); + vi.stubEnv("VITE_DEV_SERVER_URL", ""); + vi.stubEnv("XDG_SESSION_TYPE", "wayland"); + vi.stubEnv("XDG_DATA_HOME", "/xdg"); + vi.stubEnv("APPIMAGE", "/Applications/current.AppImage"); + existsSyncMock.mockReturnValue(true); + readFileSyncMock.mockReturnValue(settings); + getSwitchValueMock.mockReturnValue(""); + hasSwitchMock.mockReturnValue(false); + readdirSyncMock.mockReturnValue([]); + + return Effect.scoped( + Effect.gen(function* () { + yield* Layer.build( + DesktopPreReadyPlatform.layer.pipe( + Layer.provide(Layer.succeed(HostProcess.Platform, "linux")), + ), + ); + const appended = appendSwitchMock.mock.calls.some(([name]) => name === "disable-gpu"); + assert.equal(appended, expected); + }), + ).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs()))); + }); + it.effect("persists Linux scaling synchronously across relaunches and settings rewrites", () => { vi.stubEnv("T3CODE_HOME", "/isolated"); vi.stubEnv("VITE_DEV_SERVER_URL", ""); From 74d0087c249d56cc54bc8a576e9539d8a98d25d8 Mon Sep 17 00:00:00 2001 From: SaahiilM <47355754+SaahiilM@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:26:14 -0500 Subject: [PATCH 6/9] fix(desktop): honor the ozone platform hint in the NVIDIA Wayland guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The guard only read --ozone-platform, so an X11 hint on a Wayland login still appended --disable-gpu, and a Wayland hint without session variables was missed. Read --ozone-platform-hint too, keep the explicit platform switch ahead of it, and fall back to the existing session/socket detection for auto and default. Tests cover the X11 hint on a Wayland login, the Wayland hint with no session environment, platform precedence, and auto/default fallback, plus the pre-ready wiring. 🤖 Generated with DeepSeek V4.1 Flash Free via OpenCode --- .../app/DesktopEarlyElectronStartup.test.ts | 53 +++++++++++++++++++ .../src/app/DesktopEarlyElectronStartup.ts | 28 +++++++--- .../src/app/DesktopPreReadyPlatform.test.ts | 27 ++++++++++ .../src/app/DesktopPreReadyPlatform.ts | 4 ++ 4 files changed, 106 insertions(+), 6 deletions(-) diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts index 08e57778cf300..1b80a30204d27 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts @@ -201,6 +201,7 @@ describe("Linux device scale persistence failures", () => { describe("shouldDisableGpuOnNvidiaWayland", () => { const base = { ozonePlatform: null, + ozonePlatformHint: null, homeDirectory: "/home/user", joinPath: NodePath.posix.join, existsSync: (path: string) => path === "/dev/nvidiactl", @@ -236,6 +237,58 @@ describe("Linux device scale persistence failures", () => { ); }); + it("respects --ozone-platform-hint=x11 on a Wayland login", () => { + assert.isFalse( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "wayland", WAYLAND_DISPLAY: "wayland-0" }, + ozonePlatformHint: "x11", + hasLiveWaylandSocket: () => true, + }), + ); + }); + + it("honors --ozone-platform-hint=wayland when the session variables are absent", () => { + assert.isTrue( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: {}, + ozonePlatformHint: "wayland", + }), + ); + }); + + it("prefers the explicit --ozone-platform over --ozone-platform-hint", () => { + assert.isFalse( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "wayland" }, + ozonePlatform: "x11", + ozonePlatformHint: "wayland", + }), + ); + }); + + it("falls back to the session environment for hint=auto or hint=default", () => { + for (const ozonePlatformHint of ["auto", "default"]) { + assert.isTrue( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "wayland" }, + ozonePlatformHint, + }), + ); + assert.isFalse( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: {}, + ozonePlatformHint, + hasLiveWaylandSocket: () => false, + }), + ); + } + }); + it("detects Wayland via WAYLAND_DISPLAY when session variables are absent", () => { assert.isTrue( shouldDisableGpuOnNvidiaWayland({ ...base, env: { WAYLAND_DISPLAY: "wayland-0" } }), diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts index caefaee485672..e10ca1ee1701c 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts @@ -81,16 +81,26 @@ export function resolveEarlyLinuxPasswordStorePreference( } } +const normalizeSwitchValue = (value: string | null | undefined): string | null => { + const normalized = value?.trim().toLowerCase(); + return normalized && normalized.length > 0 ? normalized : null; +}; + const isWaylandPlatform = ( env: NodeJS.ProcessEnv, ozonePlatform: string | null, + ozonePlatformHint: string | null, hasLiveWaylandSocket: () => boolean, ): boolean => { - const explicit = (ozonePlatform ?? "").toLowerCase(); - if (explicit === "wayland") return true; - if (explicit) return false; - if ((trimNonEmpty(env.XDG_SESSION_TYPE) ?? "").toLowerCase() === "wayland") return true; - if (trimNonEmpty(env.WAYLAND_DISPLAY) !== null) return true; + // --ozone-platform selects the backend directly; --ozone-platform-hint only + // breaks the default/auto tie, so an explicit platform always wins. + const explicit = normalizeSwitchValue(ozonePlatform); + if (explicit !== null) return explicit === "wayland"; + const hint = normalizeSwitchValue(ozonePlatformHint); + if (hint === "wayland") return true; + if (hint === "x11") return false; + if (normalizeSwitchValue(env.XDG_SESSION_TYPE) === "wayland") return true; + if (normalizeSwitchValue(env.WAYLAND_DISPLAY) !== null) return true; return hasLiveWaylandSocket(); }; @@ -142,6 +152,7 @@ export const makeHasLiveWaylandSocket = export function shouldDisableGpuOnNvidiaWayland(input: { readonly env: NodeJS.ProcessEnv; readonly ozonePlatform: string | null; + readonly ozonePlatformHint: string | null; readonly homeDirectory: string; readonly joinPath: JoinPath; readonly existsSync: (path: string) => boolean; @@ -150,7 +161,12 @@ export function shouldDisableGpuOnNvidiaWayland(input: { readonly hasLiveWaylandSocket?: () => boolean; }): boolean { if ( - !isWaylandPlatform(input.env, input.ozonePlatform, input.hasLiveWaylandSocket ?? (() => false)) + !isWaylandPlatform( + input.env, + input.ozonePlatform, + input.ozonePlatformHint, + input.hasLiveWaylandSocket ?? (() => false), + ) ) return false; if (input.hasSwitch("disable-gpu") || input.hasSwitch("enable-gpu")) return false; diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts index dfc286fbbc3f5..f6303b7795771 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts @@ -113,6 +113,33 @@ describe("DesktopPreReadyPlatform", () => { ).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs()))); }); + it.effect("pre-ready GPU switch: honors an X11 ozone platform hint on a Wayland login", () => { + vi.stubEnv("T3CODE_HOME", "/isolated"); + vi.stubEnv("VITE_DEV_SERVER_URL", ""); + vi.stubEnv("XDG_SESSION_TYPE", "wayland"); + vi.stubEnv("XDG_DATA_HOME", "/xdg"); + vi.stubEnv("APPIMAGE", "/Applications/current.AppImage"); + existsSyncMock.mockReturnValue(true); + readFileSyncMock.mockReturnValue("{}"); + getSwitchValueMock.mockImplementation((name: string) => + name === "ozone-platform-hint" ? "x11" : "", + ); + hasSwitchMock.mockImplementation((name: string) => name === "ozone-platform-hint"); + readdirSyncMock.mockReturnValue([]); + + return Effect.scoped( + Effect.gen(function* () { + yield* Layer.build( + DesktopPreReadyPlatform.layer.pipe( + Layer.provide(Layer.succeed(HostProcess.Platform, "linux")), + ), + ); + const appended = appendSwitchMock.mock.calls.some(([name]) => name === "disable-gpu"); + assert.isFalse(appended); + }), + ).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs()))); + }); + it.effect("persists Linux scaling synchronously across relaunches and settings rewrites", () => { vi.stubEnv("T3CODE_HOME", "/isolated"); vi.stubEnv("VITE_DEV_SERVER_URL", ""); diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.ts index cc8ae297fd610..4ecdb7f2af42b 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.ts @@ -125,6 +125,10 @@ export const make = Effect.gen(function* () { DesktopEarlyElectronStartup.shouldDisableGpuOnNvidiaWayland({ env: process.env, ozonePlatform: readCommandLineSwitchValue(Electron.app.commandLine, "ozone-platform"), + ozonePlatformHint: readCommandLineSwitchValue( + Electron.app.commandLine, + "ozone-platform-hint", + ), homeDirectory, joinPath: NodePath.posix.join, existsSync: (path) => NodeFS.existsSync(path), From 14ce315697040a5da4d62ec580084174994ebc9f Mon Sep 17 00:00:00 2001 From: SaahiilM <47355754+SaahiilM@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:44:09 -0500 Subject: [PATCH 7/9] fix(desktop): treat --ozone-platform=auto as auto-detected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Electron's default backend selection is auto, so an explicit auto value must fall through to the session and display checks instead of returning X11. Add decision tests for auto with a Wayland session, with WAYLAND_DISPLAY only, and with an X11 session. 🤖 Generated with DeepSeek V4.1 Flash Free via OpenCode --- .../app/DesktopEarlyElectronStartup.test.ts | 25 +++++++++++++++++++ .../src/app/DesktopEarlyElectronStartup.ts | 4 +-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts index 1b80a30204d27..00bc88799cf4f 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts @@ -237,6 +237,31 @@ describe("Linux device scale persistence failures", () => { ); }); + it("treats --ozone-platform=auto as an unspecified platform", () => { + assert.isTrue( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "wayland" }, + ozonePlatform: "auto", + }), + ); + assert.isTrue( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { WAYLAND_DISPLAY: "wayland-0" }, + ozonePlatform: "auto", + }), + ); + assert.isFalse( + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "x11" }, + ozonePlatform: "auto", + hasLiveWaylandSocket: () => false, + }), + ); + }); + it("respects --ozone-platform-hint=x11 on a Wayland login", () => { assert.isFalse( shouldDisableGpuOnNvidiaWayland({ diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts index e10ca1ee1701c..dd2b5e4611567 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts @@ -93,9 +93,9 @@ const isWaylandPlatform = ( hasLiveWaylandSocket: () => boolean, ): boolean => { // --ozone-platform selects the backend directly; --ozone-platform-hint only - // breaks the default/auto tie, so an explicit platform always wins. + // breaks the auto/default tie, so an explicit platform always wins. const explicit = normalizeSwitchValue(ozonePlatform); - if (explicit !== null) return explicit === "wayland"; + if (explicit !== null && explicit !== "auto") return explicit === "wayland"; const hint = normalizeSwitchValue(ozonePlatformHint); if (hint === "wayland") return true; if (hint === "x11") return false; From 6c2120e2615ba6a22c98d0e687e770e51314c158 Mon Sep 17 00:00:00 2001 From: SaahiilM <47355754+SaahiilM@users.noreply.github.com> Date: Fri, 6 Nov 2026 09:51:20 -0500 Subject: [PATCH 8/9] fix(desktop): use the resolved Ozone backend for the GPU fallback --- .../app/DesktopEarlyElectronStartup.test.ts | 113 +++--------------- .../src/app/DesktopEarlyElectronStartup.ts | 78 +----------- .../src/app/DesktopPreReadyPlatform.test.ts | 72 ++++++----- .../src/app/DesktopPreReadyPlatform.ts | 14 --- 4 files changed, 57 insertions(+), 220 deletions(-) diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts index 00bc88799cf4f..8b05a31411c54 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts @@ -200,8 +200,7 @@ describe("Linux device scale persistence failures", () => { describe("shouldDisableGpuOnNvidiaWayland", () => { const base = { - ozonePlatform: null, - ozonePlatformHint: null, + ozonePlatform: "wayland", homeDirectory: "/home/user", joinPath: NodePath.posix.join, existsSync: (path: string) => path === "/dev/nvidiactl", @@ -217,7 +216,11 @@ describe("Linux device scale persistence failures", () => { it("is false on X11", () => { assert.isFalse( - shouldDisableGpuOnNvidiaWayland({ ...base, env: { XDG_SESSION_TYPE: "x11" } }), + shouldDisableGpuOnNvidiaWayland({ + ...base, + env: { XDG_SESSION_TYPE: "x11" }, + ozonePlatform: "x11", + }), ); }); @@ -237,107 +240,21 @@ describe("Linux device scale persistence failures", () => { ); }); - it("treats --ozone-platform=auto as an unspecified platform", () => { - assert.isTrue( - shouldDisableGpuOnNvidiaWayland({ - ...base, - env: { XDG_SESSION_TYPE: "wayland" }, - ozonePlatform: "auto", - }), - ); - assert.isTrue( - shouldDisableGpuOnNvidiaWayland({ - ...base, - env: { WAYLAND_DISPLAY: "wayland-0" }, - ozonePlatform: "auto", - }), - ); - assert.isFalse( - shouldDisableGpuOnNvidiaWayland({ - ...base, - env: { XDG_SESSION_TYPE: "x11" }, - ozonePlatform: "auto", - hasLiveWaylandSocket: () => false, - }), - ); - }); - - it("respects --ozone-platform-hint=x11 on a Wayland login", () => { - assert.isFalse( - shouldDisableGpuOnNvidiaWayland({ - ...base, - env: { XDG_SESSION_TYPE: "wayland", WAYLAND_DISPLAY: "wayland-0" }, - ozonePlatformHint: "x11", - hasLiveWaylandSocket: () => true, - }), - ); - }); - - it("honors --ozone-platform-hint=wayland when the session variables are absent", () => { - assert.isTrue( - shouldDisableGpuOnNvidiaWayland({ - ...base, - env: {}, - ozonePlatformHint: "wayland", - }), - ); - }); - - it("prefers the explicit --ozone-platform over --ozone-platform-hint", () => { - assert.isFalse( - shouldDisableGpuOnNvidiaWayland({ - ...base, - env: { XDG_SESSION_TYPE: "wayland" }, - ozonePlatform: "x11", - ozonePlatformHint: "wayland", - }), - ); - }); - - it("falls back to the session environment for hint=auto or hint=default", () => { - for (const ozonePlatformHint of ["auto", "default"]) { - assert.isTrue( - shouldDisableGpuOnNvidiaWayland({ - ...base, - env: { XDG_SESSION_TYPE: "wayland" }, - ozonePlatformHint, - }), - ); + it.each([null, "auto", "headless"])( + "does not infer Wayland from the environment for unresolved platform %s", + (ozonePlatform) => { assert.isFalse( shouldDisableGpuOnNvidiaWayland({ ...base, - env: {}, - ozonePlatformHint, - hasLiveWaylandSocket: () => false, + env: { XDG_SESSION_TYPE: "wayland", WAYLAND_DISPLAY: "wayland-0" }, + ozonePlatform, }), ); - } - }); - - it("detects Wayland via WAYLAND_DISPLAY when session variables are absent", () => { - assert.isTrue( - shouldDisableGpuOnNvidiaWayland({ ...base, env: { WAYLAND_DISPLAY: "wayland-0" } }), - ); - }); - - it("detects Wayland via live runtime socket when session variables are absent", () => { - assert.isTrue( - shouldDisableGpuOnNvidiaWayland({ - ...base, - env: {}, - hasLiveWaylandSocket: () => true, - }), - ); - }); + }, + ); - it("stays false when no Wayland signal is present at all", () => { - assert.isFalse( - shouldDisableGpuOnNvidiaWayland({ - ...base, - env: {}, - hasLiveWaylandSocket: () => false, - }), - ); + it("uses Electron's resolved Wayland backend without session or display variables", () => { + assert.isTrue(shouldDisableGpuOnNvidiaWayland({ ...base, env: {} })); }); it("is false without NVIDIA devices", () => { diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts index dd2b5e4611567..7520088890c04 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts @@ -81,94 +81,20 @@ export function resolveEarlyLinuxPasswordStorePreference( } } -const normalizeSwitchValue = (value: string | null | undefined): string | null => { - const normalized = value?.trim().toLowerCase(); - return normalized && normalized.length > 0 ? normalized : null; -}; - -const isWaylandPlatform = ( - env: NodeJS.ProcessEnv, - ozonePlatform: string | null, - ozonePlatformHint: string | null, - hasLiveWaylandSocket: () => boolean, -): boolean => { - // --ozone-platform selects the backend directly; --ozone-platform-hint only - // breaks the auto/default tie, so an explicit platform always wins. - const explicit = normalizeSwitchValue(ozonePlatform); - if (explicit !== null && explicit !== "auto") return explicit === "wayland"; - const hint = normalizeSwitchValue(ozonePlatformHint); - if (hint === "wayland") return true; - if (hint === "x11") return false; - if (normalizeSwitchValue(env.XDG_SESSION_TYPE) === "wayland") return true; - if (normalizeSwitchValue(env.WAYLAND_DISPLAY) !== null) return true; - return hasLiveWaylandSocket(); -}; - -const WAYLAND_SOCKET_NAME = /^wayland-\d+$/; -const WAYLAND_SOCKET_LINE = /\s(\/.*)$/; - -const hasLiveWaylandDisplay = (input: { - readonly env: NodeJS.ProcessEnv; - readonly readdirSync: (path: string) => ReadonlyArray<{ name: string; isSocket: () => boolean }>; - readonly readUnixSockets: () => string; - readonly joinPath: (first: string, second: string) => string; -}): boolean => { - const runtimeDirectory = trimNonEmpty(input.env.XDG_RUNTIME_DIR); - if (runtimeDirectory === null) return false; - let liveSockets: ReadonlySet; - let socketNames: ReadonlyArray; - try { - liveSockets = new Set( - input - .readUnixSockets() - .split("\n") - .flatMap((line) => line.match(WAYLAND_SOCKET_LINE)?.[1] ?? []), - ); - socketNames = input - .readdirSync(runtimeDirectory) - .filter((entry) => WAYLAND_SOCKET_NAME.test(entry.name) && entry.isSocket()) - .map((entry) => entry.name); - } catch { - return false; - } - return socketNames.some((name) => liveSockets.has(input.joinPath(runtimeDirectory, name))); -}; - const isNvidiaPresent = (existsSync: (path: string) => boolean): boolean => existsSync("/dev/nvidiactl") || existsSync("/dev/nvidia0"); -export const makeHasLiveWaylandSocket = - (input: { - readonly env: NodeJS.ProcessEnv; - readonly readdirSync: ( - path: string, - ) => ReadonlyArray<{ name: string; isSocket: () => boolean }>; - readonly readUnixSockets: () => string; - readonly joinPath: (first: string, second: string) => string; - }): (() => boolean) => - () => - hasLiveWaylandDisplay(input); - export function shouldDisableGpuOnNvidiaWayland(input: { readonly env: NodeJS.ProcessEnv; readonly ozonePlatform: string | null; - readonly ozonePlatformHint: string | null; readonly homeDirectory: string; readonly joinPath: JoinPath; readonly existsSync: (path: string) => boolean; readonly readFileString: (path: string) => string; readonly hasSwitch: (name: string) => boolean; - readonly hasLiveWaylandSocket?: () => boolean; }): boolean { - if ( - !isWaylandPlatform( - input.env, - input.ozonePlatform, - input.ozonePlatformHint, - input.hasLiveWaylandSocket ?? (() => false), - ) - ) - return false; + // Electron resolves --ozone-platform before loading the main module, including auto selection. + if (input.ozonePlatform !== "wayland") return false; if (input.hasSwitch("disable-gpu") || input.hasSwitch("enable-gpu")) return false; const settingsPath = resolveEarlyDesktopSettingsPath({ env: input.env, diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts index 82ab984da20ae..25bd90de31c30 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.test.ts @@ -17,7 +17,6 @@ const { execFileSyncMock, readFileSyncMock, existsSyncMock, - readdirSyncMock, } = vi.hoisted(() => ({ appendSwitchMock: vi.fn(), getSwitchValueMock: vi.fn(), @@ -30,7 +29,6 @@ const { execFileSyncMock: vi.fn(), readFileSyncMock: vi.fn(), existsSyncMock: vi.fn(), - readdirSyncMock: vi.fn(), })); vi.mock("electron", () => ({ @@ -56,7 +54,6 @@ vi.mock("node:fs", () => ({ writeFileSync: writeFileSyncMock, copyFileSync: copyFileSyncMock, existsSync: existsSyncMock, - readdirSync: readdirSyncMock, })); vi.mock("node:child_process", () => ({ @@ -79,7 +76,6 @@ describe("DesktopPreReadyPlatform", () => { execFileSyncMock.mockReset(); readFileSyncMock.mockReset().mockReturnValue("{}"); existsSyncMock.mockReset().mockReturnValue(false); - readdirSyncMock.mockReset().mockReturnValue([]); }); it.effect.each([ @@ -97,9 +93,10 @@ describe("DesktopPreReadyPlatform", () => { vi.stubEnv("APPIMAGE", "/Applications/current.AppImage"); existsSyncMock.mockReturnValue(true); readFileSyncMock.mockReturnValue(settings); - getSwitchValueMock.mockReturnValue(""); - hasSwitchMock.mockReturnValue(false); - readdirSyncMock.mockReturnValue([]); + getSwitchValueMock.mockImplementation((name: string) => + name === "ozone-platform" ? "wayland" : "", + ); + hasSwitchMock.mockImplementation((name: string) => name === "ozone-platform"); return Effect.scoped( Effect.gen(function* () { @@ -114,32 +111,43 @@ describe("DesktopPreReadyPlatform", () => { ).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs()))); }); - it.effect("pre-ready GPU switch: honors an X11 ozone platform hint on a Wayland login", () => { - vi.stubEnv("T3CODE_HOME", "/isolated"); - vi.stubEnv("VITE_DEV_SERVER_URL", ""); - vi.stubEnv("XDG_SESSION_TYPE", "wayland"); - vi.stubEnv("XDG_DATA_HOME", "/xdg"); - vi.stubEnv("APPIMAGE", "/Applications/current.AppImage"); - existsSyncMock.mockReturnValue(true); - readFileSyncMock.mockReturnValue("{}"); - getSwitchValueMock.mockImplementation((name: string) => - name === "ozone-platform-hint" ? "x11" : "", - ); - hasSwitchMock.mockImplementation((name: string) => name === "ozone-platform-hint"); - readdirSyncMock.mockReturnValue([]); + it.effect.each([ + { session: "wayland", platform: "wayland", hint: "x11", expected: true }, + { session: "x11", platform: "x11", hint: "wayland", expected: false }, + ])( + "pre-ready GPU switch: ignores stale hint=$hint on $session", + ({ session, platform, hint, expected }) => { + vi.stubEnv("T3CODE_HOME", "/isolated"); + vi.stubEnv("VITE_DEV_SERVER_URL", ""); + vi.stubEnv("XDG_SESSION_TYPE", session); + vi.stubEnv("XDG_DATA_HOME", "/xdg"); + vi.stubEnv("APPIMAGE", "/Applications/current.AppImage"); + existsSyncMock.mockReturnValue(true); + readFileSyncMock.mockReturnValue("{}"); + getSwitchValueMock.mockImplementation((name: string) => + name === "ozone-platform" ? platform : name === "ozone-platform-hint" ? hint : "", + ); + hasSwitchMock.mockImplementation( + (name: string) => name === "ozone-platform" || name === "ozone-platform-hint", + ); - return Effect.scoped( - Effect.gen(function* () { - yield* Layer.build( - DesktopPreReadyPlatform.layer.pipe( - Layer.provide(Layer.succeed(HostProcess.Platform, "linux")), - ), - ); - const appended = appendSwitchMock.mock.calls.some(([name]) => name === "disable-gpu"); - assert.isFalse(appended); - }), - ).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs()))); - }); + return Effect.scoped( + Effect.gen(function* () { + yield* Layer.build( + DesktopPreReadyPlatform.layer.pipe( + Layer.provide(Layer.succeed(HostProcess.Platform, "linux")), + ), + ); + const appended = appendSwitchMock.mock.calls.some(([name]) => name === "disable-gpu"); + assert.equal(appended, expected); + assert.isFalse( + getSwitchValueMock.mock.calls.some(([name]) => name === "ozone-platform-hint"), + ); + assert.isFalse(hasSwitchMock.mock.calls.some(([name]) => name === "ozone-platform-hint")); + }), + ).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs()))); + }, + ); it.effect("persists Linux scaling synchronously across relaunches and settings rewrites", () => { vi.stubEnv("T3CODE_HOME", "/isolated"); diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.ts index 45a815efdd024..d8bbb395d6f25 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.ts @@ -139,25 +139,11 @@ export const make = Effect.gen(function* () { DesktopEarlyElectronStartup.shouldDisableGpuOnNvidiaWayland({ env: process.env, ozonePlatform: readCommandLineSwitchValue(Electron.app.commandLine, "ozone-platform"), - ozonePlatformHint: readCommandLineSwitchValue( - Electron.app.commandLine, - "ozone-platform-hint", - ), homeDirectory, joinPath: NodePath.posix.join, existsSync: (path) => NodeFS.existsSync(path), readFileString: (path) => NodeFS.readFileSync(path, "utf8"), hasSwitch: (name) => Electron.app.commandLine.hasSwitch(name), - hasLiveWaylandSocket: DesktopEarlyElectronStartup.makeHasLiveWaylandSocket({ - env: process.env, - readdirSync: (directory) => - NodeFS.readdirSync(directory, { withFileTypes: true }).map((entry) => ({ - name: entry.name, - isSocket: () => entry.isSocket(), - })), - readUnixSockets: () => NodeFS.readFileSync("/proc/net/unix", "utf8"), - joinPath: NodePath.posix.join, - }), }) ) { Electron.app.commandLine.appendSwitch("disable-gpu"); From 855402e1bc6f1b26c4e764613b3f9a0875f40c84 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Sun, 15 Nov 2026 02:52:17 +0000 Subject: [PATCH 9/9] fix(desktop): preserve password store with malformed gpu preference --- .../app/DesktopEarlyElectronStartup.test.ts | 27 ++++++++++--------- .../src/app/DesktopEarlyElectronStartup.ts | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts index 8b05a31411c54..93695bbfd1586 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts @@ -12,19 +12,22 @@ import { 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" }); - }, - }); + it.each([undefined, false, true, null, "false"])( + "reads the persisted linux password-store preference with GPU setting %j", + (disableGpuAcceleration) => { + 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", disableGpuAcceleration }); + }, + }); - assert.equal(preference, "kwallet6"); - }); + assert.equal(preference, "kwallet6"); + }, + ); it("accepts JSONC in the early desktop settings file", () => { const preference = resolveEarlyLinuxPasswordStorePreference({ diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts index 7520088890c04..86ba3a006ff8f 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts @@ -40,7 +40,7 @@ const trimNonEmpty = (value: string | undefined): string | null => { const EarlyDesktopSettingsJson = fromLenientJson( Schema.Struct({ - disableGpuAcceleration: Schema.optionalKey(Schema.Boolean), + disableGpuAcceleration: Schema.optionalKey(Schema.Unknown), linuxPasswordStore: Schema.optionalKey(Schema.Unknown), }), );