Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2]Abnormal behavior when restoring a minimized Wails window on Windows. #4109

Open
superDingda opened this issue Mar 3, 2025 · 2 comments · May be fixed by #4110
Open

[v2]Abnormal behavior when restoring a minimized Wails window on Windows. #4109

superDingda opened this issue Mar 3, 2025 · 2 comments · May be fixed by #4110
Labels
Bug Something isn't working

Comments

@superDingda
Copy link

Description

After maximizing the window and minimizing it, waking it up through the singleton does not restore maximization. @leaanthony

To Reproduce

Create a single-instance maximized window.

func main() {
	// Create an instance of the app structure
	app := NewApp()

	// Create application with options
	err := wails.Run(&options.App{
		Title:            "wailstest",
		WindowStartState: options.Maximised,
		AssetServer: &assetserver.Options{
			Assets: assets,
		},
		BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
		OnStartup:        app.startup,
		SingleInstanceLock: &options.SingleInstanceLock{
			UniqueId:               "UNIQUE_ID",
			OnSecondInstanceLaunch: app.OnSecondInstanceLaunch,
		},
		Bind: []interface{}{
			app,
		},
	})

	if err != nil {
		println("Error:", err.Error())
	}
}
// App struct
type App struct {
	ctx context.Context
}

// NewApp creates a new App application struct
func NewApp() *App {
	return &App{}
}

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)
}

// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
	a.ctx = ctx
}

// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
	return fmt.Sprintf("Hello %s, It's show time!", name)
}

Expected behaviour

The window should be restored to maximized when awakened by the singleton.

Screenshots

20250303-190322.mp4

Attempted Fixes

https://github.com/wailsapp/wails/blob/master/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(
		fm.hwnd,
		w32.WM_SYSCOMMAND,
		SC_RESTORE,  // <- the window has already been restored here.
		0,
	)
	//w32.ShowWindow(fm.hwnd, w32.SW_RESTORE) 
	w32.ShowWindow(fm.hwnd, w32.SW_SHOW)  // <- use this
}

System Details

Wails Doctor          
                                


# Wails
Version | v2.9.2

# System
┌─────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | Windows 10 Enterprise                                                    |
| Version      | 2009 (Build: 22631)                                                      |
| ID           | 23H2                                                                     |
| Go Version   | go1.22.9                                                                 |
| 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                                                                     |
└─────────────────────────────────────────────────────────────────────────────────────────┘


# Diagnosis
Optional package(s) installation details:
  - upx : Available at https://upx.github.io/
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

 SUCCESS  Your system is ready for Wails development!

 ♥   If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony

Additional context

No response

@superDingda superDingda added the Bug Something isn't working label Mar 3, 2025
@leaanthony
Copy link
Member

leaanthony commented Mar 3, 2025

Are you saying w32.ShowWindow(fm.hwnd, w32.SW_SHOW) // <- use this fixes this? If so, please raise a PR 👍

superDingda pushed a commit to superDingda/wails that referenced this issue Mar 4, 2025
@superDingda
Copy link
Author

Are you saying w32.ShowWindow(fm.hwnd, w32.SW_SHOW) // <- use this fixes this? If so, please raise a PR 👍

Below is Microsoft's official description of the second parameter of ShowWindow. It states that SW_RESTORE restores the window to its original size and position when it is minimized, maximized, or arranged, which is the cause of this issue.

Value Meaning
SW_SHOW (5) Activates the window and displays it in its current size and position.
SW_RESTORE (9) Activates and displays the window. If the window is minimized, maximized, or arranged, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.

For more details, see: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants