From 3efab5ba2354bc1feeaa5c5b670d5d2344245891 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 4 Jul 2023 20:01:06 +1000 Subject: [PATCH] [v3 windows] Prevent window close events when the window was just opened --- v3/pkg/application/webview_window_windows.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index 1eae2f96a..b24c0f391 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -61,6 +61,10 @@ type windowsWebviewWindow struct { // resizeBorder* is the width/height of the resize border in pixels. resizeBorderWidth int32 resizeBorderHeight int32 + + // Internal flag to prevent closing the window almost immediately after opening it. + // This happens when the window is opened after clicking a notification icon + justOpened bool } func (w *windowsWebviewWindow) setAbsolutePosition(x int, y int) { @@ -747,10 +751,18 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp if w.framelessWithDecorations() { w32.ExtendFrameIntoClientArea(w.hwnd, true) } + w.justOpened = true + go func() { + time.Sleep(100 * time.Millisecond) + w.justOpened = false + }() case w32.WM_CLOSE: w.parent.emit(events.Common.WindowClosing) return 0 case w32.WM_KILLFOCUS: + if w.justOpened { + return 0 + } w.parent.emit(events.Common.WindowLostFocus) case w32.WM_SETFOCUS: w.parent.emit(events.Common.WindowFocus)