9 releases (3 stable)

1.1.1 Apr 4, 2024
1.1.0 Apr 3, 2024
1.0.0 Dec 25, 2022
0.2.3 Sep 18, 2022
0.1.1 Feb 18, 2021

#39 in GUI

Download history 2685/week @ 2024-02-15 1267/week @ 2024-02-22 1280/week @ 2024-02-29 2036/week @ 2024-03-07 1633/week @ 2024-03-14 2456/week @ 2024-03-21 3277/week @ 2024-03-28 2989/week @ 2024-04-04 2485/week @ 2024-04-11 2416/week @ 2024-04-18 2924/week @ 2024-04-25 3459/week @ 2024-05-02 2274/week @ 2024-05-09 2422/week @ 2024-05-16 2253/week @ 2024-05-23 2069/week @ 2024-05-30

9,579 downloads per month
Used in 25 crates (13 directly)

MIT/Apache

14KB
225 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.

API Documentation

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

License

Licensed under either of

at your option.

Dependencies

~0–13MB
~145K SLoC