The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): Settings opens while the separate preview window has focus (#36747)
Co-authored-by: Grok 4.7 <noreply@x.ai> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 14, 2026 at 14:40 UTC
68bc28196d00cfa681caa18e401c9c9e17273da2
2 files changed
+43
-5
apps/desktop/src/window/DesktopWindow.test.ts
+40
-2
@@ -246,6 +246,7 @@ function layerTest(input: {
246
readonly previewZoomReapplies?: number[];
247
readonly onReveal?: (window: Electron.BrowserWindow) => void;
248
readonly focusedWindow?: Electron.BrowserWindow;
249
+ readonly fallbackWindow?: Electron.BrowserWindow;
250
readonly platform?: NodeJS.Platform;
251
readonly appearanceWindows?: ReadonlyArray<{
252
readonly window: Electron.BrowserWindow;
@@ -299,7 +300,9 @@ function layerTest(input: {
300
Effect.as(input.window),
301
),
302
main: Ref.get(input.mainWindow),
302
- currentMainOrFirst: Ref.get(input.mainWindow),
303
+ currentMainOrFirst: Ref.get(input.mainWindow).pipe(
304
+ Effect.map(Option.orElse(() => Option.fromNullishOr(input.fallbackWindow ?? null))),
305
+ ),
306
focusedMainOrFirst:
307
input.focusedWindow === undefined
308
? Ref.get(input.mainWindow)
@@ -844,7 +847,7 @@ describe("DesktopWindow", () => {
847
}),
848
);
849
847
- it.effect("reloads and inspects the main window even when a popup has focus", () =>
850
+ it.effect("routes menu commands to the main window even when a popup has focus", () =>
851
Effect.gen(function* () {
852
const fakeWindow = makeFakeBrowserWindow();
853
const popup = makeFakeBrowserWindow();
@@ -864,7 +867,10 @@ describe("DesktopWindow", () => {
867
yield* desktopWindow.runMainContentsCommand("reload");
868
yield* desktopWindow.runMainContentsCommand("forceReload");
869
yield* desktopWindow.runMainContentsCommand("toggleDevTools");
870
+ yield* desktopWindow.dispatchMenuAction("open-settings");
871
872
+ assert.deepEqual(fakeWindow.send.mock.calls, [["desktop:menu-action", "open-settings"]]);
873
+ assert.equal(popup.send.mock.calls.length, 0);
874
assert.equal(fakeWindow.reload.mock.calls.length, 1);
875
assert.equal(fakeWindow.reloadIgnoringCache.mock.calls.length, 1);
876
assert.equal(fakeWindow.toggleDevTools.mock.calls.length, 1);
@@ -875,6 +881,38 @@ describe("DesktopWindow", () => {
881
}),
882
);
883
884
+ it.effect("recreates main for Settings when only an unregistered popup survives", () =>
885
+ Effect.gen(function* () {
886
+ const main = makeFakeBrowserWindow();
887
+ const auxiliary = makeFakeBrowserWindow();
888
+ const createCount = yield* Ref.make(0);
889
+ const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());
890
+
891
+ yield* Effect.gen(function* () {
892
+ const windows = yield* DesktopWindow.DesktopWindow;
893
+ yield* windows.dispatchMenuAction("open-settings");
894
+ assert.deepEqual(main.send.mock.calls, [["desktop:menu-action", "open-settings"]]);
895
+ assert.equal(auxiliary.send.mock.calls.length, 0);
896
+ assert.equal(yield* Ref.get(createCount), 1);
897
+ assert.strictEqual(yield* windows.ensureMain, main.window);
898
+ assert.equal(yield* Ref.get(createCount), 1);
899
+ }).pipe(
900
+ Effect.provide(
901
+ layerTest({
902
+ window: main.window,
903
+ createCount,
904
+ mainWindow,
905
+ fallbackWindow: auxiliary.window,
906
+ desktopSettings: {
907
+ ...DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS,
908
+ localEnvironmentEnabled: false,
909
+ },
910
+ }),
911
+ ),
912
+ );
913
+ }),
914
+ );
915
+
916
it.effect("does not open main or splash windows once quitting has started", () =>
917
Effect.gen(function* () {
918
const fake = makeFakeBrowserWindow();
apps/desktop/src/window/DesktopWindow.ts
+3
-3
@@ -425,7 +425,6 @@ export const make = Effect.gen(function* () {
425
);
426
427
const currentMainWindow = electronWindow.currentMainOrFirst.pipe(Effect.flatMap(withoutSplash));
428
- const focusedMainWindow = electronWindow.focusedMainOrFirst.pipe(Effect.flatMap(withoutSplash));
428
429
const zoomWindow = Effect.fn("desktop.window.zoomWindow")(function* (
430
window: Electron.BrowserWindow,
@@ -1019,7 +1018,7 @@ export const make = Effect.gen(function* () {
1018
1019
const ensureMain = Effect.gen(function* () {
1020
if (yield* Ref.get(desktopState.quitting)) return Option.none<Electron.BrowserWindow>();
1022
- const existingWindow = yield* currentMainWindow;
1021
+ const existingWindow = yield* electronWindow.main;
1022
if (Option.isSome(existingWindow)) {
1023
return existingWindow;
1024
}
@@ -1106,7 +1105,8 @@ export const make = Effect.gen(function* () {
1105
{ reveal = true }: { readonly reveal?: boolean } = {},
1106
) {
1107
if (yield* Ref.get(desktopState.quitting)) return;
1109
- const existingWindow = yield* reveal ? focusedMainWindow : electronWindow.main;
1108
+ // Only the main renderer loads the app preload that listens on these channels.
1109
+ const existingWindow = yield* electronWindow.main;
1110
if (Option.isNone(existingWindow) && (!reveal || (yield* waitingForBackend))) return;
1111
const window = Option.isSome(existingWindow) ? existingWindow : yield* ensureMain;
1112
if (Option.isNone(window) || window.value.isDestroyed()) return;