Fix enforced power listener on windows

This commit is contained in:
世界 2024-06-06 20:51:21 +08:00
parent e08c052fc9
commit 51964801ff
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -352,14 +352,6 @@ func NewRouter(
router.interfaceMonitor = interfaceMonitor
}
if runtime.GOOS == "windows" {
powerListener, err := winpowrprof.NewEventListener(router.notifyWindowsPowerEvent)
if err != nil {
return nil, E.Cause(err, "initialize power listener")
}
router.powerListener = powerListener
}
if ntpOptions.Enabled {
ntpDialer, err := dialer.New(router, ntpOptions.DialerOptions)
if err != nil {
@ -589,6 +581,15 @@ func (r *Router) Start() error {
}
}
if runtime.GOOS == "windows" {
powerListener, err := winpowrprof.NewEventListener(r.notifyWindowsPowerEvent)
if err == nil {
r.powerListener = powerListener
} else {
r.logger.Warn("initialize power listener: ", err)
}
}
if r.powerListener != nil {
monitor.Start("start power listener")
err := r.powerListener.Start()