Add support for Window::theme on the web (#2687)
This commit is contained in:
parent
0f89aac9f6
commit
a31f71ee07
3 changed files with 16 additions and 2 deletions
|
|
@ -409,7 +409,20 @@ impl Window {
|
|||
|
||||
#[inline]
|
||||
pub fn theme(&self) -> Option<Theme> {
|
||||
None
|
||||
web_sys::window()
|
||||
.and_then(|window| {
|
||||
window
|
||||
.match_media("(prefers-color-scheme: dark)")
|
||||
.ok()
|
||||
.flatten()
|
||||
})
|
||||
.map(|media_query_list| {
|
||||
if media_query_list.matches() {
|
||||
Theme::Dark
|
||||
} else {
|
||||
Theme::Light
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue