How nyannyn/drinkmorewater works
1. Project shape
- This is an Electron desktop app for Windows/Linux, not a web app.
- The app is split into a Node-based main process plus two renderer windows: a floating cup overlay and a settings/statistics window.
- The repository is small and intentionally layered around those boundaries: electron/ for app control, renderer/ for UI, build/ for icons and packaging assets.
2. Main process is the control plane
- electron/main.js is the central orchestrator.
- It owns the system tray, app lifecycle, reminder scheduling, system notifications, idle/power handling, and IPC routing.
- This is where the app decides when to show/hide the cup overlay, when to fire reminders, and when to pause/resume based on lock/sleep/idle events.
3. Two renderer windows with distinct roles
- renderer/cup.html + renderer/cup.js implement the transparent, always-on-top floating cup that appears only on reminder events.
- renderer/settings.html + renderer/settings.js implement the configuration and statistics UI.
- These windows do not directly manage app-wide state; they render state and emit user actions back to the main process.
4. Preload scripts define the trust boundary
- electron/preload-cup.js and electron/preload-settings.js expose a limited API into each renderer via contextBridge.
- This keeps the renderers isolated from raw Node/Electron access and makes the IPC boundary explicit.
- Architecturally, the preload scripts are the “adapter” layer between UI code and the privileged main process.
5. Persistent state lives outside the UI
- electron/store.js is the local data layer.
- The README indicates it replaces chrome.storage.local from the app’s Chrome-extension origin and persists to userData/data.json.
- This store likely holds reminder settings, daily/weekly drinking totals, enabled/disabled state, and other user preferences.
6. Primary data flow: reminder cycle
- Main process schedules a timer based on the selected interval.
- When the timer fires, it triggers both:
- the cup overlay in the renderer, and
- a native system notification.
- The cup window then handles the interaction loop: user holds 3 seconds or presses Space/Enter to record water intake, after which the main process/store are updated.
7. User interaction flow
- The tray icon is the app’s persistent entry point.
- Left-click opens settings/statistics; right-click exposes actions like open settings, test reminder, enable/disable reminders, and quit.
- The cup overlay supports drag/move behavior and focus-based keyboard shortcuts, so the renderer is responsible for visual interaction while the main process remains authoritative for state changes.
8. Idle/power behavior is part of the core logic
- The app pauses reminders when the system is locked or sleeping and resumes afterward.
- This is handled in the main process using Electron’s OS-level power/idle signals, which is important because reminder timing is tied to desktop state, not just elapsed wall-clock time.
9. Build and packaging
- package.json drives Electron startup and Electron Builder packaging for Windows and Linux.
- build/make-icons.js and build/icons/ support app/tray icon generation, especially the multi-size Linux icon set.
- .github/workflows/release.yml indicates automated release packaging from GitHub Actions.
10. Architecture summary for diagramming
- Think of the app as:
- Main process = scheduler, tray, notifications, persistence, OS integration
- Cup renderer = transient reminder UI and drink action capture
- Settings renderer = configuration and analytics display
- Store = local JSON persistence
- Preloads = safe IPC facade between privileged and unprivileged layers
- The main process is the hub; the renderers are clients; the store is the durable backend.
Main entry points: main.js Main process · cup.html Cup overlay · settings.html Settings window · preload-cup.js Cup preload
Components 12
Main process
Privileged Electron control plane and persistence layer.
- Main process · Owns tray, lifecycle, reminders, notifications, idle/power handling, and IPC routing.
electron/main.js - Store · Local data store for settings, totals, and reminder state.
electron/store.js - Cup preload · Exposes a limited API to the cup renderer via contextBridge.
electron/preload-cup.js - Settings preload · Exposes a limited API to the settings renderer via contextBridge.
electron/preload-settings.js
Renderers
Unprivileged UI windows for reminders and settings.
- Cup overlay · Transparent always-on-top floating cup shown for reminder events.
renderer/cup.html - Cup logic · Handles hold-to-drink, keyboard shortcuts, and overlay behavior.
renderer/cup.js - Settings window · Configuration and statistics interface for the app.
renderer/settings.html - Settings logic · Renders preferences and drinking statistics, emitting actions back to main.
renderer/settings.js
Build assets
Packaging, icon generation, and release assets.
- Icons · App and tray icon set used across platforms.
build/icons - Icon builder · Generates icon assets, especially the Linux multi-size set.
build/make-icons.js
Other components
- Package config · Electron startup and Electron Builder packaging configuration.
package.json - Release workflow · Automated packaging and release flow in GitHub Actions.
.github/workflows/release.yml
Connections 15
- Main process → Store: reads/writes · Persists reminder settings, totals, and app state.
- Main process → Cup preload: loads · Attaches the cup renderer preload to the overlay window.
- Main process → Settings preload: loads · Attaches the settings renderer preload to the settings window.
- Cup preload → Cup overlay: exposes API · Provides the cup window with a safe IPC surface.
- Settings preload → Settings window: exposes API · Provides the settings window with a safe IPC surface.
- Cup overlay → Cup logic: runs · HTML shell hosts the cup interaction code.
- Settings window → Settings logic: runs · HTML shell hosts the settings and statistics code.
- Main process → Cup overlay: shows on reminder · Opens the floating cup when the reminder timer fires.
- Main process → Settings window: opens · Shows the settings/statistics window from tray or app actions.
- Main process → Main process: schedules · Runs reminder timers and reacts to power/idle state changes.
- Main process → Store: updates intake · Records completed drinking actions and app counters.
- Main process → Icons: uses · Consumes app and tray icons at runtime and packaging time.
- Icon builder → Icons: generates · Build script produces the icon asset set.
- Package config → Main process: starts · Defines Electron entrypoint and packaging targets.
- Release workflow → Package config: packages · CI workflow builds distributable releases from the package configuration.