-
-
Notifications
You must be signed in to change notification settings - Fork 350
Add hold-to-quit progress bar and experimental toggle #238
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
Closed
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| type QuitHoldIndicatorProps = { | ||
| isActive: boolean; | ||
| progress: number; | ||
| }; | ||
|
|
||
| export function QuitHoldIndicator({ | ||
| isActive, | ||
| progress, | ||
| }: QuitHoldIndicatorProps) { | ||
| if (!isActive) { | ||
| return null; | ||
| } | ||
|
|
||
| const percent = Math.min(100, Math.max(0, progress * 100)); | ||
|
|
||
| return ( | ||
| <div | ||
| className="quit-hold-indicator" | ||
| role="progressbar" | ||
| aria-label="Hold to quit" | ||
| aria-valuemin={0} | ||
| aria-valuemax={100} | ||
| aria-valuenow={Math.round(percent)} | ||
| > | ||
| <span className="quit-hold-track"> | ||
| <span className="quit-hold-fill" style={{ width: `${percent}%` }} /> | ||
| </span> | ||
| </div> | ||
| ); | ||
| } |
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,36 @@ | ||
| import type { QuitHoldState } from "../hooks/useHoldToQuit"; | ||
|
|
||
| type QuitHoldToastProps = { | ||
| state: QuitHoldState; | ||
| }; | ||
|
|
||
| export function QuitHoldToast({ state }: QuitHoldToastProps) { | ||
| if (!state.isVisible) { | ||
| return null; | ||
| } | ||
|
|
||
| const isCanceled = state.status === "canceled"; | ||
| const message = isCanceled ? "Quit canceled" : "Hold Cmd+Q to quit"; | ||
| const progressPercent = Math.round(state.progress * 100); | ||
|
|
||
| return ( | ||
| <div className="quit-hold-toasts" role="region" aria-live="polite"> | ||
| <div | ||
| className={`quit-hold-toast ${state.status}`} | ||
| role="status" | ||
| > | ||
| <div className="quit-hold-toast-body">{message}</div> | ||
| {!isCanceled && ( | ||
| <div className="quit-hold-toast-progress"> | ||
| <div className="quit-hold-toast-progress-bar"> | ||
| <span | ||
| className="quit-hold-toast-progress-fill" | ||
| style={{ width: `${progressPercent}%` }} | ||
| /> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
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,78 @@ | ||
| // @vitest-environment jsdom | ||
| import { act, renderHook } from "@testing-library/react"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { requestAppQuit } from "../../../services/tauri"; | ||
| import { useHoldToQuit } from "./useHoldToQuit"; | ||
|
|
||
| vi.mock("../../../services/tauri", () => ({ | ||
| ackMenuQuit: vi.fn(), | ||
| requestAppQuit: vi.fn(), | ||
| })); | ||
| vi.mock("../../../services/events", () => ({ | ||
| subscribeMenuQuit: () => () => {}, | ||
| })); | ||
|
|
||
| describe("useHoldToQuit", () => { | ||
| const originalPlatform = navigator.platform; | ||
|
|
||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| Object.defineProperty(navigator, "platform", { | ||
| value: "MacIntel", | ||
| configurable: true, | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| Object.defineProperty(navigator, "platform", { | ||
| value: originalPlatform, | ||
| configurable: true, | ||
| }); | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("cancels hold and hides toast on key release", () => { | ||
| const { result } = renderHook(() => useHoldToQuit({ enabled: true })); | ||
|
|
||
| act(() => { | ||
| window.dispatchEvent( | ||
| new KeyboardEvent("keydown", { key: "q", metaKey: true }), | ||
| ); | ||
| }); | ||
|
|
||
| expect(result.current.state.status).toBe("holding"); | ||
| expect(result.current.state.isVisible).toBe(true); | ||
|
|
||
| act(() => { | ||
| window.dispatchEvent(new KeyboardEvent("keyup", { key: "q" })); | ||
| }); | ||
|
|
||
| expect(result.current.state.status).toBe("canceled"); | ||
|
|
||
| act(() => { | ||
| vi.advanceTimersByTime(1000); | ||
| }); | ||
|
|
||
| expect(result.current.state.isVisible).toBe(false); | ||
| }); | ||
|
|
||
| it("requests quit after holding long enough", async () => { | ||
| const requestMock = vi.mocked(requestAppQuit); | ||
| requestMock.mockResolvedValue(); | ||
|
|
||
| renderHook(() => useHoldToQuit({ enabled: true })); | ||
|
|
||
| act(() => { | ||
| window.dispatchEvent( | ||
| new KeyboardEvent("keydown", { key: "q", metaKey: true }), | ||
| ); | ||
| }); | ||
|
|
||
| act(() => { | ||
| vi.advanceTimersByTime(1600); | ||
| }); | ||
|
|
||
| expect(requestMock).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When hold-to-quit is enabled, the macOS quit menu path no longer calls
app.exit(0)and instead only emitsmenu-quitto the main window. If the renderer isn’t ready (early startup) or has crashed/hung, no listener will ever callrequestAppQuit, so the Quit menu/accelerator becomes a no-op and the app cannot exit normally. Consider adding a fallback exit when no window exists or after a short timeout if the event isn’t handled.Useful? React with 👍 / 👎.