fix config reloading notifier and add callback to the daemon

This commit is contained in:
LeonardoTrapani
2025-08-20 20:06:59 +02:00
parent 99f82fb420
commit ddef3435f6
3 changed files with 77 additions and 14 deletions
+16 -11
View File
@@ -35,22 +35,14 @@ func New() (*Daemon, error) {
conf := configMgr.GetConfig()
var n notify.Notifier
switch conf.Notifications.Type {
case "desktop":
n = notify.Desktop{}
case "log":
n = notify.Log{}
case "none":
n = notify.Nop{}
}
if err != nil {
return nil, fmt.Errorf("failed to create config manager: %w", err)
}
ctx, cancel := context.WithCancel(context.Background())
n := notify.GetNotifierBasedOnConfig(conf)
d := &Daemon{
notifier: n,
configMgr: configMgr,
@@ -61,6 +53,17 @@ func New() (*Daemon, error) {
return d, nil
}
func (d *Daemon) onConfigReload() {
log.Printf("Config reloaded, restarting pipeline")
d.stopPipeline()
d.notifier.Notify("Hyprvoice", "Config Reloaded")
d.mu.Lock()
d.notifier = notify.GetNotifierBasedOnConfig(d.configMgr.GetConfig())
d.mu.Unlock()
}
func (d *Daemon) status() pipeline.Status {
d.mu.RLock()
defer d.mu.RUnlock()
@@ -86,6 +89,8 @@ func (d *Daemon) Run() error {
return err
}
d.configMgr.SetOnConfigReload(d.onConfigReload)
ln, err := bus.Listen()
if err != nil {
return err