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

#46 in GUI

Download history 3170/week @ 2024-07-21 3758/week @ 2024-07-28 4264/week @ 2024-08-04 3476/week @ 2024-08-11 2652/week @ 2024-08-18 3162/week @ 2024-08-25 4242/week @ 2024-09-01 3864/week @ 2024-09-08 5454/week @ 2024-09-15 4041/week @ 2024-09-22 5506/week @ 2024-09-29 3643/week @ 2024-10-06 4370/week @ 2024-10-13 4271/week @ 2024-10-20 4546/week @ 2024-10-27 4491/week @ 2024-11-03

18,169 downloads per month
Used in 29 crates (16 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–12MB
~146K SLoC