platform: Ignore momentary pause on iOS

This commit is contained in:
世界 2024-02-08 22:14:09 +08:00
parent e2090923db
commit e6885e9967
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
2 changed files with 47 additions and 10 deletions

View File

@ -32,6 +32,8 @@ type BoxService struct {
instance *box.Box
pauseManager pause.Manager
urlTestHistoryStorage *urltest.HistoryStorage
servicePauseFields
}
func NewService(configContent string, platformInterface PlatformInterface) (*BoxService, error) {
@ -75,16 +77,6 @@ func (s *BoxService) Close() error {
return s.instance.Close()
}
func (s *BoxService) Sleep() {
s.pauseManager.DevicePause()
_ = s.instance.Router().ResetNetwork()
}
func (s *BoxService) Wake() {
s.pauseManager.DeviceWake()
_ = s.instance.Router().ResetNetwork()
}
var (
_ platform.Interface = (*platformInterfaceWrapper)(nil)
_ log.PlatformWriter = (*platformInterfaceWrapper)(nil)

View File

@ -0,0 +1,45 @@
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.pauseAccess.Lock()
defer s.pauseAccess.Unlock()
if s.pauseTimer != nil {
s.pauseTimer.Stop()
s.pauseTimer = nil
return
}
s.pauseManager.DeviceWake()
_ = s.instance.Router().ResetNetwork()
}