gui/pkg/events/platform.go
Claude dcd2c9bcb8
feat(events): new package — custom event system bridged to Core IPC
- 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>
2026-03-31 14:59:34 +01:00

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"`
}