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

[V3/macos] Fix systray click handling when no attached window #3207

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mkdocs-website/docs/en/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions v3/examples/hide-window/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
Expand All @@ -62,7 +61,7 @@ func main() {

systemTray.SetMenu(myMenu)
systemTray.OnClick(func() {
app.CurrentWindow().Show()
window.Show()
})

err := app.Run()
Expand Down
1 change: 1 addition & 0 deletions v3/pkg/application/systemtray.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func (s *SystemTray) WindowDebounce(debounce time.Duration) *SystemTray {

func (s *SystemTray) defaultClickHandler() {
if s.attachedWindow.Window == nil {
s.OpenMenu()
return
}

Expand Down
7 changes: 0 additions & 7 deletions v3/pkg/application/systemtray_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

})
}

Expand Down
1 change: 0 additions & 1 deletion v3/pkg/application/systemtray_darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions v3/pkg/application/systemtray_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down