diff --git a/service/pause/context.go b/service/pause/context.go index 9baeded..b83e01c 100644 --- a/service/pause/context.go +++ b/service/pause/context.go @@ -6,17 +6,17 @@ import ( "github.com/sagernet/sing/service" ) +// Deprecated: use service.ContextWith instead. func ManagerFromContext(ctx context.Context) Manager { return service.FromContext[Manager](ctx) } +// Deprecated: use service.ContextWith instead. func ContextWithManager(ctx context.Context, manager Manager) context.Context { return service.ContextWith[Manager](ctx, manager) } +// Deprecated: use WithDefaultManager instead. func ContextWithDefaultManager(ctx context.Context) context.Context { - if service.FromContext[Manager](ctx) != nil { - return ctx - } - return service.ContextWith[Manager](ctx, NewDefaultManager(ctx)) + return WithDefaultManager(ctx) } diff --git a/service/pause/default.go b/service/pause/default.go index 0b5d85f..55e0375 100644 --- a/service/pause/default.go +++ b/service/pause/default.go @@ -6,6 +6,7 @@ import ( "github.com/sagernet/sing/common/atomic" "github.com/sagernet/sing/common/x/list" + "github.com/sagernet/sing/service" ) type defaultManager struct { @@ -18,16 +19,20 @@ type defaultManager struct { callbacks list.List[Callback] } -func NewDefaultManager(ctx context.Context) Manager { +func WithDefaultManager(ctx context.Context) context.Context { + if service.FromContext[Manager](ctx) != nil { + return ctx + } devicePauseChan := make(chan struct{}) networkPauseChan := make(chan struct{}) close(devicePauseChan) close(networkPauseChan) - return &defaultManager{ + manager := &defaultManager{ ctx: ctx, devicePause: devicePauseChan, networkPause: networkPauseChan, } + return service.ContextWith[Manager](ctx, manager) } func (d *defaultManager) DevicePause() {