- Platform interface wrapping EventManager (Emit, On, Off, OnMultiple, Reset) - TaskEmit, TaskOn, TaskOff, QueryListeners IPC message types - ActionEventFired broadcast for agent consumption - Service with listener tracking and shutdown cleanup - 17 tests with Good/Bad/Ugly coverage Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
34 lines
1,006 B
Go
34 lines
1,006 B
Go
// pkg/events/platform.go
|
|
package events
|
|
|
|
// Platform abstracts the Wails EventManager for custom events.
|
|
//
|
|
// platform.Emit("user:login", userPayload)
|
|
// cancel := platform.On("theme:changed", func(e *CustomEvent) { applyTheme(e) })
|
|
// defer cancel()
|
|
type Platform interface {
|
|
Emit(name string, data ...any) bool
|
|
On(name string, callback func(*CustomEvent)) func()
|
|
Off(name string)
|
|
OnMultiple(name string, callback func(*CustomEvent), counter int)
|
|
Reset()
|
|
}
|
|
|
|
// CustomEvent is a named event carrying arbitrary data, mirroring the Wails type.
|
|
//
|
|
// platform.On("file:saved", func(e *CustomEvent) {
|
|
// path := e.Data.(string)
|
|
// })
|
|
type CustomEvent struct {
|
|
Name string `json:"name"`
|
|
Data any `json:"data"`
|
|
Sender string `json:"sender,omitempty"`
|
|
}
|
|
|
|
// ListenerInfo describes a registered listener for QueryListeners results.
|
|
//
|
|
// info := ListenerInfo{EventName: "user:login", Count: 3}
|
|
type ListenerInfo struct {
|
|
EventName string `json:"eventName"`
|
|
Count int `json:"count"`
|
|
}
|