From 10171931266c84e0afa310bb4da33d17cd5a917e Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sun, 22 Jun 2025 00:30:46 +0900 Subject: [PATCH 1/2] chore: make `window.close` no-op since it would leave a broken window --- src/webkitgtk/mod.rs | 6 ++++-- src/webview2/mod.rs | 12 +++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) 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() { From c0a5ac7a4a0406767d9d8ac530f782ddb1e7b17c Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sun, 22 Jun 2025 00:33:36 +0900 Subject: [PATCH 2/2] docs: Make `window.close` no-op since it would leave a broken window, and behavior is inconsistent between windows and apple platforms --- .changes/window-close-no-op.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/window-close-no-op.md 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