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>
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package lifecycle
|
|
|
|
import (
|
|
"context"
|
|
|
|
core "dappco.re/go/core"
|
|
)
|
|
|
|
type Options struct{}
|
|
|
|
type Service struct {
|
|
*core.ServiceRuntime[Options]
|
|
platform Platform
|
|
cancels []func()
|
|
}
|
|
|
|
func (s *Service) OnStartup(_ context.Context) core.Result {
|
|
eventActions := map[EventType]func(){
|
|
EventApplicationStarted: func() { _ = s.Core().ACTION(ActionApplicationStarted{}) },
|
|
EventWillTerminate: func() { _ = s.Core().ACTION(ActionWillTerminate{}) },
|
|
EventDidBecomeActive: func() { _ = s.Core().ACTION(ActionDidBecomeActive{}) },
|
|
EventDidResignActive: func() { _ = s.Core().ACTION(ActionDidResignActive{}) },
|
|
EventPowerStatusChanged: func() { _ = s.Core().ACTION(ActionPowerStatusChanged{}) },
|
|
EventSystemSuspend: func() { _ = s.Core().ACTION(ActionSystemSuspend{}) },
|
|
EventSystemResume: func() { _ = s.Core().ACTION(ActionSystemResume{}) },
|
|
}
|
|
|
|
for eventType, handler := range eventActions {
|
|
cancel := s.platform.OnApplicationEvent(eventType, handler)
|
|
s.cancels = append(s.cancels, cancel)
|
|
}
|
|
|
|
cancel := s.platform.OnOpenedWithFile(func(path string) {
|
|
_ = s.Core().ACTION(ActionOpenedWithFile{Path: path})
|
|
})
|
|
s.cancels = append(s.cancels, cancel)
|
|
|
|
return core.Result{OK: true}
|
|
}
|
|
|
|
func (s *Service) OnShutdown(_ context.Context) core.Result {
|
|
for _, cancel := range s.cancels {
|
|
cancel()
|
|
}
|
|
s.cancels = nil
|
|
return core.Result{OK: true}
|
|
}
|
|
|
|
func (s *Service) HandleIPCEvents(_ *core.Core, _ core.Message) core.Result {
|
|
return core.Result{OK: true}
|
|
}
|