How ruozhi67/waterctl_electron works
Waterctl is an Electron-enhanced Bluetooth controller for Chang Gong water-control devices. The user starts or ends a session in the renderer; the app connects over Web Bluetooth, exchanges protocol messages, handles authentication and device responses, and shows session status and a countdown. Electron automation and reconnect behavior are documented, but the Electron main/preload implementation was not excerpted, so those links are marked unverified. The PWA helper exists, but its activation in the renderer is commented out.
Main entry points: bluetooth.ts Bluetooth session · index.ts UI bootstrap · solvers.ts Authentication and commands · writeValueLogging.ts Write logging
Components 16
Renderer and session
- UI bootstrap
src/index.ts - Bluetooth session
src/bluetooth.ts
Device protocol
- Protocol payloads
src/payloads.ts - Authentication and commands
src/solvers.ts - Checksums
src/algorithms.ts - Key routine
src/deputy.wat
Session support
- Error handling
src/errors.ts - Session countdown
src/Countdown.ts - Debug log
src/logger.ts - Write logging
src/writeValueLogging.ts - Byte utilities
src/utils.ts
Electron and offline
- Electron automation
electron/main.ts - Renderer bridge
electron/preload.ts - PWA helpers
src/pwaHelper.ts
Other components
- User
- Water controller
Connections 19
- User → UI bootstrap: uses
README.md - UI bootstrap → Bluetooth session: registers click
src/index.ts - UI bootstrap → Write logging: loads
src/index.ts - UI bootstrap → Renderer bridge: calls bridge
src/index.ts - Bluetooth session → Water controller: connects and exchanges
src/bluetooth.ts - Bluetooth session → Protocol payloads: sends protocol messages
src/bluetooth.ts - Bluetooth session → Authentication and commands: builds responses
src/bluetooth.ts - Bluetooth session → Error handling: resolves failures
src/bluetooth.ts - Bluetooth session → Debug log: reads and clears logs
src/bluetooth.ts - Bluetooth session → Byte utilities: formats received bytes
src/bluetooth.ts - Bluetooth session → Session countdown: starts and stops
src/bluetooth.ts - Authentication and commands → Checksums: calculates checksums
src/solvers.ts - Authentication and commands → Byte utilities: converts values
src/solvers.ts - Authentication and commands → Key routine: uses key routine
src/solvers.ts - Write logging → Debug log: records writes
src/writeValueLogging.ts - Write logging → Byte utilities: formats writes
src/writeValueLogging.ts - Electron automation → Renderer bridge
- Electron automation → Bluetooth session: automates connection
- UI bootstrap → PWA helpers: optional PWA setup
src/index.ts