Skip to content

Rust crate to detect if dark mode or light mode is enabled

Notifications You must be signed in to change notification settings

bbb651/rust-dark-light

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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::NoPreference => {},
    }
}

On platforms which make use of xdg-desktop-portals, by default this crate uses the dbus-send and dbus-monitor commands to avoid heavy dependencies. If you already depend on zbus or ashpd, you should enable the zbus feature.

Example

cargo run --example detect

License

Licensed under either of

at your option.

About

Rust crate to detect if dark mode or light mode is enabled

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%