Watching the Windows clipboard from Node.js without polling
Disclosure: I'm the developer of Bolo, the app this code comes from, and this post is published from my account. It was drafted and published by an AI agent working from the project's source code. Bolo has a small Windows companion written in Node.js. Its main job is to type at the PC cursor what you dictate on your Android phone. A second feature is two-way clipboard sync: copy on the PC and it…
A Node.js application, named Bolo, lets users dictate text on their Android phone, which is then typed at the PC cursor. The app syncs text between the PC and Android via a clipboard. Initially, the Windows PowerShell script sent clipboard text every two seconds, but this caused a server freeze due to process buildup.
To fix this, the code introduces an event-driven clipboard watcher in Windows, which listens for clipboard changes without timers or process creation. This avoids issues with RDP sessions being locked or disconnected. Additionally, the watcher ensures only one update is sent per copy, even if multiple clipboard events occur.
For sync operations, the code uses a one-shot read mechanism that only runs when explicitly requested by the user or the app. This prevents unnecessary process creation and timeouts. The solution also includes deduplication to prevent duplicate updates and a hard timeout to ensure safe execution. Overall, the changes improve the stability and efficiency of the clipboard syncing between the PC and Android device.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.