7 releases (1 stable)
1.0.0 | Dec 25, 2022 |
---|---|
0.2.3 | Sep 18, 2022 |
0.2.2 | Apr 4, 2022 |
0.2.1 | Jan 21, 2022 |
0.1.1 | Feb 18, 2021 |
19,000 downloads per month
Used in 25 crates
(10 directly)
13KB
230 lines
rust-dark-light
Rust crate to detect if dark mode or light mode is enabled. Supports macOS, Windows, Linux, BSDs, and WASM. On Linux and BSDs, first the XDG Desktop Portal dbus API is checked for the color-scheme
preference, which works in Flatpak sandboxes without needing filesystem access. If that does not work, fallback methods are used for KDE, GNOME, Cinnamon, MATE, XFCE, and Unity.
Usage
fn main() {
let mode = dark_light::detect();
match mode {
// Dark mode
dark_light::Mode::Dark => {},
// Light mode
dark_light::Mode::Light => {},
// Unspecified
dark_light::Mode::Default => {},
}
}
Example
cargo run --example detect
lib.rs
:
Detect if dark mode or light mode is enabled.
Examples
let mode = dark_light::detect();
match mode {
// Dark mode
dark_light::Mode::Dark => {},
// Light mode
dark_light::Mode::Light => {},
// Unspecified
dark_light::Mode::Default => {},
}
Dependencies
~0–9.5MB
~166K SLoC