Skip to content

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

@superDingda

Description

@superDingda

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions