gui/pkg/screen/service.go
Claude 18a455b460
Some checks failed
Security Scan / security (push) Failing after 25s
refactor: migrate entire gui to Core v0.8.0 API
- Import paths: forge.lthn.ai/core/go → dappco.re/go/core
- Import paths: forge.lthn.ai/core/go-log → dappco.re/go/core/log
- Import paths: forge.lthn.ai/core/go-io → dappco.re/go/core/io
- RegisterTask → c.Action("name", handler) across all 15 services
- QueryHandler signature: (any, bool, error) → core.Result
- PERFORM(task) → Action.Run(ctx, opts)
- QUERY returns single core.Result (not 3 values)
- All 17 packages build and test clean on v0.8.0-alpha.1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 16:14:19 +01:00

82 lines
1.9 KiB
Go

// pkg/screen/service.go
package screen
import (
"context"
core "dappco.re/go/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) core.Result {
return func(c *core.Core) core.Result {
return core.Result{Value: &Service{
ServiceRuntime: core.NewServiceRuntime[Options](c, Options{}),
platform: p,
}, OK: true}
}
}
func (s *Service) OnStartup(_ context.Context) core.Result {
s.Core().RegisterQuery(s.handleQuery)
return core.Result{OK: true}
}
func (s *Service) HandleIPCEvents(_ *core.Core, _ core.Message) core.Result {
return core.Result{OK: true}
}
func (s *Service) handleQuery(_ *core.Core, q core.Query) core.Result {
switch q := q.(type) {
case QueryAll:
return core.Result{Value: s.platform.GetAll(), OK: true}
case QueryPrimary:
return core.Result{Value: s.platform.GetPrimary(), OK: true}
case QueryByID:
return core.Result{Value: s.queryByID(q.ID), OK: true}
case QueryAtPoint:
return core.Result{Value: s.queryAtPoint(q.X, q.Y), OK: true}
case QueryWorkAreas:
return core.Result{Value: s.queryWorkAreas(), OK: true}
case QueryCurrent:
return core.Result{Value: s.platform.GetCurrent(), OK: true}
default:
return core.Result{}
}
}
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
}