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>
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package menu
|
|
|
|
import (
|
|
"context"
|
|
|
|
core "dappco.re/go/core"
|
|
)
|
|
|
|
type Options struct{}
|
|
|
|
type Service struct {
|
|
*core.ServiceRuntime[Options]
|
|
manager *Manager
|
|
platform Platform
|
|
menuItems []MenuItem
|
|
showDevTools bool
|
|
}
|
|
|
|
func (s *Service) OnStartup(_ context.Context) core.Result {
|
|
r := s.Core().QUERY(QueryConfig{})
|
|
if r.OK {
|
|
if menuConfig, ok := r.Value.(map[string]any); ok {
|
|
s.applyConfig(menuConfig)
|
|
}
|
|
}
|
|
s.Core().RegisterQuery(s.handleQuery)
|
|
s.Core().Action("menu.setAppMenu", func(_ context.Context, opts core.Options) core.Result {
|
|
t, _ := opts.Get("task").Value.(TaskSetAppMenu)
|
|
s.menuItems = t.Items
|
|
s.manager.SetApplicationMenu(t.Items)
|
|
return core.Result{OK: true}
|
|
})
|
|
return core.Result{OK: true}
|
|
}
|
|
|
|
func (s *Service) applyConfig(configData map[string]any) {
|
|
if v, ok := configData["show_dev_tools"]; ok {
|
|
if show, ok := v.(bool); ok {
|
|
s.showDevTools = show
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *Service) ShowDevTools() bool {
|
|
return s.showDevTools
|
|
}
|
|
|
|
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 QueryGetAppMenu:
|
|
return core.Result{Value: s.menuItems, OK: true}
|
|
default:
|
|
return core.Result{}
|
|
}
|
|
}
|
|
|
|
func (s *Service) Manager() *Manager {
|
|
return s.manager
|
|
}
|