|
14 | 14 |
|
15 | 15 | use self::monitor::MonitorExt;
|
16 | 16 | use http::Request;
|
| 17 | +#[cfg(target_os = "macos")] |
| 18 | +use objc2::ClassType; |
17 | 19 | use raw_window_handle::{DisplayHandle, HasDisplayHandle, HasWindowHandle};
|
18 | 20 |
|
19 | 21 | use tauri_runtime::{
|
@@ -43,6 +45,8 @@ use webview2_com::{ContainsFullScreenElementChangedEventHandler, FocusChangedEve
|
43 | 45 | use windows::Win32::Foundation::HWND;
|
44 | 46 | #[cfg(target_os = "ios")]
|
45 | 47 | use wry::WebViewBuilderExtIos;
|
| 48 | +#[cfg(target_os = "macos")] |
| 49 | +use wry::WebViewBuilderExtMacos; |
46 | 50 | #[cfg(windows)]
|
47 | 51 | use wry::WebViewBuilderExtWindows;
|
48 | 52 | #[cfg(target_vendor = "apple")]
|
@@ -3777,6 +3781,7 @@ fn handle_user_message<T: UserEvent>(
|
3777 | 3781 | {
|
3778 | 3782 | f(Webview {
|
3779 | 3783 | controller: webview.controller(),
|
| 3784 | + environment: webview.environment(), |
3780 | 3785 | });
|
3781 | 3786 | }
|
3782 | 3787 | #[cfg(target_os = "android")]
|
@@ -3822,9 +3827,13 @@ fn handle_user_message<T: UserEvent>(
|
3822 | 3827 | }
|
3823 | 3828 | }
|
3824 | 3829 | Message::CreateWindow(window_id, handler) => match handler(event_loop) {
|
3825 |
| - Ok(webview) => { |
3826 |
| - windows.0.borrow_mut().insert(window_id, webview); |
3827 |
| - } |
| 3830 | + // wait for borrow_mut to be available - on Windows we might poll for the window to be inserted |
| 3831 | + Ok(webview) => loop { |
| 3832 | + if let Ok(mut windows) = windows.0.try_borrow_mut() { |
| 3833 | + windows.insert(window_id, webview); |
| 3834 | + break; |
| 3835 | + } |
| 3836 | + }, |
3828 | 3837 | Err(e) => {
|
3829 | 3838 | log::error!("{e}");
|
3830 | 3839 | }
|
@@ -4510,6 +4519,11 @@ You may have it installed on another user account, but it is not available for t
|
4510 | 4519 | .with_clipboard(webview_attributes.clipboard)
|
4511 | 4520 | .with_hotkeys_zoom(webview_attributes.zoom_hotkeys_enabled);
|
4512 | 4521 |
|
| 4522 | + #[cfg(target_os = "macos")] |
| 4523 | + if let Some(webview_configuration) = webview_attributes.webview_configuration { |
| 4524 | + webview_builder = webview_builder.with_webview_configuration(webview_configuration); |
| 4525 | + } |
| 4526 | + |
4513 | 4527 | #[cfg(any(target_os = "windows", target_os = "android"))]
|
4514 | 4528 | {
|
4515 | 4529 | webview_builder = webview_builder.with_https_scheme(webview_attributes.use_https_scheme);
|
@@ -4583,6 +4597,75 @@ You may have it installed on another user account, but it is not available for t
|
4583 | 4597 | });
|
4584 | 4598 | }
|
4585 | 4599 |
|
| 4600 | + if let Some(new_window_handler) = pending.new_window_handler { |
| 4601 | + #[cfg(desktop)] |
| 4602 | + let context = context.clone(); |
| 4603 | + webview_builder = webview_builder.with_new_window_req_handler(move |url, features| { |
| 4604 | + url |
| 4605 | + .parse() |
| 4606 | + .map(|url| { |
| 4607 | + let response = new_window_handler( |
| 4608 | + url, |
| 4609 | + tauri_runtime::webview::NewWindowFeatures::new( |
| 4610 | + features.size, |
| 4611 | + features.position, |
| 4612 | + tauri_runtime::webview::NewWindowOpener { |
| 4613 | + #[cfg(desktop)] |
| 4614 | + webview: features.opener.webview, |
| 4615 | + #[cfg(windows)] |
| 4616 | + environment: features.opener.environment, |
| 4617 | + #[cfg(target_os = "macos")] |
| 4618 | + target_configuration: features.opener.target_configuration, |
| 4619 | + }, |
| 4620 | + ), |
| 4621 | + ); |
| 4622 | + match response { |
| 4623 | + tauri_runtime::webview::NewWindowResponse::Allow => wry::NewWindowResponse::Allow, |
| 4624 | + #[cfg(desktop)] |
| 4625 | + tauri_runtime::webview::NewWindowResponse::Create { window_id } => { |
| 4626 | + let windows = &context.main_thread.windows.0; |
| 4627 | + let webview = loop { |
| 4628 | + if let Some(webview) = windows.try_borrow().ok().and_then(|windows| { |
| 4629 | + windows |
| 4630 | + .get(&window_id) |
| 4631 | + .map(|window| window.webviews.first().unwrap().clone()) |
| 4632 | + }) { |
| 4633 | + break webview; |
| 4634 | + } else { |
| 4635 | + // on Windows the window is created async so we should wait for it to be available |
| 4636 | + std::thread::sleep(std::time::Duration::from_millis(50)); |
| 4637 | + continue; |
| 4638 | + }; |
| 4639 | + }; |
| 4640 | + |
| 4641 | + #[cfg(desktop)] |
| 4642 | + wry::NewWindowResponse::Create { |
| 4643 | + #[cfg(target_os = "macos")] |
| 4644 | + webview: wry::WebViewExtMacOS::webview(&*webview).as_super().into(), |
| 4645 | + #[cfg(any( |
| 4646 | + target_os = "linux", |
| 4647 | + target_os = "dragonfly", |
| 4648 | + target_os = "freebsd", |
| 4649 | + target_os = "netbsd", |
| 4650 | + target_os = "openbsd", |
| 4651 | + ))] |
| 4652 | + webview: webview.webview(), |
| 4653 | + #[cfg(windows)] |
| 4654 | + webview: webview.webview(), |
| 4655 | + } |
| 4656 | + } |
| 4657 | + tauri_runtime::webview::NewWindowResponse::Deny => wry::NewWindowResponse::Deny, |
| 4658 | + } |
| 4659 | + }) |
| 4660 | + .unwrap_or(wry::NewWindowResponse::Deny) |
| 4661 | + }); |
| 4662 | + } |
| 4663 | + |
| 4664 | + if let Some(document_title_changed_handler) = pending.document_title_changed_handler { |
| 4665 | + webview_builder = |
| 4666 | + webview_builder.with_document_title_changed_handler(document_title_changed_handler) |
| 4667 | + } |
| 4668 | + |
4586 | 4669 | let webview_bounds = if let Some(bounds) = webview_attributes.bounds {
|
4587 | 4670 | let bounds: RectWrapper = bounds.into();
|
4588 | 4671 | let bounds = bounds.0;
|
@@ -4672,6 +4755,10 @@ You may have it installed on another user account, but it is not available for t
|
4672 | 4755 | webview_builder = webview_builder.with_additional_browser_args(&additional_browser_args);
|
4673 | 4756 | }
|
4674 | 4757 |
|
| 4758 | + if let Some(environment) = webview_attributes.environment { |
| 4759 | + webview_builder = webview_builder.with_environment(environment); |
| 4760 | + } |
| 4761 | + |
4675 | 4762 | webview_builder = webview_builder.with_theme(match window.theme() {
|
4676 | 4763 | TaoTheme::Dark => wry::Theme::Dark,
|
4677 | 4764 | TaoTheme::Light => wry::Theme::Light,
|
@@ -4699,6 +4786,19 @@ You may have it installed on another user account, but it is not available for t
|
4699 | 4786 | }
|
4700 | 4787 | }
|
4701 | 4788 |
|
| 4789 | + #[cfg(any( |
| 4790 | + target_os = "linux", |
| 4791 | + target_os = "dragonfly", |
| 4792 | + target_os = "freebsd", |
| 4793 | + target_os = "netbsd", |
| 4794 | + target_os = "openbsd" |
| 4795 | + ))] |
| 4796 | + { |
| 4797 | + if let Some(related_view) = webview_attributes.related_view { |
| 4798 | + webview_builder = webview_builder.with_related_view(related_view); |
| 4799 | + } |
| 4800 | + } |
| 4801 | + |
4702 | 4802 | #[cfg(any(target_os = "macos", target_os = "ios"))]
|
4703 | 4803 | {
|
4704 | 4804 | if let Some(data_store_identifier) = &webview_attributes.data_store_identifier {
|
|
0 commit comments