A Global Hotkey Is a State Boundary, Not a Shortcut

The most useful feature I shipped this year is a single shortcut: Ctrl+Alt+R (Cmd+Alt+R on macOS). Press it from anywhere on the desktop and Hobnob starts recording a meeting. No window to find, no click target, no "open the app first" step. The hard part was never the shortcut. It was deciding where the trigger lives in the architecture, and what it is allowed to do.

Hobnob is an Electron app. The recording pipeline is owned by the renderer: AudioContext captures the microphone, system audio comes in through a native tap, and IPC drives recording:start. A global shortcut, by contrast, is registered in the main process with globalShortcut, which has no access to the renderer's audio context. The naive design would be for the main process to start recording itself. That fails on the first boundary it hits, because the main process never holds the microphone stream. The renderer does, and the renderer may not even be mounted yet if the window is closed or hidden.

So the trigger is split into two halves. GlobalTriggerService in src/main/services/GlobalTriggerService.ts owns the shortcut registration, the tray icon, and the menu item "Record now". All it does when fired is call trigger(), which focuses the main window and sends an activation event over IPC. The renderer receives that event and runs the normal recording:start path it already owns. The trigger is a doorbell, not a recording engine. That separation is the whole design decision, and it is why the feature took a week instead of an afternoon: getting the main process to do nothing except wake the renderer meant re-examining every assumption about who owns the microphone.

The tray icon is the second half, and it is optional by design. resolveIconPath looks for tray/trayIcon.png in resources or the repo root; if it is missing, the tray is disabled and the shortcut still works. The constructor is wrapped so a headless environment, like CI, degrades to hotkey-only instead of throwing. That guard exists because the first test run on a Windows runner crashed the Tray constructor and masked a real regression in GlobalTriggerService.test.ts. The fix was to make the tray a capability the service probes for rather than a dependency it assumes. The test file now asserts both states: shortcut registered with tray visible, and shortcut registered with tray absent.

The settings side matters too. The shortcut is not always on. applySettings re-registers or unregisters the shortcut live when globalTriggerEnabled changes, and rebuilds the tray menu so "Record now" appears or disappears. No restart required. That constraint came from the first-run wizard flow: a user who disables the trigger during setup should see it stop immediately, and a user who re-enables it later should not have to relaunch the app. Live application costs more code than a restart prompt, but a restart prompt in a meeting tool is a missed recording.

What I would do differently: the shortcut is hardcoded to Control+Alt+R. There is no conflict resolution if another app already holds it; globalShortcut.register returns false and Hobnob logs a warning and stays silent. For a tool whose whole point is "press this from anywhere", a silently failing hotkey is a bad failure mode. The next version needs a settings field for the shortcut and a visible indicator when registration fails. That is the open question I am sitting with: should a failed registration surface as a notification, or should the app fall back to a different default and tell the user what changed?

The broader lesson: a global trigger sounds like a small feature. In an app where the recording engine lives in the renderer and the shortcut lives in the main process, it is a state-boundary problem dressed up as a hotkey. The fix was to keep the trigger dumb on purpose.