Supports macOS, Windows, Linux, BSDs, and WebAssembly.
On Linux the XDG Desktop Portal D-Bus API is checked for the color-scheme preference, which works in Flatpak sandboxes without needing filesystem access.
Usage
Add to your project:
Detect current theme mode
You can detect the current mode by using the detect function. This function returns a Mode value.
React to theme changes
You can subscribe to theme changes by using the subscribe function. It returns a Watcher that yields a new Mode each time the OS theme changes.
On macOS, theme changes are currently detected by polling once per second rather than through a native notification, since the objc2 bindings this crate uses don't yet expose a safe way to observe NSDistributedNotificationCenter.
Async theme changes
With the default async-io feature (or tokio) enabled, stream returns a futures_core::Stream of Mode.
use StreamExt;
async
License
Licensed under either of the following licenses:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)