This is a Node.js native module (Node-API/N-API) that monitors text selections across applications. It supports Windows, macOS, and Linux with platform-specific implementations.
npm run rebuild- Rebuild native module for current platformnpm run demo- Run demo/testnpm run prebuild- Prebuild all platformsnpm run typecheck- TypeScript type validationnpm run format- Format all C++ source files with clang-format
After modifying code, run the relevant checks:
- C++ code (
src/) →npm run rebuild&&npm run format index.jsorindex.d.ts→npm run typecheckpackage.json→npm install(to keeppackage-lock.jsonin sync)
index.js- Main Node.js wrapper class (SelectionHook) extending EventEmitterindex.d.ts- TypeScript definitionsbinding.gyp- Node-gyp build configuration (NAPI version 8, Node.js 18+, Electron 23+)
Each platform has selection_hook.cc/.mm (main implementation) and lib/ (utilities like clipboard, keyboard, utils):
src/windows/- UIAutomation for modern apps, Accessibility API for legacy apps, clipboard fallbacksrc/mac/- Accessibility API (AXAPI), clipboard fallbacksrc/linux/- X11 (Primary Selection viaprotocols/x11.cc), Wayland (viaprotocols/wayland.cc, in progress)
docs/- English documentation (API, Guide, Linux, Windows)docs/zh-CN/- Chinese documentation (mirrors English docs)README.md(English) /README.zh-CN.md(Chinese)
- Write all code comments in English
- Do not remove existing comments or printf statements unless explicitly instructed
- Ask permission before modifying files beyond the scope of the task
- Cross-platform implementations should use consistent function names, method names, and variable names across
src/windows/,src/mac/, andsrc/linux/unless they are platform-specific - Never attempt to
git addfiles that are listed in.gitignore, even with-f - Use only ASCII characters in source code files (including comments). Avoid non-ASCII characters like em-dash (
—), curly quotes, etc. to prevent MSVC C4819 warnings on non-Unicode code pages
When interfaces or behavior change, update all related files to keep everything consistent:
index.js/index.d.ts- JSDoc and TypeScript definitionsdocs/API.md- full API referencedocs/GUIDE.md- usage guidedocs/LINUX.md/docs/WINDOWS.md- platform documentationREADME.md- project overview and quick startexamples/node-demo.js- demo/example codebinding.gyp- build configuration (if adding/removing source files)
When updating documentation, keep English (docs/) and Chinese (docs/zh-CN/) versions in sync.
- Windows: Windows 11, PowerShell terminal
- macOS: macOS 15.5, Terminal
- Linux: Ubuntu 24.04, Terminal