mirror of
https://github.com/yewprint/yewprint
synced 2024-11-25 04:50:20 +00:00
Fix: do not auto-detect color scheme preference by default
This commit is contained in:
parent
04e071e419
commit
6061517742
2 changed files with 10 additions and 6 deletions
15
src/lib.rs
15
src/lib.rs
|
@ -193,16 +193,19 @@ pub struct Dark;
|
|||
impl Dark {
|
||||
pub fn with<T>(&self, f: impl FnOnce(&Cell<bool>) -> T) -> T {
|
||||
thread_local! {
|
||||
static DARK: Cell<bool> = {
|
||||
Cell::new(web_sys::window()
|
||||
.and_then(|x| x.match_media("(prefers-color-scheme: dark)").ok().flatten())
|
||||
.map(|x| x.matches())
|
||||
.unwrap_or(true))
|
||||
}
|
||||
static DARK: Cell<bool> = Cell::new(false);
|
||||
}
|
||||
DARK.with(f)
|
||||
}
|
||||
|
||||
pub fn auto_detect(&self) {
|
||||
let prefers_dark = web_sys::window()
|
||||
.and_then(|x| x.match_media("(prefers-color-scheme: dark)").ok().flatten())
|
||||
.map(|x| x.matches())
|
||||
.unwrap_or(true);
|
||||
self.set(prefers_dark);
|
||||
}
|
||||
|
||||
pub fn get(&self) -> bool {
|
||||
self.with(|x| x.get())
|
||||
}
|
||||
|
|
|
@ -145,6 +145,7 @@ pub fn run_app() -> Result<(), wasm_bindgen::JsValue> {
|
|||
#[cfg(feature = "console_error_panic_hook")]
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
yewprint::Dark.auto_detect();
|
||||
yew::Renderer::<app::AppRoot>::new().render();
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue