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

#42 in GUI

Download history 3568/week @ 2024-10-08 4628/week @ 2024-10-15 4103/week @ 2024-10-22 5033/week @ 2024-10-29 4218/week @ 2024-11-05 3535/week @ 2024-11-12 3893/week @ 2024-11-19 4200/week @ 2024-11-26 5122/week @ 2024-12-03 5730/week @ 2024-12-10 4620/week @ 2024-12-17 2682/week @ 2024-12-24 5325/week @ 2024-12-31 5986/week @ 2025-01-07 7187/week @ 2025-01-14 5197/week @ 2025-01-21

24,140 downloads per month
Used in 30 crates (16 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
~190K SLoC