mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-05-26 06:01:47 +03:00
Pause recurring tasks when no network
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/sagernet/sing-box"
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/common/process"
|
||||
"github.com/sagernet/sing-box/common/sleep"
|
||||
"github.com/sagernet/sing-box/common/urltest"
|
||||
"github.com/sagernet/sing-box/experimental/libbox/internal/procfs"
|
||||
"github.com/sagernet/sing-box/experimental/libbox/platform"
|
||||
@@ -21,13 +20,14 @@ import (
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
"github.com/sagernet/sing/service"
|
||||
"github.com/sagernet/sing/service/filemanager"
|
||||
"github.com/sagernet/sing/service/pause"
|
||||
)
|
||||
|
||||
type BoxService struct {
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
instance *box.Box
|
||||
sleepManager *sleep.Manager
|
||||
pauseManager pause.Manager
|
||||
}
|
||||
|
||||
func NewService(configContent string, platformInterface PlatformInterface) (*BoxService, error) {
|
||||
@@ -38,8 +38,8 @@ func NewService(configContent string, platformInterface PlatformInterface) (*Box
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx = filemanager.WithDefault(ctx, sWorkingPath, sTempPath, sUserID, sGroupID)
|
||||
ctx = service.ContextWithPtr(ctx, urltest.NewHistoryStorage())
|
||||
sleepManager := sleep.NewManager()
|
||||
ctx = service.ContextWithPtr(ctx, sleepManager)
|
||||
sleepManager := pause.NewDefaultManager(ctx)
|
||||
ctx = pause.ContextWithManager(ctx, sleepManager)
|
||||
instance, err := box.New(box.Options{
|
||||
Context: ctx,
|
||||
Options: options,
|
||||
@@ -53,7 +53,7 @@ func NewService(configContent string, platformInterface PlatformInterface) (*Box
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
instance: instance,
|
||||
sleepManager: sleepManager,
|
||||
pauseManager: sleepManager,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -67,12 +67,12 @@ func (s *BoxService) Close() error {
|
||||
}
|
||||
|
||||
func (s *BoxService) Sleep() {
|
||||
s.sleepManager.Sleep()
|
||||
s.pauseManager.DevicePause()
|
||||
_ = s.instance.Router().ResetNetwork()
|
||||
}
|
||||
|
||||
func (s *BoxService) Wake() {
|
||||
s.sleepManager.Wake()
|
||||
s.pauseManager.DeviceWake()
|
||||
}
|
||||
|
||||
var _ platform.Interface = (*platformInterfaceWrapper)(nil)
|
||||
|
||||
Reference in New Issue
Block a user