wails icon indicating copy to clipboard operation
wails copied to clipboard

The behavior of runtime.WindowUnminimise does not match the expectations.

Open superDingda opened this issue 1 year ago • 0 comments

Description

In the singleton mode of Wails, when I drag the window from position A to position B, then minimize the window, and subsequently trigger runtime.WindowUnminimise, the window returns to position A. The expected behavior is for the window to return to its position B before it was minimized.

To Reproduce


SingleInstanceLock: &options.SingleInstanceLock{
	UniqueId:               "TOOLCHAIN_GAD_UNIQUE_ID",
	OnSecondInstanceLaunch: app.onSecondInstanceLaunch,
},

func (a *App) onSecondInstanceLaunch(secondInstanceData options.SecondInstanceData) {
	if runtime.WindowIsMinimised(a.ctx) {
		runtime.WindowUnminimise(a.ctx)
	}

	runtime.Show(a.ctx)
	go runtime.EventsEmit(a.ctx, "launchArgs", secondInstanceData.Args)
}

Expected behaviour

In the singleton mode of Wails, when I drag the window from position A to position B, then minimize the window, and subsequently trigger runtime.WindowUnminimise, the window returns to position A. The expected behavior is for the window to return to its position B before it was minimized.

Screenshots

No response

Attempted Fixes

You can debug and use breakpoints to observe its behavior.


// in v2\internal\frontend\desktop\windows\winc\form.go :138 

func (fm *Form) Restore() {
	// SC_RESTORE param for WM_SYSCOMMAND to restore app if it is minimized
	const SC_RESTORE = 0xF120
	// restore the minimized window, if it is
	w32.SendMessage(                                   // Revert to the position and size before minimization.
		fm.hwnd,
		w32.WM_SYSCOMMAND,
		SC_RESTORE,
		0,
	)
	w32.ShowWindow(fm.hwnd, w32.SW_RESTORE) // Revert to the position and size from the previous session. 
}

suggestion:


func (fm *Form) Restore() {
	w32.ShowWindow(fm.hwnd, w32.SW_RESTORE)
}

I cannot understand why both SendMessage and ShowWindow are used, and both with RESTORE?

System Details

# Wails
Version | v2.9.2

# System
┌─────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | Windows 10 Enterprise                                                    |
| Version      | 2009 (Build: 22631)                                                      |
| ID           | 23H2                                                                     |
| Go Version   | go1.22.5                                                                 |
| Platform     | windows                                                                  |
| Architecture | amd64                                                                    |
| CPU          | 13th Gen Intel(R) Core(TM) i9-13900H                                     |
| GPU 1        | NVIDIA GeForce RTX 3050 4GB Laptop GPU (NVIDIA) - Driver: 31.0.15.2799   |
| GPU 2        | Intel(R) Iris(R) Xe Graphics (Intel Corporation) - Driver: 31.0.101.4575 |
| Memory       | 32GB                                                                     |
└─────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌───────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version       |
| WebView2   | N/A          | Installed | 129.0.2792.89 |
| Nodejs     | N/A          | Available |               |
| npm        | N/A          | Available |               |
| *upx       | N/A          | Available |               |
| *nsis      | N/A          | Available |               |
└─────────────── * - Optional Dependency ───────────────┘

Additional context

No response

superDingda avatar Oct 12 '24 02:10 superDingda