Skip to content

Commit f72b306

Browse files
committed
fix(desktop): conceal completed quit holds
1 parent d3f3435 commit f72b306

4 files changed

Lines changed: 84 additions & 7 deletions

File tree

‎apps/desktop/src/window/DesktopWindow.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ function makeFakeBrowserWindow() {
105105
restore: vi.fn(),
106106
setBackgroundColor: vi.fn(),
107107
setAutoHideCursor: vi.fn(),
108+
setFullScreen: vi.fn(),
109+
setOpacity: vi.fn(),
108110
setTitle: vi.fn(),
109111
setTitleBarOverlay: vi.fn(),
110112
show: vi.fn(),
@@ -127,6 +129,8 @@ function makeFakeBrowserWindow() {
127129
setZoomLevel: webContents.setZoomLevel,
128130
setBackgroundThrottling: webContents.setBackgroundThrottling,
129131
setAutoHideCursor: window.setAutoHideCursor,
132+
setFullScreen: window.setFullScreen,
133+
setOpacity: window.setOpacity,
130134
webContentsListeners,
131135
windowListeners,
132136
};
@@ -394,6 +398,25 @@ const makeSplashScenario = (createOutcomes: readonly (Electron.BrowserWindow | n
394398
});
395399

396400
describe("DesktopWindow", () => {
401+
it("leaves fullscreen before concealing a pending quit", () => {
402+
const fakeWindow = makeFakeBrowserWindow();
403+
404+
DesktopWindow.concealPendingQuitWindow(fakeWindow.window);
405+
assert.deepEqual(fakeWindow.setOpacity.mock.calls, [[0]]);
406+
407+
fakeWindow.setOpacity.mockClear();
408+
fakeWindow.isFullScreen.mockReturnValue(true);
409+
DesktopWindow.concealPendingQuitWindow(fakeWindow.window);
410+
assert.deepEqual(fakeWindow.setFullScreen.mock.calls, [[false]]);
411+
assert.deepEqual(fakeWindow.setOpacity.mock.calls, [[0]]);
412+
413+
fakeWindow.setOpacity.mockClear();
414+
fakeWindow.isFullScreen.mockReturnValue(false);
415+
fakeWindow.isDestroyed.mockReturnValue(true);
416+
DesktopWindow.concealPendingQuitWindow(fakeWindow.window);
417+
assert.equal(fakeWindow.setOpacity.mock.calls.length, 0);
418+
});
419+
397420
it("restores bounds only when the window fits within a connected display", () => {
398421
const persistedBounds = { x: 2040, y: 80, width: 1320, height: 880 };
399422
const displays = [

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,21 @@ export function isRetryableDevelopmentRendererLoadFailure(input: {
207207
);
208208
}
209209

210+
export function concealPendingQuitWindow(
211+
window: Pick<
212+
Electron.BrowserWindow,
213+
"isDestroyed" | "isFullScreen" | "setFullScreen" | "setOpacity"
214+
>,
215+
): void {
216+
if (window.isDestroyed()) return;
217+
if (window.isFullScreen()) {
218+
window.setFullScreen(false);
219+
}
220+
// Electron implements window opacity on macOS and Windows. Linux keeps the
221+
// release-gated quit behavior but cannot make the pending window disappear.
222+
window.setOpacity(0);
223+
}
224+
210225
function getWindowTitleBarOptions(
211226
shouldUseDarkColors: boolean,
212227
platform: NodeJS.Platform,
@@ -570,6 +585,9 @@ export const make = Effect.gen(function* () {
570585
window.webContents.send(QUIT_SHORTCUT_CHANNEL, hint);
571586
}
572587
},
588+
// Keep the transparent window focused until the physical shortcut is
589+
// released so its remaining repeats cannot reach the next app.
590+
concealWindow: () => concealPendingQuitWindow(window),
573591
quit: () => {
574592
void runPromise(electronApp.quit);
575593
},

‎apps/desktop/src/window/QuitHold.test.ts‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ function makeHarness(options?: {
3232
getMode?: () => Promise<QuitConfirmationMode>;
3333
}) {
3434
const notifications: Array<QuitShortcutHintEvent> = [];
35+
const concealWindow = vi.fn();
3536
const quit = vi.fn();
3637
const handler = makeQuitShortcutHandler({
3738
platform: options?.platform ?? "darwin",
3839
getMode: options?.getMode ?? (() => Promise.resolve(options?.mode ?? "hold")),
3940
notify: (event) => notifications.push(event),
41+
concealWindow,
4042
quit,
4143
});
4244
const preventDefault = vi.fn();
@@ -57,7 +59,7 @@ function makeHarness(options?: {
5759
await send(makeInput({ isAutoRepeat: true, ...repeatOverrides }));
5860
}
5961
};
60-
return { notifications, quit, preventDefault, send, holdFor };
62+
return { notifications, concealWindow, quit, preventDefault, send, holdFor };
6163
}
6264

6365
describe("makeQuitShortcutHandler", () => {
@@ -82,10 +84,11 @@ describe("makeQuitShortcutHandler", () => {
8284
expect(harness.notifications).toEqual([HOLD_DOWN, UP]);
8385
});
8486

85-
it("quits after a completed hold is released", async () => {
87+
it("conceals a completed hold, then quits after release", async () => {
8688
const harness = makeHarness();
8789
await harness.send(makeInput({}));
8890
await harness.holdFor(QUIT_HOLD_DURATION_MS + 200);
91+
expect(harness.concealWindow).toHaveBeenCalledTimes(1);
8992
expect(harness.quit).not.toHaveBeenCalled();
9093
await harness.send(makeInput({ type: "keyUp", key: "Meta", meta: false }));
9194
expect(harness.quit).not.toHaveBeenCalled();
@@ -94,6 +97,32 @@ describe("makeQuitShortcutHandler", () => {
9497
expect(harness.notifications).toEqual([HOLD_DOWN, UP]);
9598
});
9699

100+
it("keeps a concealed hold committed when another key is pressed", async () => {
101+
const harness = makeHarness();
102+
await harness.send(makeInput({}));
103+
await harness.holdFor(QUIT_HOLD_DURATION_MS);
104+
105+
await harness.send(makeInput({ key: "Shift", shift: true }));
106+
expect(harness.concealWindow).toHaveBeenCalledTimes(1);
107+
expect(harness.quit).not.toHaveBeenCalled();
108+
109+
vi.advanceTimersByTime(QUIT_HOLD_RELEASE_GRACE_MS);
110+
expect(harness.quit).toHaveBeenCalledTimes(1);
111+
});
112+
113+
it("keeps a concealed hold committed through a fresh Cmd+Q press", async () => {
114+
const harness = makeHarness();
115+
await harness.send(makeInput({}));
116+
await harness.holdFor(QUIT_HOLD_DURATION_MS);
117+
118+
await harness.send(makeInput({}));
119+
expect(harness.concealWindow).toHaveBeenCalledTimes(1);
120+
expect(harness.quit).not.toHaveBeenCalled();
121+
122+
await harness.send(makeInput({ type: "keyUp" }));
123+
expect(harness.quit).toHaveBeenCalledTimes(1);
124+
});
125+
97126
it("quits when a completed hold goes quiet without release events", async () => {
98127
const harness = makeHarness();
99128
await harness.send(makeInput({}));
@@ -164,6 +193,7 @@ describe("makeQuitShortcutHandler", () => {
164193
await harness.send(makeInput({ type: "keyUp" }));
165194
expect(harness.notifications).toEqual([HOLD_DOWN, UP]);
166195
vi.advanceTimersByTime((QUIT_HOLD_DURATION_MS + QUIT_HOLD_RELEASE_GRACE_MS) * 2);
196+
expect(harness.concealWindow).not.toHaveBeenCalled();
167197
expect(harness.quit).not.toHaveBeenCalled();
168198
});
169199

@@ -179,6 +209,7 @@ describe("makeQuitShortcutHandler", () => {
179209
it("quits without showing a hint in direct mode", async () => {
180210
const harness = makeHarness({ mode: "direct" });
181211
await harness.send(makeInput({}));
212+
expect(harness.concealWindow).not.toHaveBeenCalled();
182213
expect(harness.quit).toHaveBeenCalledTimes(1);
183214
expect(harness.notifications).toEqual([]);
184215
});
@@ -272,6 +303,7 @@ describe("makeQuitShortcutHandler", () => {
272303
await harness.send(makeInput({}));
273304
vi.advanceTimersByTime(QUIT_DOUBLE_PRESS_MS - 100);
274305
await harness.send(makeInput({}));
306+
expect(harness.concealWindow).not.toHaveBeenCalled();
275307
expect(harness.quit).toHaveBeenCalledTimes(1);
276308
expect(harness.notifications).toEqual([DOUBLE_CLICK_DOWN, UP]);
277309
});

‎apps/desktop/src/window/QuitHold.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface QuitShortcutOptions {
3232
readonly platform: NodeJS.Platform;
3333
readonly getMode: () => Promise<QuitConfirmationMode>;
3434
readonly notify: (event: QuitShortcutHintEvent) => void;
35+
readonly concealWindow: () => void;
3536
readonly quit: () => void;
3637
}
3738

@@ -120,12 +121,14 @@ export function makeQuitShortcutHandler(
120121
repeatCadenceMs = now - (lastRepeatAt === 0 ? heldSince : lastRepeatAt);
121122
lastRepeatAt = now;
122123
}
123-
if (quitOnRelease && input.isAutoRepeat && key === "q") {
124+
if (quitOnRelease) {
124125
event.preventDefault();
125-
if (modifierDown) {
126-
quitAfterQuietPeriod();
127-
} else {
128-
clearWatchdog();
126+
if (key === "q") {
127+
if (modifierDown) {
128+
quitAfterQuietPeriod();
129+
} else {
130+
clearWatchdog();
131+
}
129132
}
130133
return;
131134
}
@@ -154,6 +157,7 @@ export function makeQuitShortcutHandler(
154157
if (mode === "hold" && armed && Date.now() - heldSince >= QUIT_HOLD_DURATION_MS) {
155158
armed = false;
156159
quitOnRelease = true;
160+
options.concealWindow();
157161
quitAfterQuietPeriod();
158162
}
159163
return;

0 commit comments

Comments
 (0)