2026-03-13 14:41:42 +00:00
|
|
|
package lifecycle
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2026-03-31 16:14:19 +01:00
|
|
|
core "dappco.re/go/core"
|
2026-03-13 14:41:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Options struct{}
|
|
|
|
|
|
|
|
|
|
type Service struct {
|
|
|
|
|
*core.ServiceRuntime[Options]
|
|
|
|
|
platform Platform
|
|
|
|
|
cancels []func()
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 16:14:19 +01:00
|
|
|
func (s *Service) OnStartup(_ context.Context) core.Result {
|
2026-03-13 14:41:42 +00:00
|
|
|
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)
|
|
|
|
|
|
2026-03-31 16:14:19 +01:00
|
|
|
return core.Result{OK: true}
|
2026-03-13 14:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-31 16:14:19 +01:00
|
|
|
func (s *Service) OnShutdown(_ context.Context) core.Result {
|
2026-03-13 14:41:42 +00:00
|
|
|
for _, cancel := range s.cancels {
|
|
|
|
|
cancel()
|
|
|
|
|
}
|
|
|
|
|
s.cancels = nil
|
2026-03-31 16:14:19 +01:00
|
|
|
return core.Result{OK: true}
|
2026-03-13 14:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-31 16:14:19 +01:00
|
|
|
func (s *Service) HandleIPCEvents(_ *core.Core, _ core.Message) core.Result {
|
|
|
|
|
return core.Result{OK: true}
|
2026-03-13 14:41:42 +00:00
|
|
|
}
|