From 7ef6f7d2b94bbf7d2e35c6233ea771900a660b99 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 11 Oct 2022 21:17:55 +1100 Subject: [PATCH] Fix bug in `runtime.Show()`. Tidy up debug. --- v2/examples/systray/frontend/dist/.gitkeep | 0 .../frontend/desktop/windows/frontend.go | 4 ++-- .../frontend/desktop/windows/win32/consts.go | 21 ++++++++++--------- .../frontend/desktop/windows/win32/window.go | 7 +++++++ v2/internal/platform/systray/windows.go | 1 - 5 files changed, 20 insertions(+), 13 deletions(-) delete mode 100644 v2/examples/systray/frontend/dist/.gitkeep diff --git a/v2/examples/systray/frontend/dist/.gitkeep b/v2/examples/systray/frontend/dist/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/v2/internal/frontend/desktop/windows/frontend.go b/v2/internal/frontend/desktop/windows/frontend.go index 59c3dcbdb..2d9d4c7ea 100644 --- a/v2/internal/frontend/desktop/windows/frontend.go +++ b/v2/internal/frontend/desktop/windows/frontend.go @@ -374,11 +374,11 @@ func (f *Frontend) ScreenGetAll() ([]Screen, error) { } func (f *Frontend) Show() { - f.mainWindow.Show() + f.WindowShow() } func (f *Frontend) Hide() { - f.mainWindow.Hide() + f.WindowHide() } func (f *Frontend) WindowIsMaximised() bool { diff --git a/v2/internal/frontend/desktop/windows/win32/consts.go b/v2/internal/frontend/desktop/windows/win32/consts.go index 6c6ba609c..e48bba3d9 100644 --- a/v2/internal/frontend/desktop/windows/win32/consts.go +++ b/v2/internal/frontend/desktop/windows/win32/consts.go @@ -13,20 +13,21 @@ type HANDLE uintptr type HMONITOR HANDLE var ( - moduser32 = syscall.NewLazyDLL("user32.dll") - procSystemParametersInfo = moduser32.NewProc("SystemParametersInfoW") - procGetWindowLong = moduser32.NewProc("GetWindowLongW") - procSetClassLong = moduser32.NewProc("SetClassLongW") - procSetClassLongPtr = moduser32.NewProc("SetClassLongPtrW") - procShowWindow = moduser32.NewProc("ShowWindow") - procIsWindowVisible = moduser32.NewProc("IsWindowVisible") - procGetWindowRect = moduser32.NewProc("GetWindowRect") - procGetMonitorInfo = moduser32.NewProc("GetMonitorInfoW") - procMonitorFromWindow = moduser32.NewProc("MonitorFromWindow") + moduser32 = syscall.NewLazyDLL("user32.dll") + procSystemParametersInfo = moduser32.NewProc("SystemParametersInfoW") + procGetWindowLong = moduser32.NewProc("GetWindowLongW") + procSetClassLong = moduser32.NewProc("SetClassLongW") + procSetClassLongPtr = moduser32.NewProc("SetClassLongPtrW") + procShowWindow = moduser32.NewProc("ShowWindow") + procIsWindowVisible = moduser32.NewProc("IsWindowVisible") + procGetWindowRect = moduser32.NewProc("GetWindowRect") + procGetMonitorInfo = moduser32.NewProc("GetMonitorInfoW") + procMonitorFromWindow = moduser32.NewProc("MonitorFromWindow") procLookupIconIdFromDirectoryEx = moduser32.NewProc("LookupIconIdFromDirectoryEx") procCreateIconFromResourceEx = moduser32.NewProc("CreateIconFromResourceEx") procCreateIconIndirect = moduser32.NewProc("CreateIconIndirect") procLoadImageW = moduser32.NewProc("LoadImageW") + procBringWindowToTop = moduser32.NewProc("BringWindowToTop") ) var ( diff --git a/v2/internal/frontend/desktop/windows/win32/window.go b/v2/internal/frontend/desktop/windows/win32/window.go index 1d6c9438c..ff6df5ec3 100644 --- a/v2/internal/frontend/desktop/windows/win32/window.go +++ b/v2/internal/frontend/desktop/windows/win32/window.go @@ -218,3 +218,10 @@ func GetMonitorInfo(hMonitor HMONITOR, lmpi *MONITORINFO) bool { ) return ret != 0 } + +func BringWindowToTop(hwnd uintptr) bool { + ret, _, _ := procBringWindowToTop.Call( + hwnd, + ) + return ret != 0 +} diff --git a/v2/internal/platform/systray/windows.go b/v2/internal/platform/systray/windows.go index 032067a13..3e2a1a873 100644 --- a/v2/internal/platform/systray/windows.go +++ b/v2/internal/platform/systray/windows.go @@ -314,7 +314,6 @@ func (p *Systray) Run() error { rt := win32.GetMessage(&msg) switch int(rt) { case 0: - println("Quitting Run()") return nil case -1: return errors.New("run failed")