diff --git a/CHANGELOG.md b/CHANGELOG.md index b169fb0f39..8d5ac77143 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ And please only add new entries to the top of this list, right below the `# Unre - Implement `HasRawDisplayHandle` for `EventLoop`. - On macOS, set resize increments only for live resizes. - On Wayland, fix rare crash on DPI change +- Web: Added support for `Window::theme`. # 0.28.1 diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index e9fc26b7c0..a46a0b80c6 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -409,7 +409,20 @@ impl Window { #[inline] pub fn theme(&self) -> Option { - 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] diff --git a/src/window.rs b/src/window.rs index ba07ce7344..46bb3b8e8a 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1126,7 +1126,7 @@ impl Window { /// ## Platform-specific /// /// - **macOS:** This is an app-wide setting. - /// - **iOS / Android / Web / Wayland / x11 / Orbital:** Unsupported. + /// - **iOS / Android / Wayland / x11 / Orbital:** Unsupported. #[inline] pub fn theme(&self) -> Option { self.window.theme()