mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-19 02:19:31 +08:00
[V3/macos] Fix systray click handling when no attached window (#3207)
* Fix systray click handling * Open Menu if no window is attached in defaultClickHandler() * Remove systemTraySetMenu function * Fix a crash in hide-window example * Update changelog
This commit is contained in:
parent
dff47263d5
commit
44bbce125b
@ -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)
|
- 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 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 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
|
### Changed
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v3/pkg/application"
|
"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/events"
|
||||||
|
"github.com/wailsapp/wails/v3/pkg/icons"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -44,7 +44,6 @@ func main() {
|
|||||||
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
|
systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Click Dock icon tigger application show
|
// Click Dock icon tigger application show
|
||||||
app.On(events.Mac.ApplicationShouldHandleReopen, func(event *application.Event) {
|
app.On(events.Mac.ApplicationShouldHandleReopen, func(event *application.Event) {
|
||||||
println("reopen")
|
println("reopen")
|
||||||
@ -62,7 +61,7 @@ func main() {
|
|||||||
|
|
||||||
systemTray.SetMenu(myMenu)
|
systemTray.SetMenu(myMenu)
|
||||||
systemTray.OnClick(func() {
|
systemTray.OnClick(func() {
|
||||||
app.CurrentWindow().Show()
|
window.Show()
|
||||||
})
|
})
|
||||||
|
|
||||||
err := app.Run()
|
err := app.Run()
|
||||||
|
@ -266,6 +266,7 @@ func (s *SystemTray) WindowDebounce(debounce time.Duration) *SystemTray {
|
|||||||
|
|
||||||
func (s *SystemTray) defaultClickHandler() {
|
func (s *SystemTray) defaultClickHandler() {
|
||||||
if s.attachedWindow.Window == nil {
|
if s.attachedWindow.Window == nil {
|
||||||
|
s.OpenMenu()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,14 +142,7 @@ func (s *macosSystemTray) run() {
|
|||||||
s.menu.Update()
|
s.menu.Update()
|
||||||
// Convert impl to macosMenu object
|
// Convert impl to macosMenu object
|
||||||
s.nsMenu = (s.menu.impl).(*macosMenu).nsMenu
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ void* createAttributedString(char *title, char *FG, char *BG);
|
|||||||
void* appendAttributedString(void* original, char* label, char* fg, char* bg);
|
void* appendAttributedString(void* original, char* label, char* fg, char* bg);
|
||||||
NSImage* imageFromBytes(const unsigned char *bytes, int length);
|
NSImage* imageFromBytes(const unsigned char *bytes, int length);
|
||||||
void systemTraySetIcon(void* nsStatusItem, void* nsImage, int position, bool isTemplate);
|
void systemTraySetIcon(void* nsStatusItem, void* nsImage, int position, bool isTemplate);
|
||||||
void systemTraySetMenu(void* nsStatusItem, void* nsMenu);
|
|
||||||
void systemTrayDestroy(void* nsStatusItem);
|
void systemTrayDestroy(void* nsStatusItem);
|
||||||
void showMenu(void* nsStatusItem, void *nsMenu);
|
void showMenu(void* nsStatusItem, void *nsMenu);
|
||||||
void systemTrayGetBounds(void* nsStatusItem, NSRect *rect);
|
void systemTrayGetBounds(void* nsStatusItem, NSRect *rect);
|
||||||
|
@ -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
|
// Destroy system tray
|
||||||
void systemTrayDestroy(void* nsStatusItem) {
|
void systemTrayDestroy(void* nsStatusItem) {
|
||||||
// Remove the status item from the status bar and its associated menu
|
// Remove the status item from the status bar and its associated menu
|
||||||
|
Loading…
Reference in New Issue
Block a user