Bugfix: Better support for showing window

This commit is contained in:
Lea Anthony 2022-06-19 12:23:02 +10:00
commit a7f1ea21ef
4 changed files with 76 additions and 9 deletions

View file

@ -7,6 +7,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/win32"
"io"
"log"
"net/http"
@ -589,30 +590,54 @@ func (f *Frontend) navigationCompleted(sender *edge.ICoreWebView2, args *edge.IC
switch f.frontendOptions.WindowStartState {
case options.Maximised:
if !f.frontendOptions.DisableResize {
f.mainWindow.Maximise()
win32.ShowWindowMaximised(f.mainWindow.Handle())
} else {
f.mainWindow.Show()
win32.ShowWindow(f.mainWindow.Handle())
}
f.ShowWindow()
case options.Minimised:
f.mainWindow.Minimise()
win32.ShowWindowMinimised(f.mainWindow.Handle())
case options.Fullscreen:
f.mainWindow.Fullscreen()
f.ShowWindow()
win32.ShowWindow(f.mainWindow.Handle())
default:
if f.frontendOptions.Fullscreen {
f.mainWindow.Fullscreen()
}
f.ShowWindow()
win32.ShowWindow(f.mainWindow.Handle())
}
f.mainWindow.hasBeenShown = true
}
func (f *Frontend) ShowWindow() {
f.mainWindow.Invoke(func() {
if f.mainWindow.IsMinimised() {
f.mainWindow.Restore()
if !f.mainWindow.hasBeenShown {
f.mainWindow.hasBeenShown = true
switch f.frontendOptions.WindowStartState {
case options.Maximised:
if !f.frontendOptions.DisableResize {
win32.ShowWindowMaximised(f.mainWindow.Handle())
} else {
win32.ShowWindow(f.mainWindow.Handle())
}
case options.Minimised:
win32.RestoreWindow(f.mainWindow.Handle())
case options.Fullscreen:
f.mainWindow.Fullscreen()
win32.ShowWindow(f.mainWindow.Handle())
default:
if f.frontendOptions.Fullscreen {
f.mainWindow.Fullscreen()
}
win32.ShowWindow(f.mainWindow.Handle())
}
} else {
if win32.IsWindowMinimised(f.mainWindow.Handle()) {
win32.RestoreWindow(f.mainWindow.Handle())
} else {
win32.ShowWindow(f.mainWindow.Handle())
}
}
w32.SetForegroundWindow(f.mainWindow.Handle())
w32.SetFocus(f.mainWindow.Handle())

View file

@ -15,6 +15,7 @@ var (
moduser32 = syscall.NewLazyDLL("user32.dll")
procSystemParametersInfo = moduser32.NewProc("SystemParametersInfoW")
procGetWindowLong = moduser32.NewProc("GetWindowLongW")
procShowWindow = moduser32.NewProc("ShowWindow")
)
var (
moddwmapi = syscall.NewLazyDLL("dwmapi.dll")

View file

@ -16,6 +16,23 @@ const (
GWL_STYLE = -16
)
const (
SW_HIDE = 0
SW_NORMAL = 1
SW_SHOWNORMAL = 1
SW_SHOWMINIMIZED = 2
SW_MAXIMIZE = 3
SW_SHOWMAXIMIZED = 3
SW_SHOWNOACTIVATE = 4
SW_SHOW = 5
SW_MINIMIZE = 6
SW_SHOWMINNOACTIVE = 7
SW_SHOWNA = 8
SW_RESTORE = 9
SW_SHOWDEFAULT = 10
SW_FORCEMINIMIZE = 11
)
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb773244.aspx
type MARGINS struct {
CxLeftWidth, CxRightWidth, CyTopHeight, CyBottomHeight int32
@ -42,6 +59,21 @@ func IsWindowMinimised(hwnd uintptr) bool {
return style&WS_MINIMIZE != 0
}
func RestoreWindow(hwnd uintptr) {
showWindow(hwnd, SW_RESTORE)
}
func ShowWindow(hwnd uintptr) {
showWindow(hwnd, SW_SHOW)
}
func ShowWindowMaximised(hwnd uintptr) {
showWindow(hwnd, SW_MAXIMIZE)
}
func ShowWindowMinimised(hwnd uintptr) {
showWindow(hwnd, SW_MINIMIZE)
}
func dwmExtendFrameIntoClientArea(hwnd uintptr, margins *MARGINS) error {
ret, _, _ := procDwmExtendFrameIntoClientArea.Call(
hwnd,
@ -61,3 +93,11 @@ func getWindowLong(hwnd uintptr, index int) int32 {
return int32(ret)
}
func showWindow(hwnd uintptr, cmdshow int) bool {
ret, _, _ := procShowWindow.Call(
hwnd,
uintptr(cmdshow))
return ret != 0
}

View file

@ -22,6 +22,7 @@ type Window struct {
versionInfo *operatingsystem.WindowsVersionInfo
isDarkMode bool
isActive bool
hasBeenShown bool
}
func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *operatingsystem.WindowsVersionInfo) *Window {