mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 10:01:30 +00:00
41 lines
729 B
Go
41 lines
729 B
Go
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() {
|
|
_ = s.instance.Router().ResetNetwork()
|
|
s.pauseAccess.Lock()
|
|
defer s.pauseAccess.Unlock()
|
|
if s.pauseTimer != nil {
|
|
s.pauseTimer.Stop()
|
|
s.pauseTimer = nil
|
|
return
|
|
}
|
|
s.pauseManager.DeviceWake()
|
|
}
|