10 releases (4 stable)

2.0.0 Jan 10, 2025
1.1.1 Apr 4, 2024
1.0.0 Dec 25, 2022
0.2.3 Sep 18, 2022
0.1.1 Feb 18, 2021

#38 in GUI

Download history 4021/week @ 2024-11-25 5292/week @ 2024-12-02 5507/week @ 2024-12-09 4998/week @ 2024-12-16 2814/week @ 2024-12-23 4236/week @ 2024-12-30 6792/week @ 2025-01-06 6891/week @ 2025-01-13 6164/week @ 2025-01-20 7450/week @ 2025-01-27 9206/week @ 2025-02-03 8067/week @ 2025-02-10 6629/week @ 2025-02-17 7223/week @ 2025-02-24 7191/week @ 2025-03-03 7245/week @ 2025-03-10

29,263 downloads per month
Used in 32 crates (18 directly)

MIT/Apache

16KB
196 lines

dark-light

Rust crate to detect the system theme mode

Crates.io Version Matrix

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.

API Documentation

Usage

Add to your project:

cargo add dark-light

Detect current theme mode

You can detect the current mode by using the detect function. This function returns a Mode value.

fn main() -> Result<(), dark_light::Error> {
    match dark_light::detect()? {
        dark_light::Mode::Dark => println!("Dark mode"),
        dark_light::Mode::Light => println!("Light mode"),
        dark_light::Mode::Unspecified => println!("Unspecified"),
    }
    Ok(())
}

License

Licensed under either of the following licenses:

Dependencies

~0–18MB
~203K SLoC