Repository navigation
feat(desktop): Chrome-style hold-to-quit #5508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juliusmarminge
merged 13 commits into
pingdotgg:main
from
Bil0000:t3code/quit-confirmation-dialog
Aug 15, 2026
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6c7f2a5
feat(contracts): add confirmQuit client setting
Bil0000 a036330
feat(desktop): confirm before quitting the app
Bil0000 b4f3043
feat(web): add quit confirmation setting
Bil0000 61e37fb
fix(desktop): never let the quit prompt strand the app
Bil0000 c0a33cb
fix(web): keep desktop-only settings out of browser search
Bil0000 996790d
Merge origin/main into t3code/quit-confirmation-dialog
Bil0000 88c7327
feat(desktop): replace quit dialog with Chrome-style hold-to-quit
Bil0000 eebafda
Merge remote-tracking branch 'origin/main' into t3code/quit-confirmat…
Bil0000 7089780
fix(desktop): merge fallout for hold-to-quit tests
Bil0000 f5506c7
fix(desktop): require auto-repeat evidence before hold-to-quit fires
Bil0000 de7a1db
fix(desktop): allow wall-clock timing in the quit-hold input handler
Bil0000 a809627
feat(desktop): shorten hold-to-quit and add double-tap quit
Bil0000 47fd70d
fix(desktop): interrupted quit press no longer counts toward double-tap
Bil0000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| import { makeQuitHoldHandler, QUIT_HOLD_DURATION_MS } from "./QuitHold.ts"; | ||
| import type { QuitHoldKeyInput, QuitHoldState } from "./QuitHold.ts"; | ||
|
|
||
| function makeInput(overrides: Partial<QuitHoldKeyInput>): QuitHoldKeyInput { | ||
| return { | ||
| type: "keyDown", | ||
| key: "q", | ||
| meta: true, | ||
| control: false, | ||
| alt: false, | ||
| shift: false, | ||
| isAutoRepeat: false, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function makeHarness(options?: { enabled?: boolean; platform?: NodeJS.Platform }) { | ||
| const notifications: Array<QuitHoldState> = []; | ||
| const quit = vi.fn(); | ||
| const handler = makeQuitHoldHandler({ | ||
| platform: options?.platform ?? "darwin", | ||
| isEnabled: () => Promise.resolve(options?.enabled ?? true), | ||
| notify: (state) => notifications.push(state), | ||
| quit, | ||
| }); | ||
| const preventDefault = vi.fn(); | ||
| const send = async (input: QuitHoldKeyInput) => { | ||
| handler({ preventDefault }, input); | ||
| // Let the isEnabled promise settle. | ||
| await Promise.resolve(); | ||
| await Promise.resolve(); | ||
| }; | ||
| return { notifications, quit, preventDefault, send }; | ||
| } | ||
|
|
||
| describe("makeQuitHoldHandler", () => { | ||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| }); | ||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| it("shows the hint on a tap without quitting", async () => { | ||
| const harness = makeHarness(); | ||
| await harness.send(makeInput({})); | ||
| expect(harness.preventDefault).toHaveBeenCalledTimes(1); | ||
| expect(harness.notifications).toEqual(["down"]); | ||
|
|
||
| await harness.send(makeInput({ type: "keyUp" })); | ||
| expect(harness.notifications).toEqual(["down", "up"]); | ||
| vi.advanceTimersByTime(QUIT_HOLD_DURATION_MS * 2); | ||
| expect(harness.quit).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("quits after the shortcut is held for the full duration", async () => { | ||
| const harness = makeHarness(); | ||
| await harness.send(makeInput({})); | ||
| await harness.send(makeInput({ isAutoRepeat: true })); | ||
| vi.advanceTimersByTime(QUIT_HOLD_DURATION_MS - 1); | ||
| expect(harness.quit).not.toHaveBeenCalled(); | ||
| vi.advanceTimersByTime(1); | ||
| expect(harness.quit).toHaveBeenCalledTimes(1); | ||
| // Only one hint for the whole hold, despite auto-repeats. | ||
| expect(harness.notifications).toEqual(["down"]); | ||
| }); | ||
|
|
||
| it("cancels the hold when the modifier is released first", async () => { | ||
| const harness = makeHarness(); | ||
| await harness.send(makeInput({})); | ||
| await harness.send(makeInput({ type: "keyUp", key: "Meta", meta: false })); | ||
| expect(harness.notifications).toEqual(["down", "up"]); | ||
| vi.advanceTimersByTime(QUIT_HOLD_DURATION_MS * 2); | ||
| expect(harness.quit).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("quits immediately on a single press when disabled", async () => { | ||
| const harness = makeHarness({ enabled: false }); | ||
| await harness.send(makeInput({})); | ||
| expect(harness.quit).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("ignores other shortcuts", async () => { | ||
| const harness = makeHarness(); | ||
| await harness.send(makeInput({ key: "w" })); | ||
| await harness.send(makeInput({ shift: true })); | ||
| await harness.send(makeInput({ meta: false })); | ||
| expect(harness.preventDefault).not.toHaveBeenCalled(); | ||
| expect(harness.notifications).toEqual([]); | ||
| }); | ||
|
|
||
| it("uses control on non-mac platforms", async () => { | ||
| const harness = makeHarness({ platform: "linux" }); | ||
| await harness.send(makeInput({ meta: false, control: true })); | ||
| expect(harness.preventDefault).toHaveBeenCalledTimes(1); | ||
| vi.advanceTimersByTime(QUIT_HOLD_DURATION_MS); | ||
| expect(harness.quit).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // Chrome-style hold-to-quit. The quit accelerator is intercepted in | ||
| // before-input-event (which runs before the native menu accelerator), and the | ||
| // app only quits once the shortcut has been held for QUIT_HOLD_DURATION_MS. | ||
| // A quick tap just shows the renderer's "Hold to Quit" hint. Quitting from the | ||
| // application menu itself is untouched and quits immediately. | ||
| export const QUIT_HOLD_DURATION_MS = 1500; | ||
|
|
||
| export type QuitHoldState = "down" | "up"; | ||
|
|
||
| export interface QuitHoldKeyInput { | ||
| readonly type: string; | ||
| readonly key: string; | ||
| readonly meta: boolean; | ||
| readonly control: boolean; | ||
| readonly alt: boolean; | ||
| readonly shift: boolean; | ||
| readonly isAutoRepeat: boolean; | ||
| } | ||
|
|
||
| export interface QuitHoldOptions { | ||
| readonly platform: NodeJS.Platform; | ||
| readonly isEnabled: () => Promise<boolean>; | ||
| readonly notify: (state: QuitHoldState) => void; | ||
| readonly quit: () => void; | ||
| } | ||
|
|
||
| export function makeQuitHoldHandler( | ||
| options: QuitHoldOptions, | ||
| ): (event: { preventDefault: () => void }, input: QuitHoldKeyInput) => void { | ||
| const modifierKey = options.platform === "darwin" ? "meta" : "control"; | ||
| let holdTimer: NodeJS.Timeout | undefined; | ||
|
macroscopeapp[bot] marked this conversation as resolved.
Outdated
|
||
| let holding = false; | ||
|
|
||
| const release = () => { | ||
| if (!holding) return; | ||
| holding = false; | ||
| if (holdTimer !== undefined) { | ||
| clearTimeout(holdTimer); | ||
| holdTimer = undefined; | ||
| } | ||
| options.notify("up"); | ||
| }; | ||
|
Bil0000 marked this conversation as resolved.
|
||
|
|
||
| return (event, input) => { | ||
| const key = input.key.toLowerCase(); | ||
| if (input.type === "keyUp") { | ||
| if (key === "q" || key === modifierKey) release(); | ||
| return; | ||
| } | ||
| if (input.type !== "keyDown") return; | ||
|
|
||
| const modifierDown = options.platform === "darwin" ? input.meta : input.control; | ||
| if (!modifierDown || input.alt || input.shift || key !== "q") return; | ||
|
Bil0000 marked this conversation as resolved.
Outdated
|
||
|
|
||
| event.preventDefault(); | ||
| if (input.isAutoRepeat || holding) return; | ||
|
|
||
| holding = true; | ||
| options.notify("down"); | ||
| void options.isEnabled().then( | ||
| (enabled) => { | ||
| if (!enabled) { | ||
| // Hold-to-quit disabled: a single press quits immediately. | ||
| holding = false; | ||
| options.quit(); | ||
| return; | ||
| } | ||
| if (!holding) return; | ||
| holdTimer = setTimeout(() => { | ||
| holdTimer = undefined; | ||
| holding = false; | ||
| options.quit(); | ||
| }, QUIT_HOLD_DURATION_MS); | ||
| }, | ||
| // A failed settings read must never strand the quit request. | ||
| () => { | ||
| holding = false; | ||
| options.quit(); | ||
| }, | ||
| ); | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.