Skip to content

Commit

Permalink
Make the setting changed watcher more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Mar 16, 2024
1 parent 28b9503 commit 3f4cfa6
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions settings/changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package settings

import (
"github.com/godbus/dbus/v5"
"github.com/rymdport/portal"
"github.com/rymdport/portal/internal/apis"
)

Expand Down Expand Up @@ -33,15 +32,20 @@ func OnSignalSettingChanged(callback func(changed Changed)) error {
conn.Signal(dbusChan)

for sig := range dbusChan {
if len(sig.Body) != 3 {
return portal.ErrUnexpectedResponse
if len(sig.Body) == 0 {
continue
}

callback(Changed{
Namespace: sig.Body[0].(string),
Key: sig.Body[1].(string),
Value: sig.Body[2],
})
changed := Changed{Namespace: sig.Body[0].(string)}
if len(sig.Body) > 1 {
changed.Key = sig.Body[1].(string)
}

if len(sig.Body) > 2 {
changed.Value = sig.Body[2]
}

callback(changed)
}

return nil
Expand Down

0 comments on commit 3f4cfa6

Please sign in to comment.