screen-wake-lock
Minimal cross-platform screen wake lock library.
Overview
This library provides a simple guard that prevents the display from entering idle/sleep mode while it remains alive. It supports Windows, macOS, and Linux.
Usage
use ScreenWakeLock;
// Acquire a wake lock
let lock = acquire?;
// Keep running...
// The screen will stay awake while the lock is alive
// Release the lock (also happens automatically when dropped)
drop;
Platform Support
- Windows: Uses
SetThreadExecutionStateAPI - macOS: Uses IOKit power management
- Linux: Uses D-Bus inhibitor service (requires a session bus)
Additional Features
- Check if wake lock is supported:
ScreenWakeLock::is_supported() - Linux-specific options:
ScreenWakeLock::acquire_with_linux_options()
Example