-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port over the settings watcher from Fyne
- Loading branch information
Showing
2 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package settings | ||
|
||
import ( | ||
"github.com/godbus/dbus/v5" | ||
"github.com/rymdport/portal" | ||
) | ||
|
||
const settingsCallPath = portal.CallBaseName + ".Settings" | ||
|
||
// WatchSettingsChange allows setting a function to run each time the portal settings change. | ||
func WatchSettingsChange(callback func(value []any)) error { | ||
conn, err := dbus.SessionBus() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := conn.AddMatchSignal( | ||
dbus.WithMatchObjectPath(portal.ObjectPath), | ||
dbus.WithMatchInterface(settingsCallPath), | ||
dbus.WithMatchMember("SettingChanged"), | ||
); err != nil { | ||
return err | ||
} | ||
defer conn.Close() | ||
|
||
dbusChan := make(chan *dbus.Signal) | ||
conn.Signal(dbusChan) | ||
|
||
for sig := range dbusChan { | ||
callback(sig.Body) | ||
} | ||
|
||
return nil | ||
} |