diff --git a/.changes/window-close-no-op.md b/.changes/window-close-no-op.md new file mode 100644 index 000000000..3de7d7981 --- /dev/null +++ b/.changes/window-close-no-op.md @@ -0,0 +1,5 @@ +--- +wry: patch +--- + +Make `window.close` no-op since it would leave a broken window, and behavior is inconsistent between windows and apple platforms diff --git a/src/webkitgtk/mod.rs b/src/webkitgtk/mod.rs index 8232fadec..41bfa015f 100644 --- a/src/webkitgtk/mod.rs +++ b/src/webkitgtk/mod.rs @@ -441,8 +441,10 @@ impl InnerWebView { web_context: &mut WebContext, attributes: &mut WebViewAttributes, ) { - // window.close() - webview.connect_close(move |webview| unsafe { webview.destroy() }); + // Simply destroying the webview would leave blank window which is not good. + // TODO: we need to add api to register callback on `window.close` + // and ask user code if close the window, or just ignore `window.close`. + //webview.connect_close(move |webview| unsafe { webview.destroy() }); // Synthetic mouse events synthetic_mouse_events::setup(webview); diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index d3cf47dfd..342082e9e 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -576,11 +576,13 @@ impl InnerWebView { attributes: &mut WebViewAttributes, token: &mut EventRegistrationToken, ) -> Result<()> { - // Close container HWND when `window.close` is called in JS - webview.add_WindowCloseRequested( - &WindowCloseRequestedEventHandler::create(Box::new(move |_, _| DestroyWindow(hwnd))), - token, - )?; + // Simply destroying the hwnd would cause inconsistent window state so ignoring for now. + // TODO: we need to add api to register callback on `window.close` + // and ask user code if close the window, or just ignore `window.close`. + // webview.add_WindowCloseRequested( + // &WindowCloseRequestedEventHandler::create(Box::new(move |_, _| DestroyWindow(hwnd))), + // token, + // )?; // Document title changed handler if let Some(document_title_changed_handler) = attributes.document_title_changed_handler.take() {