Overview
A Windows background tool I use daily: press a hotkey and it grabs whatever text you currently have selected, sends it to an LLM, and shows the result in a small popup - either a translation between Swedish and English (it detects which language automatically) or a list of synonyms. It lives in the system tray, works from a single always-ready window instead of opening a new one each time, and keeps working automatically after the computer wakes from sleep.
Architecture & Implementation
The entry point wires together a HotkeyManager with translation and synonym callbacks, then starts hotkey registration, a power-resume watcher, a Pause-key shutdown listener, and a system tray controller, each running on its own background thread.
Two global hotkeys - Win+Alt+V for translation and Win+Alt+S for synonyms - act on whatever text is currently selected on the desktop: the hotkey handler simulates a copy, reads the clipboard, and validates it (checking its type and enforcing a short maximum length) before sending anything to the LLM.
The results GUI is a singleton with a queue-driven event loop: rapid hotkey presses don't spawn overlapping windows, and background LLM results are marshalled back onto the Tk thread safely rather than touched directly from a worker thread. It shows the original input alongside a best result and up to seven alternates, each with one-click copy, and the LLM call itself runs on a background thread with retries so it never blocks the GUI.
Requests to the LLM go through LangChain prompt templates paired with a Pydantic output parser, so a translation or synonym request always comes back as structured JSON with an explicit best-choice field rather than free-form text that has to be parsed by hand.
A resume heuristic detects when Windows wakes from sleep or hibernate and automatically re-registers the hotkey hooks, since Windows silently drops them across a suspend cycle. Shutdown is handled the same way from any of its three triggers - the tray's quit option, the Pause key, or a process signal - through one centralized cleanup path.