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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! 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.
pub use Error;
pub use Mode;
pub use Watcher;
/// 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 detect;
/// Subscribes to changes in the system theme mode.
///
/// Returns a [`Watcher`] that receives a new [`Mode`] each time the OS theme changes.
/// Only mode transitions are emitted, and the watcher's background thread (where used)
/// stops when the `Watcher` is dropped.
///
/// # Example
///
/// ``` no_run
/// use dark_light::{ Error, Mode };
///
/// fn main() -> Result<(), Error> {
/// let watcher = dark_light::subscribe()?;
/// for mode in watcher.iter() {
/// match mode {
/// Mode::Dark => {},
/// Mode::Light => {},
/// Mode::Unspecified => {},
/// }
/// }
/// Ok(())
/// }
/// ```
pub use subscribe;
/// Subscribes to changes in the system theme mode using an async stream.
///
/// Returns a [`Stream`] that yields a new [`Mode`] each time the OS theme changes.
///
/// # Example
///
/// ``` no_run
/// use dark_light::{ Error, Mode };
/// use futures_util::StreamExt;
///
/// fn main() -> Result<(), Error> {
/// futures_executor::block_on(async {
/// let mut stream = dark_light::stream()?;
/// while let Some(mode) = stream.next().await {
/// match mode {
/// Mode::Dark => {},
/// Mode::Light => {},
/// Mode::Unspecified => {},
/// }
/// }
/// Ok(())
/// })
/// }
/// ```
pub use stream;