mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 10:01:30 +00:00
platform: Ignore momentary pause on iOS
This commit is contained in:
parent
e2090923db
commit
e6885e9967
|
@ -32,6 +32,8 @@ type BoxService struct {
|
||||||
instance *box.Box
|
instance *box.Box
|
||||||
pauseManager pause.Manager
|
pauseManager pause.Manager
|
||||||
urlTestHistoryStorage *urltest.HistoryStorage
|
urlTestHistoryStorage *urltest.HistoryStorage
|
||||||
|
|
||||||
|
servicePauseFields
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(configContent string, platformInterface PlatformInterface) (*BoxService, error) {
|
func NewService(configContent string, platformInterface PlatformInterface) (*BoxService, error) {
|
||||||
|
@ -75,16 +77,6 @@ func (s *BoxService) Close() error {
|
||||||
return s.instance.Close()
|
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 (
|
var (
|
||||||
_ platform.Interface = (*platformInterfaceWrapper)(nil)
|
_ platform.Interface = (*platformInterfaceWrapper)(nil)
|
||||||
_ log.PlatformWriter = (*platformInterfaceWrapper)(nil)
|
_ log.PlatformWriter = (*platformInterfaceWrapper)(nil)
|
||||||
|
|
45
experimental/libbox/service_pause.go
Normal file
45
experimental/libbox/service_pause.go
Normal 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()
|
||||||
|
}
|
Loading…
Reference in a new issue