-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode.rs
31 lines (24 loc) · 860 Bytes
/
mode.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
use dioxus::prelude::*;
use crate::model::Mode;
pub fn use_mode_provider() {
let mut mode_signal = Signal::new(Mode::default());
#[cfg(not(target_os = "android"))]
spawn(async move {
use dioxus::desktop::tao::window::Theme;
use midoku_theme::prelude::*;
let window = dioxus::desktop::window();
let mut stream = midoku_theme::subscribe().await;
while let Some(mode) = stream.next().await {
mode_signal.set(mode.into());
match mode {
Mode::Dark => window.set_theme(Some(Theme::Dark)),
Mode::Light => window.set_theme(Some(Theme::Light)),
Mode::Unspecified => window.set_theme(None),
}
}
});
use_context_provider(|| mode_signal);
}
pub fn use_mode() -> Signal<Mode> {
use_context::<Signal<Mode>>()
}