mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-11 07:55:34 +03:00
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
0d5835d133
commit
7a8d570db7
7
.changes/webview-theme.md
Normal file
7
.changes/webview-theme.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
"tauri": "patch"
|
||||
"tauri-runtime": "patch"
|
||||
"tauri-runtime-wry": "patch"
|
||||
---
|
||||
|
||||
On Windows, change webview theme based on Window theme for more accurate `prefers-color-scheme` support.
|
@ -13,7 +13,7 @@ exclude = [ "CHANGELOG.md", "/target" ]
|
||||
readme = "README.md"
|
||||
|
||||
[dependencies]
|
||||
wry = { git = "https://github.com/tauri-apps/wry", branch = "dev", default-features = false, features = [ "file-drop", "protocol" ] }
|
||||
wry = { git = "https://github.com/tauri-apps/wry", default-features = false, features = [ "file-drop", "protocol" ] }
|
||||
tauri-runtime = { version = "0.12.1", path = "../tauri-runtime" }
|
||||
tauri-utils = { version = "1.2.1", path = "../tauri-utils" }
|
||||
uuid = { version = "1", features = [ "v4" ] }
|
||||
|
@ -2851,6 +2851,19 @@ fn handle_event_loop<T: UserEvent>(
|
||||
}
|
||||
|
||||
match event {
|
||||
#[cfg(windows)]
|
||||
WryWindowEvent::ThemeChanged(theme) => {
|
||||
if let Some(window) = windows.borrow().get(&window_id) {
|
||||
if let Some(WindowHandle::Webview { inner, .. }) = &window.inner {
|
||||
let theme = match theme {
|
||||
WryTheme::Dark => wry::webview::Theme::Dark,
|
||||
WryTheme::Light => wry::webview::Theme::Light,
|
||||
_ => wry::webview::Theme::Light,
|
||||
};
|
||||
inner.set_theme(theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
WryWindowEvent::CloseRequested => {
|
||||
on_close_requested(callback, window_id, windows.clone());
|
||||
}
|
||||
@ -3025,6 +3038,9 @@ fn create_webview<T: UserEvent>(
|
||||
.with_drag_and_drop(webview_attributes.file_drop_handler_enabled);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
let window_theme = window_builder.inner.window.preferred_theme;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
if window_builder.tabbing_identifier.is_none()
|
||||
@ -3075,6 +3091,15 @@ fn create_webview<T: UserEvent>(
|
||||
webview_builder = webview_builder.with_additional_browser_args(&additional_browser_args);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
if let Some(theme) = window_theme {
|
||||
webview_builder = webview_builder.with_theme(match theme {
|
||||
WryTheme::Dark => wry::webview::Theme::Dark,
|
||||
WryTheme::Light => wry::webview::Theme::Light,
|
||||
_ => wry::webview::Theme::Light,
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(handler) = ipc_handler {
|
||||
webview_builder = webview_builder.with_ipc_handler(create_ipc_handler(
|
||||
context,
|
||||
|
Loading…
Reference in New Issue
Block a user