Skip to main content

Module hotkeys

Module hotkeys 

Source
Expand description

Native global hotkeys (#150).

Lets the user bind OS-level global shortcuts to the same actions the CLI exposes (pause/resume, trigger/skip a break, cycle profile), so a break can be driven from the keyboard whether or not the Preferences window is focused. Bindings live in Settings (hotkeys_enabled + hotkeys) and are registered on the backend via tauri-plugin-global-shortcut, so they keep working with the window hidden — the renderer’s webview can’t be relied on for this.

The pure pieces — which bindings to register (registrable_bindings) and which profile a “cycle” lands on (next_profile_name) — are unit-tested here; the actual OS registration in apply_hotkeys is the thin, uncovered FFI shim.

Structs§

Hotkey
A single binding: an HotkeyAction and the accelerator that triggers it (tauri-plugin-global-shortcut syntax, e.g. "CmdOrCtrl+Alt+P"). An empty accelerator means the action is unbound.

Enums§

HotkeyAction
An action a global hotkey can fire. Mirrors the local CLI actions so a chord is just another route to the same behaviour (CLI parity).

Functions§

apply_hotkeys
(Re)register the enabled global shortcuts for the active settings, clearing any previously-registered ones first. Each binding is registered with its own handler that fires execute_hotkey_action on key-down.
execute_hotkey_action
Run the action a hotkey is bound to, going through the same scheduler entry points the CLI/IPC use so the two paths stay in lockstep. Pause and resume mirror the IPC handler’s pause-state writes; trigger/skip and the profile cycle reuse the shared command helpers.
next_profile_name
The profile that a “cycle profile” hotkey should switch to: the one after active in names, wrapping around to the first. None when there are no profiles or the active name isn’t found (nothing sensible to do). Pure so the wrap-around is unit-testable.
normalize_accelerator 🔒
Canonical form of an accelerator for conflict comparison: case-insensitive and modifier-order-insensitive. Mirrors the renderer’s normalizeAccelerator (src/lib/hotkeys.ts) so the in-app conflict warning and the backend’s conflict handling agree.
registrable_bindings
The bindings that should actually be registered with the OS: only when hotkeys are enabled, only entries with a non-blank accelerator, and only chords bound to exactly one action. A chord bound to two or more actions is dropped entirely (none of them fire) so behaviour is unambiguous and matches the conflict the renderer flags — rather than letting whichever action registers first silently win. Pure so the gating is unit-testable without touching the OS.