Skip to content

Commit

Permalink
Port over the settings watcher from Fyne
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Mar 14, 2024
1 parent acaacfc commit 4ee6fc3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,43 @@ The goal of this project is to be a toolkit agnostic package for Go graphical us

## Supported Portal APIs

The following APIs are partially or completely implemented:
The lsit below contains all of the portal APIs available as of 2024-03-14. Checked boxes are partially or completely implemented within this project.

- [x] [Notification](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Notification.html)
- [x] [OpenURI](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.OpenURI.html)
- [x] [FileChooser](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.FileChooser.html)
- [ ] Account
- [ ] Background
- [ ] Camera
- [ ] Clipboard
- [ ] Device
- [ ] Documents
- [ ] Dynamic Launcher
- [ ] Email
- [x] File Chooser
- [ ] File Transfer
- [ ] Game Mode
- [ ] Global Shortcuts
- [ ] Inhibit
- [ ] Input Capture
- [ ] Location
- [ ] Memory Monitor
- [ ] Network Monitor
- [x] Notification
- [x] OpenURI
- [ ] Power Profile Monitor
- [ ] Print
- [ ] Proxy Resolver
- [ ] Realtime
- [ ] Remote Desktop
- [ ] Request
- [ ] ScreenCast
- [ ] Screenshot
- [ ] Secret
- [ ] Session
- [x] Settings
- [ ] Trash
- [ ] Wallpaper

## Integrations into other projects

## Used by other projects

This section is meant as a reference to where this project is being used. Feel free to add yours if desired.

Expand Down
34 changes: 34 additions & 0 deletions settings/watch.go
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
}

0 comments on commit 4ee6fc3

Please sign in to comment.