5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-20 10:59:30 +08:00

[V3-Linux] Systray OnClick on initial icon click (#3907)

Support linux systrays first click to open

- Convert event handling to switch statement for better readability
- Fix menu event handlers to properly trigger open/close callbacks
- Update click behavior to use doubleClickHandler for Activate

CHANGELOG.md
This commit is contained in:
Atterpac 2024-11-23 13:46:14 -07:00 committed by GitHub
parent abcc37f9a1
commit d27e75c57f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 8 deletions

View File

@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
in [#3888](https://github.com/wailsapp/wails/pull/3888)
### Changed
- Refactored systray click messaging to better align with user interactions by @atterpac in [#3907](https://github.com/wailsapp/wails/pull/3907)
- Asset embed to include `all:frontend/dist` to support frameworks that generate subfolders by @atterpac in [#3887](https://github.com/wailsapp/wails/pull/3887)
- Taskfile refactor by [leaanthony](https://github.com/leaanthony) in [#3748](https://github.com/wailsapp/wails/pull/3748)
- Upgrade to `go-webview2` v1.0.16 by [leaanthony](https://github.com/leaanthony)

View File

@ -92,6 +92,17 @@ func main() {
})
systemTray.SetMenu(myMenu)
systemTray.OnClick(func() {
println("System tray clicked!")
})
systemTray.OnDoubleClick(func() {
println("System tray double clicked!")
})
systemTray.OnRightClick(func() {
println("System tray right clicked!")
})
//systemTray.AttachWindow(window).WindowOffset(5)

0
v3/internal/dbus/generate.sh Normal file → Executable file
View File

View File

@ -421,7 +421,7 @@ func newSystemTrayImpl(s *SystemTray) systemTrayImpl {
}
func (s *linuxSystemTray) openMenu() {
// FIXME: Use DBUS to open?
// FIXME: Emit com.canonical to open?
globalApplication.info("systray error: openMenu not implemented on Linux")
}
@ -622,17 +622,19 @@ func (s *linuxSystemTray) GetProperty(id int32, name string) (value dbus.Variant
// Event is com.canonical.dbusmenu.Event method.
func (s *linuxSystemTray) Event(id int32, eventID string, data dbus.Variant, timestamp uint32) (err *dbus.Error) {
if eventID == "clicked" {
switch eventID {
case "clicked":
if item, ok := s.itemMap[id]; ok {
InvokeAsync(item.menuItem.handleClick)
}
}
if eventID == "opened" {
case "opened":
if s.parent.clickHandler != nil {
s.parent.clickHandler()
}
if s.parent.onMenuOpen != nil {
s.parent.onMenuOpen()
}
}
if eventID == "closed" {
case "closed":
if s.parent.onMenuClose != nil {
s.parent.onMenuClose()
}
@ -698,14 +700,16 @@ func (s *linuxSystemTray) GetLayout(parentID int32, recursionDepth int32, proper
// Activate implements org.kde.StatusNotifierItem.Activate method.
func (s *linuxSystemTray) Activate(x int32, y int32) (err *dbus.Error) {
s.parent.clickHandler()
if s.parent.doubleClickHandler != nil {
s.parent.doubleClickHandler()
}
return
}
// ContextMenu is org.kde.StatusNotifierItem.ContextMenu method
func (s *linuxSystemTray) ContextMenu(x int32, y int32) (err *dbus.Error) {
fmt.Println("ContextMenu", x, y)
return
return nil
}
func (s *linuxSystemTray) Scroll(delta int32, orientation string) (err *dbus.Error) {