diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index 8aea8c2bb..6e1bfff66 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed bug for linux in doctor in the event user doesn't have proper drivers installed. Added by [@pylotlight](https://github.com/pylotlight) in [PR](https://github.com/wailsapp/wails/pull/3032) - Fix dpi scaling on start up (windows). Changed by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3145) - Fix replace line in `go.mod` to use relative paths. Fixes Windows paths with spaces - @leaanthony. +- Fix MacOS systray click handling when no attached window by [thomas-senechal](https://github.com/thomas-senechal) in PR [#3207](https://github.com/wailsapp/wails/pull/3207) ### Changed diff --git a/v3/examples/hide-window/main.go b/v3/examples/hide-window/main.go index 0f6f259b2..d23ddec74 100644 --- a/v3/examples/hide-window/main.go +++ b/v3/examples/hide-window/main.go @@ -6,8 +6,8 @@ import ( "runtime" "github.com/wailsapp/wails/v3/pkg/application" - "github.com/wailsapp/wails/v3/pkg/icons" "github.com/wailsapp/wails/v3/pkg/events" + "github.com/wailsapp/wails/v3/pkg/icons" ) func main() { @@ -44,7 +44,6 @@ func main() { systemTray.SetTemplateIcon(icons.SystrayMacTemplate) } - // Click Dock icon tigger application show app.On(events.Mac.ApplicationShouldHandleReopen, func(event *application.Event) { println("reopen") @@ -62,7 +61,7 @@ func main() { systemTray.SetMenu(myMenu) systemTray.OnClick(func() { - app.CurrentWindow().Show() + window.Show() }) err := app.Run() diff --git a/v3/pkg/application/systemtray.go b/v3/pkg/application/systemtray.go index 052c930f5..38a35d32d 100644 --- a/v3/pkg/application/systemtray.go +++ b/v3/pkg/application/systemtray.go @@ -266,6 +266,7 @@ func (s *SystemTray) WindowDebounce(debounce time.Duration) *SystemTray { func (s *SystemTray) defaultClickHandler() { if s.attachedWindow.Window == nil { + s.OpenMenu() return } diff --git a/v3/pkg/application/systemtray_darwin.go b/v3/pkg/application/systemtray_darwin.go index 7ed0daaf9..76997d92a 100644 --- a/v3/pkg/application/systemtray_darwin.go +++ b/v3/pkg/application/systemtray_darwin.go @@ -142,14 +142,7 @@ func (s *macosSystemTray) run() { s.menu.Update() // Convert impl to macosMenu object s.nsMenu = (s.menu.impl).(*macosMenu).nsMenu - // We only set the tray menu if we don't have an attached - // window. If we do, then we manually operate the menu using - // the right mouse button - if s.parent.attachedWindow.Window == nil { - C.systemTraySetMenu(s.nsStatusItem, s.nsMenu) - } } - }) } diff --git a/v3/pkg/application/systemtray_darwin.h b/v3/pkg/application/systemtray_darwin.h index 50e6cee43..5bede00c8 100644 --- a/v3/pkg/application/systemtray_darwin.h +++ b/v3/pkg/application/systemtray_darwin.h @@ -12,7 +12,6 @@ void* createAttributedString(char *title, char *FG, char *BG); void* appendAttributedString(void* original, char* label, char* fg, char* bg); NSImage* imageFromBytes(const unsigned char *bytes, int length); void systemTraySetIcon(void* nsStatusItem, void* nsImage, int position, bool isTemplate); -void systemTraySetMenu(void* nsStatusItem, void* nsMenu); void systemTrayDestroy(void* nsStatusItem); void showMenu(void* nsStatusItem, void *nsMenu); void systemTrayGetBounds(void* nsStatusItem, NSRect *rect); diff --git a/v3/pkg/application/systemtray_darwin.m b/v3/pkg/application/systemtray_darwin.m index 2af2b9bfc..f24290a4e 100644 --- a/v3/pkg/application/systemtray_darwin.m +++ b/v3/pkg/application/systemtray_darwin.m @@ -130,16 +130,6 @@ void systemTraySetIcon(void* nsStatusItem, void* nsImage, int position, bool isT }); } -// Add menu to system tray -void systemTraySetMenu(void* nsStatusItem, void* nsMenu) { - // Set the menu on the main thread - dispatch_async(dispatch_get_main_queue(), ^{ - NSStatusItem *statusItem = (NSStatusItem *)nsStatusItem; - NSMenu *menu = (NSMenu *)nsMenu; - statusItem.menu = menu; - }); -} - // Destroy system tray void systemTrayDestroy(void* nsStatusItem) { // Remove the status item from the status bar and its associated menu