Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

QuitHoldOverlay.tsx

47 lines1.4 KB

1import { useEffect, useState } from "react";
2​
3import { isMacPlatform } from "../lib/utils";
4​
5// Matches the hold duration in apps/desktop/src/window/QuitHold.ts: the hint
6// from a quick tap lingers for as long as a full hold would have taken.
7const HIDE_AFTER_RELEASE_MS = 1200;
8​
9/**
10 * Chrome-style "Hold ⌘Q to Quit" hint. The desktop main process intercepts
11 * the quit accelerator and pushes press/release states; a quick tap shows
12 * this pill while a full hold quits the app.
13 */
14export function QuitHoldOverlay() {
15 const [visible, setVisible] = useState(false);
16​
17 useEffect(() => {
18 const subscribe = window.desktopBridge?.onQuitShortcut;
19 if (!subscribe) return;
20 let hideTimer: number | undefined;
21 const unsubscribe = subscribe((state) => {
22 window.clearTimeout(hideTimer);
23 if (state === "down") {
24 setVisible(true);
25 return;
26 }
27 hideTimer = window.setTimeout(() => setVisible(false), HIDE_AFTER_RELEASE_MS);
28 });
29 return () => {
30 window.clearTimeout(hideTimer);
31 unsubscribe();
32 };
33 }, []);
34​
35 if (!visible) return null;
36 const shortcut = isMacPlatform(navigator.platform) ? "⌘Q" : "Ctrl+Q";
37 return (
38 <div
39 role="status"
40 className="pointer-events-none fixed inset-x-0 top-[22%] z-100 flex justify-center"
41 >
42 <div className="rounded-full bg-neutral-700/95 px-8 py-4 text-2xl font-bold text-white shadow-xl">
43 Hold {shortcut} to Quit
44 </div>
45 </div>
46 );