wails/v3/pkg/application/events_common_darwin.go
Lea Anthony 35500c891e
fix(macos): Show hidden windows when dock icon is clicked (#4583) (#4790)
When an application starts with Hidden: true, clicking the dock icon
now correctly shows the window. This matches standard macOS UX where
clicking the dock icon should bring up the app's windows.

The fix adds a default handler for ApplicationShouldHandleReopen that
automatically shows all hidden windows when there are no visible windows.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-14 15:26:16 +11:00

36 lines
1.2 KiB
Go

//go:build darwin && !ios
package application
import "github.com/wailsapp/wails/v3/pkg/events"
var commonApplicationEventMap = map[events.ApplicationEventType]events.ApplicationEventType{
events.Mac.ApplicationDidFinishLaunching: events.Common.ApplicationStarted,
events.Mac.ApplicationDidChangeTheme: events.Common.ThemeChanged,
}
func (m *macosApp) setupCommonEvents() {
for sourceEvent, targetEvent := range commonApplicationEventMap {
sourceEvent := sourceEvent
targetEvent := targetEvent
m.parent.Event.OnApplicationEvent(sourceEvent, func(event *ApplicationEvent) {
event.Id = uint(targetEvent)
applicationEvents <- event
})
}
// Handle dock icon click (applicationShouldHandleReopen) to show windows
// when there are no visible windows. This provides the expected macOS UX
// where clicking the dock icon shows a hidden app's window.
// Issue #4583: Apps with StartHidden: true should show when dock icon is clicked.
m.parent.Event.OnApplicationEvent(events.Mac.ApplicationShouldHandleReopen, func(event *ApplicationEvent) {
if !event.Context().HasVisibleWindows() {
// Show all windows that are not visible
for _, window := range m.parent.Window.GetAll() {
if !window.IsVisible() {
window.Show()
}
}
}
})
}