Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

refactor: major hotkey selection refactor

Gabriel Stein7312996c3123
diff --git a/main.js b/main.js
index 917a670b9..2d0bd62b4 100644
--- a/main.js
+++ b/main.js
@@ -161,6 +161,15 @@ trayManager.setWindowManager(windowManager);
if (process.platform === "darwin") {
globeKeyManager.on("globe-down", () => {
+ // Forward to control panel for hotkey capture
+ if (
+ windowManager.controlPanelWindow &&
+ !windowManager.controlPanelWindow.isDestroyed()
+ ) {
+ windowManager.controlPanelWindow.webContents.send("globe-key-pressed");
+ }
+
+ // Handle dictation toggle if Globe is the current hotkey
if (hotkeyManager.getCurrentHotkey && hotkeyManager.getCurrentHotkey() === "GLOBE") {
if (
windowManager.mainWindow &&
diff --git a/preload.js b/preload.js
index 571d162cf..557c34ffb 100644
--- a/preload.js
+++ b/preload.js
@@ -169,12 +169,14 @@ contextBridge.exposeInMainWorld("electronAPI", {
getLogLevel: () => ipcRenderer.invoke("get-log-level"),
log: (entry) => ipcRenderer.invoke("app-log", entry),
-
- // System settings helpers
- openMicrophoneSettings: () => ipcRenderer.invoke("open-microphone-settings"),
- openSoundInputSettings: () =>
- ipcRenderer.invoke("open-sound-input-settings"),
-
+
+ // Globe key listener for hotkey capture (macOS only)
+ onGlobeKeyPressed: (callback) => {
+ const listener = () => callback?.();
+ ipcRenderer.on("globe-key-pressed", listener);
+ return () => ipcRenderer.removeListener("globe-key-pressed", listener);
+ },
+
// Remove all listeners for a channel
removeAllListeners: (channel) => {
ipcRenderer.removeAllListeners(channel);
diff --git a/src/App.jsx b/src/App.jsx
index b7c4da4f3..4da074800 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,6 +1,5 @@
import React, { useState, useEffect, useRef } from "react";
import "./index.css";
-import { X } from "lucide-react";
import { useToast } from "./components/ui/Toast";
import { LoadingDots } from "./components/ui/LoadingDots";
import { useHotkey } from "./hooks/useHotkey";
@@ -209,20 +208,6 @@ export default function App() {
}
}}
>
- {isRecording && isHovered && (
- <Tooltip content="Cancel recording">
- <button
- aria-label="Cancel recording"
- onClick={(e) => {
- e.stopPropagation();
- cancelRecording();
- }}
- className="w-7 h-7 rounded-full bg-neutral-800/90 hover:bg-red-500 border border-white/20 hover:border-red-400 flex items-center justify-center transition-all duration-150 shadow-lg backdrop-blur-sm"
- >
- <X size={12} strokeWidth={2.5} color="white" />
- </button>
- </Tooltip>
- )}
<Tooltip content={micProps.tooltip}>
<button
ref={buttonRef}
diff --git a/src/components/OnboardingFlow.tsx b/src/components/OnboardingFlow.tsx
index 94bd2afd5..66de81cae 100644
--- a/src/components/OnboardingFlow.tsx
+++ b/src/components/OnboardingFlow.tsx
@@ -12,7 +12,7 @@ import {
Download,
Key,
Shield,
- Keyboard,
+ Command,
TestTube,
Sparkles,
Lock,
@@ -37,7 +37,6 @@ import { useSettings } from "../hooks/useSettings";
import { getLanguageLabel, REASONING_PROVIDERS } from "../utils/languages";
import LanguageSelector from "./ui/LanguageSelector";
import { UnifiedModelPickerCompact } from "./UnifiedModelPicker";
-const InteractiveKeyboard = React.lazy(() => import("./ui/Keyboard"));
import { setAgentName as saveAgentName } from "../utils/agentName";
import { formatHotkeyLabel, getDefaultHotkey } from "../utils/hotkeys";
import { API_ENDPOINTS, buildApiUrl, normalizeBaseUrl } from "../config/constants";
@@ -318,7 +317,7 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
{ title: "Privacy", icon: Lock },
{ title: "Setup", icon: Settings },
{ title: "Permissions", icon: Shield },
- { title: "Hotkey", icon: Keyboard },
+ { title: "Hotkey", icon: Command },
{ title: "Test", icon: TestTube },
{ title: "Agent Name", icon: User },
{ title: "Finish", icon: Check },
@@ -918,60 +917,20 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
<div className="text-center">
<h2 className="text-2xl font-bold text-gray-900 mb-2">Choose Your Hotkey</h2>
<p className="text-gray-600">
- Press any key or key combination (like Cmd+Shift+K) to set your dictation hotkey
+ Set the key combination you'll use to start and stop dictation
</p>
</div>
- <div className="space-y-4">
- <div>
- <label className="block text-sm font-medium text-gray-700 mb-2">
- Activation Key
- </label>
- <HotkeyInput
- value={hotkey}
- onChange={async (newHotkey) => {
- // Immediately register the new hotkey
- const success = await registerHotkey(newHotkey);
- if (success) {
- setHotkey(newHotkey);
- }
- }}
- placeholder="Click here and press a key combination..."
- disabled={isHotkeyRegistering}
- />
- <p className="text-xs text-gray-500 mt-6">
- Supports single keys (F1, `) or combinations (Cmd+Shift+K)
- </p>
- </div>
-
- <div className="bg-indigo-50 p-4 rounded-lg border border-indigo-200">
- <h4 className="font-medium text-indigo-900 mb-3">
- Current hotkey:
- </h4>
- <div className="flex items-center justify-center">
- <kbd className="px-4 py-2 bg-white border-2 border-indigo-300 rounded-lg font-mono text-xl font-semibold text-indigo-900 shadow-sm">
- {formatHotkeyLabel(hotkey)}
- </kbd>
- </div>
- </div>
-
- <div className="bg-gray-50 p-4 rounded-lg">
- <h4 className="font-medium text-gray-900 mb-3">
- Or click a key on the keyboard:
- </h4>
- <React.Suspense fallback={<div>Loading keyboard...</div>}>
- <InteractiveKeyboard
- selectedKey={hotkey}
- setSelectedKey={async (key) => {
- const success = await registerHotkey(key);
- if (success) {
- setHotkey(key);
- }
- }}
- />
- </React.Suspense>
- </div>
- </div>
+ <HotkeyInput
+ value={hotkey}
+ onChange={async (newHotkey) => {
+ const success = await registerHotkey(newHotkey);
+ if (success) {
+ setHotkey(newHotkey);
+ }
+ }}
+ disabled={isHotkeyRegistering}
+ />
</div>
);
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index feb0ea84d..38830c53b 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -1,7 +1,7 @@
import React, { useState, useCallback, useEffect, useRef } from "react";
import { Button } from "./ui/button";
import { Input } from "./ui/input";
-import { RefreshCw, Download, Keyboard, Mic, Shield } from "lucide-react";
+import { RefreshCw, Download, Command, Mic, Shield } from "lucide-react";
import WhisperModelPicker from "./WhisperModelPicker";
import ProcessingModeSelector from "./ui/ProcessingModeSelector";
import ApiKeyInput from "./ui/ApiKeyInput";
@@ -22,7 +22,6 @@ import AIModelSelectorEnhanced from "./AIModelSelectorEnhanced";
import type { UpdateInfoResult } from "../types/electron";
import { HotkeyInput } from "./ui/HotkeyInput";
import { useHotkeyRegistration } from "../hooks/useHotkeyRegistration";
-const InteractiveKeyboard = React.lazy(() => import("./ui/Keyboard"));
export type SettingsSectionType =
| "general"
@@ -120,7 +119,7 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPage
onSuccess: (registeredHotkey) => {
setDictationKey(registeredHotkey);
},
- showSuccessToast: true,
+ showSuccessToast: false,
showErrorToast: true,
showAlert: showAlertDialog,
});
@@ -718,55 +717,13 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPage
Configure the key or key combination you press to start and stop voice dictation.
</p>
</div>
- <div className="space-y-4">
- <div>
- <label className="block text-sm font-medium text-gray-700 mb-2">
- Activation Key
- </label>
- <HotkeyInput
- value={dictationKey}
- onChange={async (newHotkey) => {
- await registerHotkey(newHotkey);
- }}
- placeholder="Click here and press a key combination..."
- disabled={isHotkeyRegistering}
- />
- <p className="text-xs text-gray-500 mt-6">
- Supports single keys (F1, `) or combinations (Cmd+Shift+K)
- </p>
- </div>
-
- <div className="bg-indigo-50 p-4 rounded-lg border border-indigo-200">
- <h4 className="font-medium text-indigo-900 mb-3">
- Current hotkey:
- </h4>
- <div className="flex items-center justify-center">
- <kbd className="px-4 py-2 bg-white border-2 border-indigo-300 rounded-lg font-mono text-xl font-semibold text-indigo-900 shadow-sm">
- {formatHotkeyLabel(dictationKey)}
- </kbd>
- </div>
- </div>
-
- <div className="bg-gray-50 p-4 rounded-lg">
- <h4 className="font-medium text-gray-900 mb-3">
- Or click a key on the keyboard:
- </h4>
- <React.Suspense
- fallback={
- <div className="h-32 flex items-center justify-center text-gray-500">
- Loading keyboard...
- </div>
- }
- >
- <InteractiveKeyboard
- selectedKey={dictationKey}
- setSelectedKey={async (key) => {
- await registerHotkey(key);
- }}
- />
- </React.Suspense>
- </div>
- </div>
+ <HotkeyInput
+ value={dictationKey}
+ onChange={async (newHotkey) => {
+ await registerHotkey(newHotkey);
+ }}
+ disabled={isHotkeyRegistering}
+ />
</div>
{/* Permissions Section */}
@@ -824,7 +781,7 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPage
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 text-sm mb-6">
<div className="text-center p-4 border border-gray-200 rounded-xl bg-white">
<div className="w-8 h-8 mx-auto mb-2 bg-indigo-600 rounded-lg flex items-center justify-center">
- <Keyboard className="w-4 h-4 text-white" />
+ <Command className="w-4 h-4 text-white" />
</div>
<p className="font-medium text-gray-800 mb-1">Default Hotkey</p>
<p className="text-gray-600 font-mono text-xs">
diff --git a/src/components/ui/HotkeyInput.tsx b/src/components/ui/HotkeyInput.tsx
index 436358587..27ef9dc94 100644
--- a/src/components/ui/HotkeyInput.tsx
+++ b/src/components/ui/HotkeyInput.tsx
@@ -1,13 +1,7 @@
import React, { useState, useCallback, useRef, useEffect } from "react";
import { formatHotkeyLabel } from "../../utils/hotkeys";
-/**
- * Layout-independent key code to key name mapping.
- * Uses e.code (physical key) instead of e.key (layout-dependent character)
- * to ensure hotkeys work correctly across different keyboard layouts.
- */
const CODE_TO_KEY: Record<string, string> = {
- // Number row
Backquote: "`",
Digit1: "1",
Digit2: "2",
@@ -21,7 +15,6 @@ const CODE_TO_KEY: Record<string, string> = {
Digit0: "0",
Minus: "-",
Equal: "=",
-
// QWERTY row
KeyQ: "Q",
KeyW: "W",
@@ -36,7 +29,6 @@ const CODE_TO_KEY: Record<string, string> = {
BracketLeft: "[",
BracketRight: "]",
Backslash: "\\",
-
// ASDF row
KeyA: "A",
KeyS: "S",
@@ -49,7 +41,6 @@ const CODE_TO_KEY: Record<string, string> = {
KeyL: "L",
Semicolon: ";",
Quote: "'",
-
// ZXCV row
KeyZ: "Z",
KeyX: "X",
@@ -61,14 +52,12 @@ const CODE_TO_KEY: Record<string, string> = {
Comma: ",",
Period: ".",
Slash: "/",
-
// Special keys
Space: "Space",
Escape: "Esc",
Tab: "Tab",
Enter: "Enter",
Backspace: "Backspace",
-
// Function keys
F1: "F1",
F2: "F2",
@@ -82,14 +71,12 @@ const CODE_TO_KEY: Record<string, string> = {
F10: "F10",
F11: "F11",
F12: "F12",
-
// Arrow keys
ArrowUp: "Up",
ArrowDown: "Down",
ArrowLeft: "Left",
ArrowRight: "Right",
-
- // Other common keys
+ // Navigation keys
Insert: "Insert",
Delete: "Delete",
Home: "Home",
@@ -98,9 +85,6 @@ const CODE_TO_KEY: Record<string, string> = {
PageDown: "PageDown",
};
-/**
- * Keys that should be ignored when pressed alone (modifier-only presses)
- */
const MODIFIER_CODES = new Set([
"ShiftLeft",
"ShiftRight",
@@ -117,163 +101,232 @@ export interface HotkeyInputProps {
value: string;
onChange: (hotkey: string) => void;
onBlur?: () => void;
- placeholder?: string;
- className?: string;
disabled?: boolean;
autoFocus?: boolean;
}
-/**
- * Maps a keyboard event to an Electron-compatible accelerator string.
- * Uses physical key codes for layout independence.
- *
- * @example
- * // Returns "CommandOrControl+Shift+K" when Cmd+Shift+K is pressed on macOS
- * // Returns "CommandOrControl+Shift+K" when Ctrl+Shift+K is pressed on Windows/Linux
- */
export function mapKeyboardEventToHotkey(e: KeyboardEvent): string | null {
- // Ignore modifier-only key presses
if (MODIFIER_CODES.has(e.code)) {
return null;
}
- // Get the base key from code
const baseKey = CODE_TO_KEY[e.code];
if (!baseKey) {
return null;
}
- // Build modifier array using Electron's cross-platform convention
const modifiers: string[] = [];
- // CommandOrControl: Cmd on macOS, Ctrl on Windows/Linux
if (e.ctrlKey || e.metaKey) {
modifiers.push("CommandOrControl");
}
-
if (e.altKey) {
modifiers.push("Alt");
}
-
if (e.shiftKey) {
modifiers.push("Shift");
}
- // Combine modifiers and base key
- if (modifiers.length > 0) {
- return [...modifiers, baseKey].join("+");
- }
-
- // Single key (no modifiers)
- return baseKey;
+ return modifiers.length > 0 ? [...modifiers, baseKey].join("+") : baseKey;
}
-/**
- * HotkeyInput - A keyboard capture component for compound hotkeys.
- *
- * Supports:
- * - Single keys (e.g., "F1", "`")
- * - Compound keys (e.g., "CommandOrControl+Shift+K")
- * - Layout-independent key detection using e.code
- * - Cross-platform compatibility with Electron's accelerator format
- */
export function HotkeyInput({
value,
onChange,
onBlur,
- placeholder = "Press a key combination...",
- className = "",
disabled = false,
autoFocus = false,
}: HotkeyInputProps) {
- const [isFocused, setIsFocused] = useState(false);
const [isCapturing, setIsCapturing] = useState(false);
- const inputRef = useRef<HTMLDivElement>(null);
+ const [activeModifiers, setActiveModifiers] = useState<Set<string>>(
+ new Set()
+ );
+ const containerRef = useRef<HTMLDivElement>(null);
+ const isMac =
+ typeof navigator !== "undefined" && /Mac|Darwin/.test(navigator.platform);
const handleKeyDown = useCallback(
(e: React.KeyboardEvent<HTMLDivElement>) => {
if (disabled) return;
-
- // Prevent default behavior for most keys
e.preventDefault();
e.stopPropagation();
- // Convert keyboard event to native KeyboardEvent for mapping
- const nativeEvent = e.nativeEvent;
- const hotkey = mapKeyboardEventToHotkey(nativeEvent);
+ const mods = new Set<string>();
+ if (e.ctrlKey || e.metaKey) mods.add(isMac ? "Cmd" : "Ctrl");
+ if (e.altKey) mods.add(isMac ? "Option" : "Alt");
+ if (e.shiftKey) mods.add("Shift");
+ setActiveModifiers(mods);
+ const hotkey = mapKeyboardEventToHotkey(e.nativeEvent);
if (hotkey) {
onChange(hotkey);
setIsCapturing(false);
+ setActiveModifiers(new Set());
+ containerRef.current?.blur();
}
},
- [disabled, onChange]
+ [disabled, onChange, isMac]
);
- const handleFocus = useCallback(() => {
- setIsFocused(true);
- setIsCapturing(true);
+ const handleKeyUp = useCallback(() => {
+ setActiveModifiers(new Set());
}, []);
+ const handleFocus = useCallback(() => {
+ if (!disabled) {
+ setIsCapturing(true);
+ }
+ }, [disabled]);
+
const handleBlur = useCallback(() => {
- setIsFocused(false);
setIsCapturing(false);
+ setActiveModifiers(new Set());
onBlur?.();
}, [onBlur]);
- // Auto-focus support
useEffect(() => {
- if (autoFocus && inputRef.current) {
- inputRef.current.focus();
+ if (autoFocus && containerRef.current) {
+ containerRef.current.focus();
}
}, [autoFocus]);
- const displayValue = value ? formatHotkeyLabel(value) : "";
- const isMac =
- typeof navigator !== "undefined" && /Mac|Darwin/.test(navigator.platform);
+ useEffect(() => {
+ if (!isCapturing || !isMac) return;
+
+ const dispose = window.electronAPI?.onGlobeKeyPressed?.(() => {
+ onChange("GLOBE");
+ setIsCapturing(false);
+ setActiveModifiers(new Set());
+ containerRef.current?.blur();
+ });
+
+ return () => dispose?.();
+ }, [isCapturing, isMac, onChange]);
+
+ const displayValue = formatHotkeyLabel(value);
+ const isGlobe = value === "GLOBE";
+
+ const hotkeyParts = value?.includes("+") ? displayValue.split("+") : [];
return (
- <div
- ref={inputRef}
- tabIndex={disabled ? -1 : 0}
- role="button"
- aria-label="Press a key combination to set hotkey"
- onKeyDown={handleKeyDown}
- onFocus={handleFocus}
- onBlur={handleBlur}
- className={`
- relative flex items-center justify-center
- w-full px-4 py-3
- text-center text-lg font-mono
- border-2 rounded-lg
- transition-all duration-200
- cursor-pointer select-none
- focus:outline-none
- ${
- disabled
- ? "bg-gray-100 border-gray-200 text-gray-400 cursor-not-allowed"
- : isFocused
- ? "bg-indigo-50 border-indigo-400 ring-2 ring-indigo-200"
- : "bg-white border-gray-300 hover:border-gray-400"
- }
- ${className}
- `}
- >
- {isCapturing && !displayValue ? (
- <span className="text-indigo-600 animate-pulse">{placeholder}</span>
- ) : displayValue ? (
- <span className="text-gray-900">{displayValue}</span>
- ) : (
- <span className="text-gray-400">{placeholder}</span>
- )}
+ <div className="space-y-3">
+ <div
+ ref={containerRef}
+ tabIndex={disabled ? -1 : 0}
+ role="button"
+ aria-label="Press a key combination to set hotkey"
+ onKeyDown={handleKeyDown}
+ onKeyUp={handleKeyUp}
+ onFocus={handleFocus}
+ onBlur={handleBlur}
+ className={`
+ relative overflow-hidden
+ rounded-xl border-2
+ transition-all duration-300 ease-out
+ cursor-pointer select-none
+ focus:outline-none
+ ${
+ disabled
+ ? "bg-gray-50 border-gray-200 cursor-not-allowed opacity-60"
+ : isCapturing
+ ? "bg-gradient-to-br from-indigo-50 to-purple-50 border-indigo-400 shadow-lg shadow-indigo-100"
+ : "bg-white border-gray-200 hover:border-gray-300 hover:shadow-md"
+ }
+ `}
+ >
+ {isCapturing && (
+ <div className="absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-indigo-500 via-purple-500 to-indigo-500 animate-pulse" />
+ )}
+
+ <div className="px-6 py-5">
+ {isCapturing ? (
+ <div className="space-y-3">
+ <div className="flex items-center justify-center gap-2">
+ <div className="w-2 h-2 bg-red-500 rounded-full animate-pulse" />
+ <span className="text-sm font-medium text-gray-600">
+ Recording
+ </span>
+ </div>
+
+ {activeModifiers.size > 0 ? (
+ <div className="flex items-center justify-center gap-1.5">
+ {Array.from(activeModifiers).map((mod) => (
+ <kbd
+ key={mod}
+ className="px-2.5 py-1.5 bg-indigo-100 border border-indigo-200 rounded-lg text-sm font-semibold text-indigo-700 shadow-sm"
+ >
+ {mod}
+ </kbd>
+ ))}
+ <span className="text-indigo-400 font-medium">+</span>
+ <span className="px-2.5 py-1.5 border-2 border-dashed border-indigo-300 rounded-lg text-sm text-indigo-400">
+ key
+ </span>
+ </div>
+ ) : (
+ <p className="text-center text-gray-500">
+ Press any key or combination
+ </p>
+ )}
+
+ <p className="text-xs text-center text-gray-400">
+ {isMac ? "Try ⌘⇧K or ⌥Space" : "Try Ctrl+Shift+K or Alt+Space"}
+ </p>
+ </div>
+ ) : value ? (
+ <div className="flex flex-col items-center gap-2">
+ {hotkeyParts.length > 0 ? (
+ <div className="flex items-center justify-center gap-1.5">
+ {hotkeyParts.map((part, i) => (
+ <React.Fragment key={part}>
+ {i > 0 && (
+ <span className="text-gray-300 font-medium">+</span>
+ )}
+ <kbd className="px-3 py-2 bg-gray-100 border border-gray-200 rounded-lg text-base font-semibold text-gray-800 shadow-sm">
+ {part}
+ </kbd>
+ </React.Fragment>
+ ))}
+ </div>
+ ) : isGlobe ? (
+ <div className="flex items-center gap-2">
+ <kbd className="px-4 py-2 bg-gradient-to-b from-gray-50 to-gray-100 border border-gray-200 rounded-xl text-2xl shadow-sm">
+ 🌐
+ </kbd>
+ <span className="text-sm font-medium text-gray-600">
+ Globe/Fn
+ </span>
+ </div>
+ ) : (
+ <kbd className="px-5 py-3 bg-gradient-to-b from-gray-50 to-gray-100 border border-gray-200 rounded-xl text-xl font-bold text-gray-800 shadow-sm min-w-[60px] text-center">
+ {displayValue}
+ </kbd>
+ )}
- {isFocused && (
- <div className="absolute -bottom-6 left-0 right-0 text-center">
- <span className="text-xs text-indigo-600">
- {isMac ? "Try Cmd+Shift+K or any key" : "Try Ctrl+Shift+K or any key"}
- </span>
+ <p className="text-xs text-gray-400">Click to change</p>
+ </div>
+ ) : (
+ <div className="flex flex-col items-center gap-2 py-2">
+ <div className="flex items-center gap-2 text-gray-400">
+ <svg
+ className="w-5 h-5"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ >
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={1.5}
+ d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707"
+ />
+ </svg>
+ <span className="font-medium">Click to set hotkey</span>
+ </div>
+ </div>
+ )}
</div>
- )}
+ </div>
</div>
);
}
diff --git a/src/components/ui/Keyboard.tsx b/src/components/ui/Keyboard.tsx
deleted file mode 100644
index d7333db37..000000000
--- a/src/components/ui/Keyboard.tsx
+++ /dev/null
@@ -1,280 +0,0 @@
-import React, { useState, useEffect } from "react";
-import { formatHotkeyLabel } from "../../utils/hotkeys";
-
-interface KeyboardProps {
- selectedKey?: string;
- setSelectedKey: (key: string) => void;
-}
-
-interface KeyProps {
- keyValue: string;
- isSelected: boolean;
- onClick: () => void;
- width?: string;
- disabled?: boolean;
- displayValue?: React.ReactNode;
-}
-
-const Key: React.FC<KeyProps> = ({
- keyValue,
- isSelected,
- onClick,
- width = "w-12",
- disabled = false,
- displayValue,
-}) => {
- const [isPressed, setIsPressed] = useState(false);
-
- const handleClick = () => {
- if (disabled) return;
- setIsPressed(true);
- onClick();
- setTimeout(() => setIsPressed(false), 150);
- };
-
- return (
- <button
- onClick={handleClick}
- disabled={disabled}
- className={`
- ${width} h-12 rounded-lg font-mono text-sm font-medium
- transition-all duration-150 ease-in-out
- transform active:scale-95
- ${isPressed ? "translate-y-1 shadow-inner" : "translate-y-0 shadow-lg"}
- hover:translate-y-0.5 hover:shadow-md
- focus:outline-none focus:ring-2 focus:ring-indigo-300
- ${
- isSelected
- ? "bg-indigo-500 text-white border-2 border-indigo-600"
- : disabled
- ? "bg-gray-300 text-gray-500 cursor-not-allowed"
- : "bg-white text-gray-800 border-2 border-gray-300 hover:border-gray-400"
- }
- ${isPressed ? "bg-gray-100" : ""}
- `}
- >
- {displayValue ?? (keyValue === "Space" ? "" : keyValue)}
- </button>
- );
-};
-
-export default function Keyboard({ selectedKey, setSelectedKey }: KeyboardProps) {
- const isMac = typeof navigator !== "undefined" && /Mac|Darwin/.test(navigator.platform);
- const canUseGlobe = isMac;
- const functionKeys = [
- "Esc",
- "F1",
- "F2",
- "F3",
- "F4",
- "F5",
- "F6",
- "F7",
- "F8",
- "F9",
- "F10",
- "F11",
- "F12",
- ];
-
- const numberRow = ["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "="];
-
- const qwertyRow = ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "\\"];
-
- const asdfRow = ["A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'"];
-
- const zxcvRow = ["Z", "X", "C", "V", "B", "N", "M", ",", ".", "/"];
-
- const handleKeyClick = (key: string) => {
- setSelectedKey(key);
- };
-
- useEffect(() => {
- if (!canUseGlobe && selectedKey === "GLOBE") {
- setSelectedKey("`");
- }
- }, [canUseGlobe, selectedKey, setSelectedKey]);
-
- return (
- <div className="p-6 bg-gradient-to-b from-gray-100 to-gray-200 rounded-2xl shadow-2xl border border-gray-300">
- {/* Function Keys Row */}
- <div className="flex justify-center gap-2 mb-4">
- {functionKeys.map((key) => (
- <Key
- key={key}
- keyValue={key}
- isSelected={selectedKey === key}
- onClick={() => handleKeyClick(key)}
- width={key === "Esc" ? "w-14" : "w-12"}
- />
- ))}
- </div>
-
- {/* Number Row */}
- <div className="flex justify-center gap-1 mb-2">
- {numberRow.map((key) => (
- <Key
- key={key}
- keyValue={key}
- isSelected={selectedKey === key}
- onClick={() => handleKeyClick(key)}
- />
- ))}
- <Key
- keyValue="Backspace"
- isSelected={selectedKey === "Backspace"}
- onClick={() => handleKeyClick("Backspace")}
- width="w-20"
- disabled
- />
- </div>
-
- {/* QWERTY Row */}
- <div className="flex justify-center gap-1 mb-2">
- <Key
- keyValue="Tab"
- isSelected={selectedKey === "Tab"}
- onClick={() => handleKeyClick("Tab")}
- width="w-16"
- disabled
- />
- {qwertyRow.map((key) => (
- <Key
- key={key}
- keyValue={key}
- isSelected={selectedKey === key}
- onClick={() => handleKeyClick(key)}
- />
- ))}
- </div>
-
- {/* ASDF Row */}
- <div className="flex justify-center gap-1 mb-2">
- <Key
- keyValue="Caps"
- isSelected={selectedKey === "CapsLock"}
- onClick={() => handleKeyClick("CapsLock")}
- width="w-18"
- disabled
- />
- {asdfRow.map((key) => (
- <Key
- key={key}
- keyValue={key}
- isSelected={selectedKey === key}
- onClick={() => handleKeyClick(key)}
- />
- ))}
- <Key
- keyValue="Enter"
- isSelected={selectedKey === "Enter"}
- onClick={() => handleKeyClick("Enter")}
- width="w-20"
- disabled
- />
- </div>
-
- {/* ZXCV Row */}
- <div className="flex justify-center gap-1 mb-2">
- <Key
- keyValue="Shift"
- isSelected={selectedKey === "Shift"}
- onClick={() => handleKeyClick("Shift")}
- width="w-24"
- disabled
- />
- {zxcvRow.map((key) => (
- <Key
- key={key}
- keyValue={key}
- isSelected={selectedKey === key}
- onClick={() => handleKeyClick(key)}
- />
- ))}
- <Key
- keyValue="Shift"
- isSelected={false}
- onClick={() => handleKeyClick("Shift")}
- width="w-24"
- disabled
- />
- </div>
-
- {/* Bottom Row */}
- <div className="flex justify-center gap-1">
- <Key
- keyValue="Ctrl"
- isSelected={selectedKey === "Ctrl"}
- onClick={() => handleKeyClick("Ctrl")}
- width="w-16"
- disabled
- />
- {canUseGlobe ? (
- <Key
- keyValue="GLOBE"
- displayValue={
- <span role="img" aria-label="Globe">
- 🌐
- </span>
- }
- isSelected={selectedKey === "GLOBE"}
- onClick={() => handleKeyClick("GLOBE")}
- width="w-16"
- />
- ) : (
- <Key
- keyValue="Globe"
- displayValue={
- <span role="img" aria-label="Globe">
- 🌐
- </span>
- }
- isSelected={false}
- onClick={() => {}}
- width="w-16"
- disabled
- />
- )}
- <Key
- keyValue="Alt"
- isSelected={selectedKey === "Alt"}
- onClick={() => handleKeyClick("Alt")}
- width="w-16"
- disabled
- />
- <Key
- keyValue="Space"
- isSelected={selectedKey === "Space"}
- onClick={() => handleKeyClick("Space")}
- width="w-64"
- />
- <Key
- keyValue="Alt"
- isSelected={false}
- onClick={() => handleKeyClick("Alt")}
- width="w-16"
- disabled
- />
- <Key
- keyValue="Ctrl"
- isSelected={false}
- onClick={() => handleKeyClick("Ctrl")}
- width="w-16"
- disabled
- />
- </div>
-
- {/* Selected Key Display */}
- {selectedKey && (
- <div className="mt-6 text-center">
- <div className="inline-flex items-center px-4 py-2 bg-indigo-100 border-2 border-indigo-300 rounded-lg">
- <span className="text-sm text-indigo-700 mr-2">Selected:</span>
- <kbd className="px-3 py-1 bg-white border border-indigo-200 rounded font-mono text-lg font-semibold text-indigo-900">
- {formatHotkeyLabel(selectedKey)}
- </kbd>
- </div>
- </div>
- )}
- </div>
- );
-}
diff --git a/src/types/electron.ts b/src/types/electron.ts
index c6af4ead0..2cf03d4c3 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -261,6 +261,9 @@ declare global {
// Hotkey management
updateHotkey: (key: string) => Promise<{ success: boolean; message: string }>;
+ // Globe key listener for hotkey capture (macOS only)
+ onGlobeKeyPressed?: (callback: () => void) => () => void;
+
// Gemini API key management
getGeminiKey: () => Promise<string | null>;
saveGeminiKey: (key: string) => Promise<void>;
diff --git a/src/utils/hotkeys.ts b/src/utils/hotkeys.ts
index 5f7e32c86..0e03032c5 100644
--- a/src/utils/hotkeys.ts
+++ b/src/utils/hotkeys.ts
@@ -59,7 +59,7 @@ export function formatHotkeyLabel(hotkey?: string | null): string {
// Handle special GLOBE key for macOS
if (hotkey === "GLOBE") {
- return "Globe";
+ return "Globe/Fn";
}
// Handle compound hotkeys (contains "+")