From 2eba8c9c26ff5f9512b0039ac04bc7fd27a5256f Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 9 Aug 2022 00:08:50 -0700 Subject: [PATCH] fix: devtool warning by adding parent view, closes #273 (#654) * fix: devtool warning by adding parent view, closes #273 Previously, we would just inject the webview into the contentView of the NSWindow. When devtools would inject the subView into this top-level content view, a warning would be displayed. * Move parent view to macOS only Co-authored-by: Yu-Wei Wu --- src/webview/wkwebview/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/webview/wkwebview/mod.rs b/src/webview/wkwebview/mod.rs index a5eec1357..c85511751 100644 --- a/src/webview/wkwebview/mod.rs +++ b/src/webview/wkwebview/mod.rs @@ -495,11 +495,22 @@ r#"Object.defineProperty(window, 'ipc', { // Inject the web view into the window as main content #[cfg(target_os = "macos")] { + // Create a view to contain the webview, without it devtools will try to + // inject a subview into the frame causing an obnoxious warning. + // See https://github.com/tauri-apps/wry/issues/273 + let parent_view: id = msg_send![class!(NSView), alloc]; + let _: () = msg_send![parent_view, init]; + parent_view.setAutoresizingMask_(NSViewHeightSizable | NSViewWidthSizable); + let _: () = msg_send![parent_view, addSubview: webview]; + // Tell the webview we use layers (macOS only) let _: () = msg_send![webview, setWantsLayer: YES]; // inject the webview into the window let ns_window = window.ns_window() as id; - let _: () = msg_send![ns_window, setContentView: webview]; + // NOTE: We ignore the fact that we may get back the existing view as we + // expect tao::Window to hold a handle to it and release it for us + // eventually. + let _: () = msg_send![ns_window, setContentView: parent_view]; // make sure the window is always on top when we create a new webview let app_class = class!(NSApplication);