Files
magpie/internal/gui/minimised_windows.go
T
yetone 185ee6d5c1 gui: an auto restart brings a minimised main window back minimised on Windows (#3495, realLemonawa on X)
Settings' Auto restart after an update brought the main window back if
it was up, and on Windows a window minimised to the taskbar counts as
up, so the new version showed it on screen (quietly, without focus).
Now the old version notes whether it was minimised: the restart-quiet
mark reads "<seconds> minimised" (mainUp reads up and minimised
together on the main thread). The new version, on Windows, puts the
window straight onto the taskbar with SetWindowPlacement and
SW_SHOWMINNOACTIVE, never shown on screen and never activated, at its
kept place and size, with WPF_RESTORETOMAXIMIZED when it was maximised
(placeMain split into placeAt and the maximise). A mark of the seconds
alone, from an older version, still reads as a window up. A restart the
user clicked is unchanged.

The first auto update into this version is still made by the old one,
which doesn't write the word, so the window comes back minimised from
the update after it. macOS and Linux keep showing it quietly: #5926.

Run:
- Windows (xiaomi-gpu, in the signed-in console session through a
  one-shot schtasks /it, since the windows are real):
  TestRestartMinimisedComesBackMinimised, which starts the test binary
  as a Wails app three times: minimised, minimised and maximised, and
  shown. It checks the window comes back minimised, is never shown
  whole (WindowShow while not iconic), doesn't take the foreground,
  mainUp says up and minimised, and that SC_RESTORE brings it back
  (maximised when it was) with its page visible (the page reports
  document.visibilityState). PASS.
- Windows over ssh: go test -count=1 ./internal/gui/ fails only
  TestGatewayHeldByAContainer, TestPluginAgentMissingSaysSo (#5324),
  TestLodyImportHandoff, TestImportStatusUnreadableIsUnknown,
  TestUpdateThatWontStart (#4115, #1827) and TestProviderSaveClientCert
  (filed #5928); all six fail the same at origin/main 987eac0aa.
- mote (darwin): go test -count=1 ./internal/gui/ ok (166s); at the
  head rebased on 6b92824ff, the three vets and -run
  'Quiet|Restart|Lightweight|Main' ./internal/gui/ ok.
- gofmt clean; go vet darwin, GOOS=windows and GOOS=linux -tags nogui
  ./internal/gui/ ok (GOOS=linux with the GUI needs cgo and doesn't
  cross-compile from mote, on main too).

Broken by hand: showsMinimised false on Windows (the old show): the
two minimised cases red ("came back not minimised"). Without
WPF_RESTORETOMAXIMIZED: the maximised case red ("maximised=false, want
true"). Taking the minimised flag out of the mark is red in
TestRestartBySelfComesBackQuietly.

Not tried: a real update of the installed app on Windows (the
schtasks run drives the same openMain path the app's start takes); the
Windows test stays green with no show of our own after SC_RESTORE
(the restored page reports visible), so none was added.
2026-11-10 18:07:05 +08:00

50 lines
1.4 KiB
Go

//go:build windows && !nogui
package gui
import (
"unsafe"
"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/w32"
)
// showsMinimised: Windows can put a window not shown yet straight onto the
// taskbar, to restore at its place and size (#3495).
const showsMinimised = true
// wpfRestoreToMaximized is WINDOWPLACEMENT's WPF_RESTORETOMAXIMIZED: the
// window, restored from the taskbar, comes back maximised.
const wpfRestoreToMaximized = 0x0002
// showMinimised puts w, placed and not shown yet, onto the taskbar as a
// window minimised there: neither shown on screen nor activated, so the
// app the user is in keeps the keyboard. Wails' Show (SW_SHOW) would
// activate it. Restored, it comes back where it was put, maximised if
// maximise, its page shown (TestRestartMinimisedComesBackMinimised). On
// the main thread.
func showMinimised(w *application.WebviewWindow, maximise bool) {
hwnd := w32.HWND(uintptr(w.NativeWindow()))
wp := w32.WINDOWPLACEMENT{}
wp.Length = uint32(unsafe.Sizeof(wp))
if hwnd == 0 || !w32.GetWindowPlacement(hwnd, &wp) {
showHere(w, false) // shown quietly, as before #3495
if maximise {
w.Maximise()
}
return
}
wp.ShowCmd = w32.SW_SHOWMINNOACTIVE
if maximise {
wp.Flags |= wpfRestoreToMaximized
} else {
wp.Flags &^= wpfRestoreToMaximized
}
if !w32.SetWindowPlacement(hwnd, &wp) {
showHere(w, false)
if maximise {
w.Maximise()
}
}
}