#mode #color-scheme #dark #light #themes #system #detect

dark-light

Detect if dark mode or light mode is enabled

10 releases (4 stable)

new 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

#47 in GUI

Download history 4848/week @ 2024-09-20 4992/week @ 2024-09-27 4146/week @ 2024-10-04 4222/week @ 2024-10-11 4551/week @ 2024-10-18 3876/week @ 2024-10-25 5274/week @ 2024-11-01 3389/week @ 2024-11-08 3607/week @ 2024-11-15 4205/week @ 2024-11-22 4770/week @ 2024-11-29 4993/week @ 2024-12-06 6241/week @ 2024-12-13 3151/week @ 2024-12-20 3113/week @ 2024-12-27 5495/week @ 2025-01-03

18,737 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–14MB
~180K SLoC