mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 05:21:31 +11:00
Add support for Window::theme
on the web (#2687)
This commit is contained in:
parent
0f89aac9f6
commit
a31f71ee07
|
@ -11,6 +11,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
- Implement `HasRawDisplayHandle` for `EventLoop`.
|
- Implement `HasRawDisplayHandle` for `EventLoop`.
|
||||||
- On macOS, set resize increments only for live resizes.
|
- On macOS, set resize increments only for live resizes.
|
||||||
- On Wayland, fix rare crash on DPI change
|
- On Wayland, fix rare crash on DPI change
|
||||||
|
- Web: Added support for `Window::theme`.
|
||||||
|
|
||||||
# 0.28.1
|
# 0.28.1
|
||||||
|
|
||||||
|
|
|
@ -409,7 +409,20 @@ impl Window {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn theme(&self) -> Option<Theme> {
|
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]
|
#[inline]
|
||||||
|
|
|
@ -1126,7 +1126,7 @@ impl Window {
|
||||||
/// ## Platform-specific
|
/// ## Platform-specific
|
||||||
///
|
///
|
||||||
/// - **macOS:** This is an app-wide setting.
|
/// - **macOS:** This is an app-wide setting.
|
||||||
/// - **iOS / Android / Web / Wayland / x11 / Orbital:** Unsupported.
|
/// - **iOS / Android / Wayland / x11 / Orbital:** Unsupported.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn theme(&self) -> Option<Theme> {
|
pub fn theme(&self) -> Option<Theme> {
|
||||||
self.window.theme()
|
self.window.theme()
|
||||||
|
|
Loading…
Reference in a new issue