|
2 | 2 |
|
3 | 3 | ## Project Overview |
4 | 4 |
|
5 | | -Cross-platform desktop system tray application for controlling monitor brightness, contrast, dark mode, and volume. Built with **Tauri v2** (Rust backend) + **React 18** (TypeScript frontend) + **Vite 6**. |
| 5 | +Cross-platform desktop system tray application for controlling monitor brightness, contrast, dark mode, volume, and keep-awake (sleep prevention). Built with **Tauri v2** (Rust backend) + **React 18** (TypeScript frontend) + **Vite 6**. |
6 | 6 |
|
7 | 7 | Display and dark mode operations are delegated to the [display-dj CLI](https://github.com/synle/display-dj-cli), which runs as a bundled HTTP server sidecar. The Tauri backend makes HTTP requests to it. Volume control remains platform-specific in Rust. |
8 | 8 |
|
@@ -30,15 +30,16 @@ cd src-tauri && cargo test # Run all Rust backend tests |
30 | 30 | ### Frontend Tests (Vitest + React Testing Library) |
31 | 31 |
|
32 | 32 | - **Setup**: `src/test/setup.ts` — Configures jsdom, jest-dom matchers, and Tauri API mocks |
33 | | -- **Unit tests**: `src/components/*.test.tsx` — Tests for each component (Header, Slider, DarkModeToggle, VolumeControl, AllMonitorsControl, MonitorControl) |
| 33 | +- **Unit tests**: `src/components/*.test.tsx` — Tests for each component (Header, Slider, DarkModeToggle, VolumeControl, AllMonitorsControl, MonitorControl, KeepAwakeToggle) |
34 | 34 | - **Smoke test**: `src/App.test.tsx` — Verifies App renders without errors, fetches initial data, handles backend failures gracefully |
35 | 35 | - Tauri `invoke()` and `listen()` are mocked globally in the test setup |
36 | 36 |
|
37 | 37 | ### Backend Tests (Rust) |
38 | 38 |
|
39 | | -- **Unit tests**: Inline `#[cfg(test)]` modules in `config.rs` and `display.rs` |
| 39 | +- **Unit tests**: Inline `#[cfg(test)]` modules in `config.rs`, `display.rs`, and `keep_awake.rs` |
40 | 40 | - `config.rs`: Serialization/deserialization, defaults, camelCase conventions, file roundtrips, CommandValue enum variants, MonitorMetadata serde, effective min brightness, backward-compatible deserialization of old configs, preferences with monitorConfigs roundtrip |
41 | 41 | - `display.rs`: `DjDisplay` to `Monitor` conversion (including uid computation), `merge_with_configs` (rename, sort), `reconcile_migrated_configs`, `ensure_metadata_for_monitors`, Monitor serde |
| 42 | + - `keep_awake.rs`: KeepAwake guard creation, Mutex<Option<KeepAwake>> pattern (enable/disable/re-enable) |
42 | 43 | - **Smoke test**: `src-tauri/tests/smoke.rs` — Integration test verifying the crate compiles, links, and public API (AppState, run) is accessible |
43 | 44 |
|
44 | 45 | ### CI |
@@ -76,14 +77,15 @@ These are documented inline in `config.rs` with WARNING comments. |
76 | 77 | - Preferences use `#[serde(default)]` so old config files missing new fields gracefully fall back to defaults |
77 | 78 | - Brightness values are clamped to `effective_min_brightness()` which enforces an absolute floor of 5 |
78 | 79 | - Contrast is DDC-only (`Option<u32>` / `number | null`): built-in displays return `null`. The contrast slider is hidden by default and toggled via the `showContrast` preference in Settings |
| 80 | +- Keep Awake uses the `keepawake` crate (v0.6) to prevent system idle sleep and display sleep. The guard is stored as `Mutex<Option<KeepAwake>>` in `AppState` — creating the guard enables keep-awake, dropping it (setting to `None`) releases the assertion. Works on macOS (IOKit), Windows (SetThreadExecutionState), and Linux (D-Bus). The `set_keep_awake` command is `async` to avoid the tray icon pitfall. |
79 | 81 |
|
80 | 82 | ## Related Projects |
81 | 83 |
|
82 | 84 | - **[display-dj-cli](https://github.com/synle/display-dj-cli)** — The Rust CLI/HTTP server that handles all display operations (brightness, contrast, dark mode). Bundled as a Tauri sidecar. Source at `/Users/syle/Downloads/display-dj-cli`. When bumping the sidecar version, always review upstream changes in that repo. |
83 | 85 |
|
84 | 86 | ## Dependencies |
85 | 87 |
|
86 | | -The display-dj CLI sidecar handles all platform-specific display dependencies internally. No external tools need to be installed for display control. |
| 88 | +The display-dj CLI sidecar handles all platform-specific display dependencies internally. No external tools need to be installed for display control. The `keepawake` crate handles sleep prevention natively on all platforms (macOS IOKit, Windows SetThreadExecutionState, Linux D-Bus). |
87 | 89 |
|
88 | 90 | ### Sidecar binaries |
89 | 91 |
|
|
0 commit comments