Skip to content

Commit

Permalink
fix: devtool warning by adding parent view, closes #273 (#654)
Browse files Browse the repository at this point in the history
* 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 <wusyong9104@gmail.com>
  • Loading branch information
spwilson2 and Yu-Wei Wu committed Aug 9, 2022
1 parent 9fdcde3 commit 2eba8c9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2eba8c9

Please sign in to comment.