dark_light/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! This crate is designed to facilitate the development of applications that support both light and dark themes. It provides a simple API to detect the current theme mode.
//!
//! It supports macOS, Windows, Linux, BSDs, and WASM.
//!
//! On Linux the [XDG Desktop Portal](https://flatpak.github.io/xdg-desktop-portal/) D-Bus API is checked for the `color-scheme` preference, which works in Flatpak sandboxes without needing filesystem access.

mod error;
mod mode;
mod platforms;

pub use error::Error;
pub use mode::Mode;

/// Detects the system theme mode.
///
/// # Example
///
/// ``` no_run
/// use dark_light::{ Error, Mode };
///
/// fn main() -> Result<(), Error> {
///     let mode = dark_light::detect()?;
///     match mode {
///         Mode::Dark => {},
///         Mode::Light => {},
///         Mode::Unspecified => {},
///     }
///     Ok(())
/// }
/// ```
pub use platforms::platform::detect;