fix config reloading notifier and add callback to the daemon
This commit is contained in:
+16
-11
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user