From 2c67b27b4af5b1b2d66080275d838aabc22d82ad Mon Sep 17 00:00:00 2001 From: Alexandr Stelnykovych Date: Fri, 7 Nov 2025 16:51:58 +0200 Subject: [PATCH] refactor: remove SPNGroup from 'control.instance' interface and update pause logic --- service/control/module.go | 1 - service/control/pause.go | 23 ++++++++++++----------- service/instance.go | 9 +++++++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/service/control/module.go b/service/control/module.go index d04ff7e1..8efdf52c 100644 --- a/service/control/module.go +++ b/service/control/module.go @@ -31,7 +31,6 @@ type Control struct { type instance interface { Config() *config.Config InterceptionGroup() *mgr.GroupModule - SPNGroup() *mgr.ExtendedGroup IsShuttingDown() bool } diff --git a/service/control/pause.go b/service/control/pause.go index 79387d08..a33ddebc 100644 --- a/service/control/pause.go +++ b/service/control/pause.go @@ -32,15 +32,18 @@ func (c *Control) pause(duration time.Duration, onlySPN bool) (retErr error) { return errors.New("invalid pause duration") } + spn_enabled := config.GetAsBool("spn/enable", false) if onlySPN { if c.pauseInfo.Interception { return errors.New("cannot pause SPN separately when core is paused") } - if !c.pauseInfo.SPN && !c.instance.SPNGroup().Ready() { + // If SPN is not running and not already paused, cannot pause it or change pause duration. + if !spn_enabled() && !c.pauseInfo.SPN { return errors.New("cannot pause SPN when it is not running") } } + // Stop resume worker if running and start a new one later. c.stopResumeWorker() defer func() { if retErr == nil { @@ -49,18 +52,16 @@ func (c *Control) pause(duration time.Duration, onlySPN bool) (retErr error) { } }() + // Pause SPN if not already paused. if !c.pauseInfo.SPN { - if c.instance.SPNGroup().Ready() { - enabled := config.GetAsBool("spn/enable", false) - if enabled() { - // TODO: the 'pause' state must not make permanent config changes. - // Consider possibility to not store permanent config changes. - // E.g. SPN enabled -> pause SPN -> restart PC/Portmaster -> SPN should be enabled again. - config.SetConfigOption("spn/enable", false) - c.mgr.Info("SPN paused") - } - c.pauseInfo.SPN = true + if spn_enabled() { + // TODO: the 'pause' state must not make permanent config changes. + // Consider possibility to not store permanent config changes. + // E.g. SPN enabled -> pause SPN -> restart PC/Portmaster -> SPN should be enabled again. + config.SetConfigOption("spn/enable", false) + c.mgr.Info("SPN paused") } + c.pauseInfo.SPN = true } if onlySPN { diff --git a/service/instance.go b/service/instance.go index 5b3ab760..ebf53fd1 100644 --- a/service/instance.go +++ b/service/instance.go @@ -317,7 +317,11 @@ func New(svcCfg *ServiceConfig) (*Instance, error) { //nolint:maintidx // Grouped interception modules that can be paused/resumed together. instance.serviceGroupInterception = mgr.NewGroupModule("Interception Group", instance.interception, - instance.dnsmonitor, + + // TODO: The dnsmonitor is currently not part of this group, as it has inconsistent issue when stopping. + // Fix chars-issue of this module and re-add it here. + //instance.dnsmonitor, + instance.compat) // Add all modules to instance group. @@ -348,11 +352,12 @@ func New(svcCfg *ServiceConfig) (*Instance, error) { //nolint:maintidx instance.filterLists, instance.customlist, - // Grouped interception modules: + // Grouped pausable interception modules: // instance.interception, // instance.dnsmonitor, // instance.compat instance.serviceGroupInterception, + instance.dnsmonitor, // TODO: Remove when re-added to serviceGroupInterception group. instance.status, instance.broadcasts,