[v3 windows] Add close handling: HideOnClose, QuitOnLastWindowClosed and DisableQuitOnLastWindowClosed

This commit is contained in:
stffabi
2023-05-30 16:32:00 +08:00
committed by Misite Bao
parent fa74986f1e
commit ba150eccae
4 changed files with 13 additions and 6 deletions
+2 -2
View File
@@ -164,7 +164,7 @@ An 'X' indicates that the option is not supported by the platform.
| AlwaysOnTop | Y | | | |
| URL | | | | |
| DisableResize | Y | | | |
| Frameless | | | | |
| Frameless | Y | | | |
| MinWidth | Y | | | |
| MinHeight | Y | | | |
| MaxWidth | Y | | | |
@@ -178,7 +178,7 @@ An 'X' indicates that the option is not supported by the platform.
| CSS | | | | |
| X | | | | |
| Y | | | | |
| HideOnClose | | | | |
| HideOnClose | Y | | | |
| FullscreenButtonEnabled | | | | |
| Hidden | Y | | | |
| EnableFraudulentWebsiteWarnings | | | | |
+1 -1
View File
@@ -220,7 +220,7 @@ func (m *windowsApp) unregisterWindow(w *windowsWebviewWindow) {
delete(m.windowMap, w.hwnd)
// If this was the last window...
if len(m.windowMap) == 0 {
if len(m.windowMap) == 0 && !m.parent.options.Windows.DisableQuitOnLastWindowClosed {
w32.PostQuitMessage(0)
}
}
+3
View File
@@ -6,6 +6,9 @@ type WindowsApplicationOptions struct {
// If `shouldReturn` is `true` then `returnCode` will be returned by the main message loop.
// If `shouldReturn` is `false` then returnCode will be ignored and the message will be processed by the main message loop.
WndProcInterceptor func(hwnd uintptr, msg uint32, wParam, lParam uintptr) (returnCode uintptr, shouldReturn bool)
// DisableQuitOnLastWindowClosed disables the auto quit of the application if the last window has been closed.
DisableQuitOnLastWindowClosed bool
}
type BackdropType int32
+7 -3
View File
@@ -5,11 +5,12 @@ package application
import (
"errors"
"fmt"
"github.com/samber/lo"
"strconv"
"unicode/utf16"
"unsafe"
"github.com/samber/lo"
"github.com/wailsapp/wails/v3/pkg/events"
"github.com/wailsapp/wails/v3/pkg/w32"
)
@@ -609,11 +610,14 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp
case w32.WM_SIZE:
return 0
case w32.WM_CLOSE:
w32.PostMessage(w.hwnd, w32.WM_QUIT, 0, 0)
if w.parent.options.HideOnClose {
w.hide()
return 0 // Do not let the DefWindowProc allow to close us
}
// Unregister the window with the application
windowsApp := globalApplication.impl.(*windowsApp)
windowsApp.unregisterWindow(w)
return 0
case w32.WM_GETMINMAXINFO:
mmi := (*w32.MINMAXINFO)(unsafe.Pointer(lparam))
hasConstraints := false