Skip to content

rust-dark-light/dark-light

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: