diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts index 6d40bd128b77..d0c912dfc41d 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, + resolveWindowsDisableFeaturesSwitch, } from "./DesktopEarlyElectronStartup.ts"; describe("DesktopEarlyElectronStartup", () => { @@ -129,6 +130,35 @@ describe("DesktopEarlyElectronStartup", () => { ); }); }); + + describe("resolveWindowsDisableFeaturesSwitch", () => { + it.each([ + { disableFeatures: null, expected: "HideCursorWhileTyping" }, + { disableFeatures: "Vulkan", expected: "Vulkan,HideCursorWhileTyping" }, + // Chromium reads ":params" as part of a disabled name, so this entry leaves the feature on. + { + disableFeatures: "HideCursorWhileTyping:mode/strict", + expected: "HideCursorWhileTyping:mode/strict,HideCursorWhileTyping", + }, + ])("disables hide-pointer-while-typing alongside $disableFeatures", (input) => { + assert.equal( + resolveWindowsDisableFeaturesSwitch({ + enableFeatures: "Vulkan", + disableFeatures: input.disableFeatures, + }), + input.expected, + ); + }); + + it.each([ + { enableFeatures: null, disableFeatures: "Vulkan, HideCursorWhileTyping" }, + { enableFeatures: null, disableFeatures: "HideCursorWhileTyping { + assert.isNull(resolveWindowsDisableFeaturesSwitch(input)); + }); + }); }); describe("Linux device scale persistence failures", () => { diff --git a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts index 3c571bcf02b1..c5642ad53cc4 100644 --- a/apps/desktop/src/app/DesktopEarlyElectronStartup.ts +++ b/apps/desktop/src/app/DesktopEarlyElectronStartup.ts @@ -138,6 +138,29 @@ export function resolveLinuxDisableFeaturesSwitch(input: { : `${input.disableFeatures},${WAYLAND_COLOR_MANAGER_FEATURE}`; } +// Chromium 152 hides the pointer while typing on Windows, then shows it again on any +// WM_MOUSEMOVE, including the ones Windows sends while the mouse stays still. +const HIDE_CURSOR_WHILE_TYPING_FEATURE = "HideCursorWhileTyping"; + +// Chromium reads entries as Name + (list ?? "") + .split(",") + .some((entry) => entry.trim().split(nameEnd)[0] === HIDE_CURSOR_WHILE_TYPING_FEATURE); + +export function resolveWindowsDisableFeaturesSwitch(input: { + readonly enableFeatures: string | null; + readonly disableFeatures: string | null; +}): string | null { + // Chromium applies --disable-features first, so an opt-in must keep the feature off this list. + if (listsHideCursorWhileTyping(input.enableFeatures, /[<.:]/)) return null; + if (listsHideCursorWhileTyping(input.disableFeatures, / { ).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs()))); }); + it.effect("turns off Chromium's flickering hide-pointer-while-typing on Windows", () => { + hasSwitchMock.mockReturnValue(false); + + return Effect.gen(function* () { + yield* DesktopPreReadyPlatform.make; + assert.deepEqual(appendSwitchMock.mock.calls, [ + ["disable-features", "HideCursorWhileTyping"], + ]); + }).pipe(Effect.provideService(HostProcess.Platform, "win32")); + }); + it.effect( "acquires a synchronous pre-ready layer before an asynchronous Clerk-shaped layer", () => diff --git a/apps/desktop/src/app/DesktopPreReadyPlatform.ts b/apps/desktop/src/app/DesktopPreReadyPlatform.ts index 8ac4654636ab..5ed984496ae7 100644 --- a/apps/desktop/src/app/DesktopPreReadyPlatform.ts +++ b/apps/desktop/src/app/DesktopPreReadyPlatform.ts @@ -183,6 +183,17 @@ export const make = Effect.gen(function* () { } } + if (platform === "win32") { + // Chromium keeps only the last --disable-features value, so pass the merged list. + const disableFeatures = DesktopEarlyElectronStartup.resolveWindowsDisableFeaturesSwitch({ + enableFeatures: readCommandLineSwitchValue(Electron.app.commandLine, "enable-features"), + disableFeatures: readCommandLineSwitchValue(Electron.app.commandLine, "disable-features"), + }); + if (disableFeatures !== null) { + Electron.app.commandLine.appendSwitch("disable-features", disableFeatures); + } + } + return { linux, linuxPasswordStoreCommandLine }; }); }).pipe(Effect.withSpan("desktop.electron.configureBeforeReady"));