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

QuitHoldOverlay.tsx

50 lines1.5 KB

1import { useEffect, useState } from "react";
2​
3import { isMacPlatform } from "../lib/utils";
4​
5const HOLD_HINT_LINGER_MS = 1200;
6​
7export function QuitHoldOverlay() {
8 const [visibleMode, setVisibleMode] = useState<"hold" | "double-click" | null>(null);
9​
10 useEffect(() => {
11 const subscribe = window.desktopBridge?.onQuitShortcut;
12 if (!subscribe) return;
13 let hideTimer: number | undefined;
14 let pressedMode: "hold" | "double-click" = "hold";
15 const unsubscribe = subscribe((hint) => {
16 window.clearTimeout(hideTimer);
17 if (hint.state === "down") {
18 pressedMode = hint.mode;
19 setVisibleMode(hint.mode);
20 return;
21 }
22 if (pressedMode === "double-click") {
23 setVisibleMode(null);
24 return;
25 }
26 hideTimer = window.setTimeout(() => setVisibleMode(null), HOLD_HINT_LINGER_MS);
27 });
28 return () => {
29 window.clearTimeout(hideTimer);
30 unsubscribe();
31 };
32 }, []);
33​
34 if (!visibleMode) return null;
35 const shortcut = isMacPlatform(navigator.platform) ? "⌘Q" : "Ctrl+Q";
36 const message =
37 visibleMode === "hold"
38 ? `Hold ${shortcut} or press twice to quit`
39 : `Press ${shortcut} again to quit`;
40 return (
41 <div
42 role="status"
43 className="pointer-events-none fixed inset-x-0 top-[22%] z-100 flex justify-center"
44 >
45 <div className="rounded-full bg-foreground/95 px-8 py-4 text-2xl font-bold text-background shadow-xl">
46 {message}
47 </div>
48 </div>
49 );