diff --git a/windows-agent/internal/config/config.go b/windows-agent/internal/config/config.go index be8883d16..0e08cc37a 100644 --- a/windows-agent/internal/config/config.go +++ b/windows-agent/internal/config/config.go @@ -32,6 +32,9 @@ type Config struct { // Sync mu *sync.Mutex + + // notifiers are called after any configuration changes. + notifiers []func() } // New creates and initializes a new Config object. @@ -44,6 +47,11 @@ func New(ctx context.Context, cachePath string) (m *Config) { return m } +// Notify appends a callback. It'll be called very time any configuration changes. +func (c *Config) Notify(f func()) { + c.notifiers = append(c.notifiers, f) +} + // Subscription returns the ProToken and the method it was acquired with (if any). func (c *Config) Subscription(ctx context.Context) (token string, source Source, err error) { c.mu.Lock() @@ -130,6 +138,10 @@ func (c *Config) set(ctx context.Context, field *string, value string) error { old := *field *field = value + for _, f := range c.notifiers { + f() + } + if err := c.dump(); err != nil { log.Errorf(ctx, "Could not update settings: %v", err) *field = old @@ -250,6 +262,10 @@ func (c *Config) collectRegistrySettingsTasks(ctx context.Context, data Registry log.Warningf(ctx, "Could not obtain some updated registry settings: %v", errs) } + for _, f := range c.notifiers { + f() + } + // Dump updated checksums if err := c.dump(); err != nil { return nil, fmt.Errorf("could not store updated registry settings: %v", err)