https://github.com/rymdport/portal
Toolkit agnostic and easy to use Go module for the XDG Desktop Portal API.
https://github.com/rymdport/portal
dbus go xdg-desktop-portal
Last synced: 6 months ago
JSON representation
Toolkit agnostic and easy to use Go module for the XDG Desktop Portal API.
- Host: GitHub
- URL: https://github.com/rymdport/portal
- Owner: rymdport
- License: apache-2.0
- Created: 2023-11-18T20:56:14.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-08-30T10:05:28.000Z (10 months ago)
- Last Synced: 2025-08-30T11:23:35.415Z (10 months ago)
- Topics: dbus, go, xdg-desktop-portal
- Language: Go
- Homepage: https://pkg.go.dev/github.com/rymdport/portal
- Size: 2.16 MB
- Stars: 28
- Watchers: 1
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/rymdport/portal)
[](https://github.com/rymdport/portal/actions/workflows/tests.yml)
[](https://github.com/rymdport/portal/actions/workflows/analysis.yml)
[](https://goreportcard.com/report/github.com/rymdport/portal)
# Portal
Portal is a Go module providing developer friendly functions for accessing the [XDG Desktop Protocol](https://flatpak.github.io/xdg-desktop-portal/) D-Bus API. The goal of this project is to be toolkit agnostic and allow using the portals without needing to access [libportal](https://github.com/flatpak/libportal) through CGo.
Using the portals allow applications to request information from the user even when running inside a sandbox like Flatpak. As such, it is possible to open file dialogs, open links in the browser, send notifications and much more in a way that integrates well with the desktop environment. This also avoids needing to open up permissions in the sandbox.
## API
The api of this Go module is designed to closely follow the structure naming of the upstream APIs. This means, in practice, that each D-Bus interface is implemented as its own package here. However, care is taken to be developer friendly and integrate seamlessly with native Go types.
- Documentation for this module and all of its packages can be found on pkg.go.dev: https://pkg.go.dev/github.com/rymdport/portal
- Documentation for the D-Bus protocol of the portals: https://flatpak.github.io/xdg-desktop-portal/docs/api-reference.html
The version of this module's API is still in a `v0.X.Y` state and is subject to change in the future.
A release with breaking changes will increment X while Y will be incremented when there are minor bug or feature improvements.
### Window Handles
The portal APIs often provide a `windowHandle` parameter that allow dialogs and other actions to be attached to a specific window.
#### From Fyne
With Fyne running in X11 mode it is easy to get the window handle like below. However, note that the snippet will not work with `-tags wayland`.
```go
// based on https://github.com/fyne-io/fyne/blob/19dcdbdb5f5a9b293a21a29b5235c163345b36d0/dialog/file_xdg_flatpak.go#L124
func getWindowHandle(window fyne.Window) string {
windowHandle := ""
window.(driver.NativeWindow).RunNative(func(context any) {
handle := context.(driver.X11WindowContext).WindowHandle
windowHandle = portal.FormatX11WindowHandle(handle)
})
return windowHandle
}
```
## Example
The following example showcases how a file chooser can be opened for selecting one or more files.
```go
package main
import (
"fmt"
"log"
"github.com/rymdport/portal/filechooser"
)
func main() {
options := filechooser.OpenFileOptions{Multiple: true}
files, err := filechooser.OpenFile("", "Select files", &options)
if err != nil {
log.Fatalln(err)
}
fmt.Println(files)
}
```
## Supported Portal Interfaces
The list below contains all of the portal interfaces available within the project. Checked boxes are partially or completely implemented within this project. Note that this list usually refers to the state of the `main` branch and not necessarily the latest release.
- [x] Account
- [x] Background
- [ ] Camera
- [ ] Clipboard
- [ ] Documents
- [ ] Dynamic Launcher
- [ ] Email
- [x] File Chooser
- [ ] File Transfer
- [ ] Game Mode
- [ ] Global Shortcuts
- [ ] Inhibit
- [ ] Input Capture
- [x] Location
- [x] Memory Monitor
- [x] Network Monitor
- [x] Notification
- [x] OpenURI
- [x] Power Profile Monitor
- [ ] Print
- [x] Proxy Resolver
- [ ] Realtime
- [ ] Remote Desktop
- [x] Request
- [ ] ScreenCast
- [x] Screenshot
- [x] Secret
- [x] Session
- [x] Settings
- [x] Trash
- [ ] Usb
- [x] Wallpaper
## 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.
- This project is used as of the [v2.5.0](https://github.com/fyne-io/fyne/releases/tag/v2.5.0) release of [Fyne](https://fyne.io).
- All the old theme watching code has been replaced by the `settings` package (and `appearance` subpackage) from this module. The `filechooser` and `notification` packages replace the old Fyne-code when compiling with `-tags flatpak`.
## Contributing
Contributions are strongly appreciated. Everything from creating bug reports to contributing code will help the project a lot, so please feel free to help in any way, shape, or form that you feel comfortable with.
## License
- Portal is licensed under `Apache License Version 2.0` and will forever continue to be free and open source.