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

#41 in GUI

Download history 3584/week @ 2023-12-22 4839/week @ 2023-12-29 3857/week @ 2024-01-05 4002/week @ 2024-01-12 4191/week @ 2024-01-19 3896/week @ 2024-01-26 4580/week @ 2024-02-02 6888/week @ 2024-02-09 2069/week @ 2024-02-16 1255/week @ 2024-02-23 1229/week @ 2024-03-01 2204/week @ 2024-03-08 1680/week @ 2024-03-15 2500/week @ 2024-03-22 3493/week @ 2024-03-29 2309/week @ 2024-04-05

10,293 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–14MB
~156K SLoC