Some checks failed
Security Scan / security (push) Failing after 25s
- 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>
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
// pkg/clipboard/service.go
|
|
package clipboard
|
|
|
|
import (
|
|
"context"
|
|
|
|
core "dappco.re/go/core"
|
|
)
|
|
|
|
type Options struct{}
|
|
|
|
type Service struct {
|
|
*core.ServiceRuntime[Options]
|
|
platform Platform
|
|
}
|
|
|
|
// Register(p) binds the clipboard service to a Core instance.
|
|
// c.WithService(clipboard.Register(wailsClipboard))
|
|
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)
|
|
s.Core().Action("clipboard.setText", func(_ context.Context, opts core.Options) core.Result {
|
|
success := s.platform.SetText(opts.String("text"))
|
|
return core.Result{Value: success, OK: true}
|
|
})
|
|
s.Core().Action("clipboard.clear", func(_ context.Context, _ core.Options) core.Result {
|
|
success := s.platform.SetText("")
|
|
return core.Result{Value: success, OK: true}
|
|
})
|
|
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.(type) {
|
|
case QueryText:
|
|
text, ok := s.platform.Text()
|
|
return core.Result{Value: ClipboardContent{Text: text, HasContent: ok && text != ""}, OK: true}
|
|
default:
|
|
return core.Result{}
|
|
}
|
|
}
|