Stubs (15 files, 479 exports): - All managers: Dialog, Event, Browser, Clipboard, ContextMenu, Environment, Screen, KeyBinding - Window interface (~50 methods), BrowserWindow, platform options (iOS/Android) - MenuItem (42 roles), WebviewWindowOptions (full platform types) - Wails v3 submodule pinned at alpha 74 New events package (17th package): - Custom event system bridged to Core IPC - TaskEmit, TaskOn, TaskOff, QueryListeners, ActionEventFired Feature expansions: - Window: zoom, content (SetURL/SetHTML/ExecJS), bounds, print, flash - Screen: QueryCurrent, ScreenPlacement, Rect geometry - Dialog: typed tasks, file options, Info/Question/Warning/Error - Keybinding: TaskProcess, ErrorNotRegistered - Notification: RevokePermission, RegisterCategory, action broadcasts - Dock: SetProgressBar, Bounce/StopBounce - Environment: HasFocusFollowsMouse - ContextMenu: QueryGetAll, TaskUpdate, TaskDestroy Display bridge: 5 new event types wired to WebSocket MCP: 4 event tools (emit, on, off, list) 17 packages build and test clean (1 flaky test ordering issue in window). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
// pkg/screen/service.go
|
|
package screen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"forge.lthn.ai/core/go/pkg/core"
|
|
)
|
|
|
|
type Options struct{}
|
|
|
|
type Service struct {
|
|
*core.ServiceRuntime[Options]
|
|
platform Platform
|
|
}
|
|
|
|
// Register(p) binds the screen service to a Core instance.
|
|
// core.WithService(screen.Register(wailsScreen))
|
|
func Register(p Platform) func(*core.Core) (any, error) {
|
|
return func(c *core.Core) (any, error) {
|
|
return &Service{
|
|
ServiceRuntime: core.NewServiceRuntime[Options](c, Options{}),
|
|
platform: p,
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
func (s *Service) OnStartup(ctx context.Context) error {
|
|
s.Core().RegisterQuery(s.handleQuery)
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) HandleIPCEvents(c *core.Core, msg core.Message) error {
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) handleQuery(c *core.Core, q core.Query) (any, bool, error) {
|
|
switch q := q.(type) {
|
|
case QueryAll:
|
|
return s.platform.GetAll(), true, nil
|
|
case QueryPrimary:
|
|
return s.platform.GetPrimary(), true, nil
|
|
case QueryCurrent:
|
|
return s.platform.GetCurrent(), true, nil
|
|
case QueryByID:
|
|
return s.queryByID(q.ID), true, nil
|
|
case QueryAtPoint:
|
|
return s.queryAtPoint(q.X, q.Y), true, nil
|
|
case QueryWorkAreas:
|
|
return s.queryWorkAreas(), true, nil
|
|
default:
|
|
return nil, false, nil
|
|
}
|
|
}
|
|
|
|
func (s *Service) queryByID(id string) *Screen {
|
|
for _, scr := range s.platform.GetAll() {
|
|
if scr.ID == id {
|
|
return &scr
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) queryAtPoint(x, y int) *Screen {
|
|
for _, scr := range s.platform.GetAll() {
|
|
b := scr.Bounds
|
|
if x >= b.X && x < b.X+b.Width && y >= b.Y && y < b.Y+b.Height {
|
|
return &scr
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) queryWorkAreas() []Rect {
|
|
screens := s.platform.GetAll()
|
|
areas := make([]Rect, len(screens))
|
|
for i, scr := range screens {
|
|
areas[i] = scr.WorkArea
|
|
}
|
|
return areas
|
|
}
|