5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-16 17:09:28 +08:00

[v3 windows] Rename systray callback handlers

This commit is contained in:
Lea Anthony 2023-05-08 20:16:25 +10:00 committed by Misite Bao
parent 46a0d467c0
commit 6dd092c7a9
3 changed files with 37 additions and 24 deletions

View File

@ -17,6 +17,8 @@ func main() {
}, },
}) })
window := app.NewWebviewWindow().Hide()
systemTray := app.NewSystemTray() systemTray := app.NewSystemTray()
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
systemTray.SetIcon(application.DefaultMacTemplateIcon) systemTray.SetIcon(application.DefaultMacTemplateIcon)
@ -37,6 +39,10 @@ func main() {
systemTray.SetMenu(myMenu) systemTray.SetMenu(myMenu)
systemTray.OnClick(func() {
window.Show()
})
err := app.Run() err := app.Run()
if err != nil { if err != nil {

View File

@ -32,12 +32,12 @@ type SystemTray struct {
darkModeIcon []byte darkModeIcon []byte
iconPosition int iconPosition int
leftButtonClickHandler func() clickHandler func()
rightButtonClickHandler func() rightClickHandler func()
leftButtonDoubleClickHandler func() doubleClickHandler func()
rightButtonDoubleClickHandler func() rightDoubleClickHandler func()
mouseEnterHandler func() mouseEnterHandler func()
mouseLeaveHandler func() mouseLeaveHandler func()
// Platform specific implementation // Platform specific implementation
impl systemTrayImpl impl systemTrayImpl
@ -136,23 +136,23 @@ func (s *SystemTray) Destroy() {
s.impl.destroy() s.impl.destroy()
} }
func (s *SystemTray) OnLeftButtonClick(handler func()) *SystemTray { func (s *SystemTray) OnClick(handler func()) *SystemTray {
s.leftButtonClickHandler = handler s.clickHandler = handler
return s return s
} }
func (s *SystemTray) OnRightButtonClick(handler func()) *SystemTray { func (s *SystemTray) OnRightClick(handler func()) *SystemTray {
s.rightButtonClickHandler = handler s.rightClickHandler = handler
return s return s
} }
func (s *SystemTray) OnLeftButtonDoubleClick(handler func()) *SystemTray { func (s *SystemTray) OnDoubleClick(handler func()) *SystemTray {
s.leftButtonDoubleClickHandler = handler s.doubleClickHandler = handler
return s return s
} }
func (s *SystemTray) OnRightButtonDoubleClick(handler func()) *SystemTray { func (s *SystemTray) OnRightDoubleClick(handler func()) *SystemTray {
s.rightButtonDoubleClickHandler = handler s.rightDoubleClickHandler = handler
return s return s
} }

View File

@ -84,8 +84,15 @@ func (s *windowsSystemTray) run() {
// TODO: Set Menu // TODO: Set Menu
// Set Default Callbacks // Set Default Callbacks
s.parent.leftButtonClickHandler = func() { if s.parent.clickHandler == nil {
println("Left Button Clicked") s.parent.clickHandler = func() {
println("Left Button Clicked")
}
}
if s.parent.rightClickHandler == nil {
s.parent.rightClickHandler = func() {
//s.showMenu()
}
} }
// Update the icon // Update the icon
@ -176,20 +183,20 @@ func (s *windowsSystemTray) wndProc(msg uint32, wParam, lParam uintptr) uintptr
msg := lParam & 0xffff msg := lParam & 0xffff
switch msg { switch msg {
case w32.WM_LBUTTONUP: case w32.WM_LBUTTONUP:
if s.parent.leftButtonClickHandler != nil { if s.parent.clickHandler != nil {
s.parent.leftButtonClickHandler() s.parent.clickHandler()
} }
case w32.WM_RBUTTONUP: case w32.WM_RBUTTONUP:
if s.parent.rightButtonClickHandler != nil { if s.parent.rightClickHandler != nil {
s.parent.rightButtonClickHandler() s.parent.rightClickHandler()
} }
case w32.WM_LBUTTONDBLCLK: case w32.WM_LBUTTONDBLCLK:
if s.parent.leftButtonDoubleClickHandler != nil { if s.parent.doubleClickHandler != nil {
s.parent.leftButtonDoubleClickHandler() s.parent.doubleClickHandler()
} }
case w32.WM_RBUTTONDBLCLK: case w32.WM_RBUTTONDBLCLK:
if s.parent.rightButtonDoubleClickHandler != nil { if s.parent.rightDoubleClickHandler != nil {
s.parent.rightButtonDoubleClickHandler() s.parent.rightDoubleClickHandler()
} }
case 0x0406: case 0x0406:
if s.parent.mouseEnterHandler != nil { if s.parent.mouseEnterHandler != nil {