2024-02-08 22:14:09 +08:00
|
|
|
package libbox
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type servicePauseFields struct {
|
|
|
|
pauseAccess sync.Mutex
|
|
|
|
pauseTimer *time.Timer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BoxService) Pause() {
|
|
|
|
s.pauseAccess.Lock()
|
|
|
|
defer s.pauseAccess.Unlock()
|
|
|
|
if s.pauseTimer != nil {
|
|
|
|
s.pauseTimer.Stop()
|
|
|
|
}
|
|
|
|
s.pauseTimer = time.AfterFunc(time.Minute, s.pause)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BoxService) pause() {
|
|
|
|
s.pauseAccess.Lock()
|
|
|
|
defer s.pauseAccess.Unlock()
|
|
|
|
s.pauseManager.DevicePause()
|
|
|
|
_ = s.instance.Router().ResetNetwork()
|
|
|
|
s.pauseTimer = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BoxService) Wake() {
|
2024-03-12 14:22:31 +08:00
|
|
|
_ = s.instance.Router().ResetNetwork()
|
2024-02-08 22:14:09 +08:00
|
|
|
s.pauseAccess.Lock()
|
|
|
|
defer s.pauseAccess.Unlock()
|
|
|
|
if s.pauseTimer != nil {
|
|
|
|
s.pauseTimer.Stop()
|
|
|
|
s.pauseTimer = nil
|
|
|
|
return
|
|
|
|
}
|
|
|
|
s.pauseManager.DeviceWake()
|
|
|
|
}
|