Files
2026-05-13 20:40:14 +08:00

43 lines
719 B
Go

package tray
import (
"context"
"errors"
)
const (
wmLeftButtonUp = 0x0202
wmLeftButtonDoubleClick = 0x0203
)
type Config struct {
Tooltip string
IconPath string
OnOpen func()
}
type Controller struct {
config Config
}
func Start(ctx context.Context, config Config) (func(), error) {
if config.OnOpen == nil {
return nil, errors.New("tray open handler is required")
}
return start(ctx, newController(config))
}
func newController(config Config) *Controller {
return &Controller{config: config}
}
func (c *Controller) handleTrayEvent(event uintptr) bool {
if event&0xffff != wmLeftButtonDoubleClick {
return false
}
if c.config.OnOpen != nil {
c.config.OnOpen()
}
return true
}