Help us shape the future of Go! Take the 2026 Go Developer Survey

portal

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

Go API Reference Tests Analysis Go Report Card

Portal

Portal is a Go module providing developer friendly functions for accessing the XDG Desktop Protocol D-Bus API. The goal of this project is to be toolkit agnostic and allow using the portals without needing to access libportal through CGo.

This repository is a maintained fork of rymdport/portal. It provides predictable releases for Refyne and xfilepicker, while keeping changes suitable for contributing back upstream whenever possible.

Maintenance scope

The actively supported surface is the shared request and signal machinery plus the filechooser, notification, openuri, settings, and settings/appearance packages. Other packages are retained for upstream compatibility and accept fixes on a best-effort basis.

The fork follows upstream changes selectively. Releases use this repository's module path and are tested before Refyne or xfilepicker adopt them.

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.

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.

// 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.

package main

import (
	"fmt"
	"log"

	"github.com/alexballas/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)
}

Every function that opens a portal dialog has a *Context variant. Cancelling the context asks the portal to dismiss the dialog:

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

files, err := filechooser.OpenFileContext(ctx, "", "Select files", nil)
if errors.Is(err, context.DeadlineExceeded) {
	// user did not pick a file within 30s; dialog was dismissed
}

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.

  • Account
  • Background
  • Camera
  • Clipboard
  • Documents
  • Dynamic Launcher
  • Email
  • File Chooser
  • File Transfer
  • Game Mode
  • Global Shortcuts
  • Inhibit
  • Input Capture
  • Location
  • Memory Monitor
  • Network Monitor
  • Notification
  • OpenURI
  • Power Profile Monitor
  • Print
  • Proxy Resolver
  • Realtime
  • Remote Desktop
  • Request
  • ScreenCast
  • Screenshot
  • Secret
  • Session
  • Settings
  • Trash
  • Usb
  • 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 release of Fyne.
    • 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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnexpectedResponse = errors.New("unexpected response from dbus")

ErrunexpectedResonse is returned when the received dbus data was in an unexpected format.

Functions

func FormatX11WindowHandle

func FormatX11WindowHandle(handle uintptr) string

FormatX11WindowHandle takes an X11 window handle and formats it in the string format that is required for the portal APIs.

Types

This section is empty.

Directories

Path Synopsis
Package account lets sandboxed applications query basic information about the user, like their name and avatar photo.
Package account lets sandboxed applications query basic information about the user, like their name and avatar photo.
Package background lets sandboxed applications request that the application is allowed to run in the background or started automatically when the user logs in.
Package background lets sandboxed applications request that the application is allowed to run in the background or started automatically when the user logs in.
Package filechooser asks the user to pick files through the xdg-desktop-portal FileChooser interface.
Package filechooser asks the user to pick files through the xdg-desktop-portal FileChooser interface.
internal
apis
Package apis contains dbus paths and call names for various portal apis.
Package apis contains dbus paths and call names for various portal apis.
convert
Package convert contains functions for converting to dbus data structures.
Package convert contains functions for converting to dbus data structures.
request
Package request implements the Request interface shared by portal methods that return a handle and emit a Response signal asynchronously.
Package request implements the Request interface shared by portal methods that return a handle and emit a Response signal asynchronously.
session
Package session is the Session interface shared by portal interfaces that create long-lived sessions (location, usb, ...).
Package session is the Session interface shared by portal interfaces that create long-lived sessions (location, usb, ...).
Package location lets sandboxed applications query basic information about the location.
Package location lets sandboxed applications query basic information about the location.
Package memorymonitor provides information about low system memory to sandboxed applications.
Package memorymonitor provides information about low system memory to sandboxed applications.
Package networkmonitor provides network status information to sandboxed applications.
Package networkmonitor provides network status information to sandboxed applications.
Package notification lets sandboxed applications send and withdraw notifications.
Package notification lets sandboxed applications send and withdraw notifications.
Package openuri allows sandboxed applications to open URIs (e.g.
Package openuri allows sandboxed applications to open URIs (e.g.
Package powerprofilemonitor provides information about the user-selected system-wide power profile, to sandboxed applications.
Package powerprofilemonitor provides information about the user-selected system-wide power profile, to sandboxed applications.
Package proxyresolver provides network proxy information to sandboxed applications.
Package proxyresolver provides network proxy information to sandboxed applications.
Package screenshot lets sandboxed applications request a screenshot.
Package screenshot lets sandboxed applications request a screenshot.
Package secret allows sandboxed applications to retrieve a per-application secret.
Package secret allows sandboxed applications to retrieve a per-application secret.
Package settings provides read-only access to a small number of host settings required for toolkits similar to XSettings.
Package settings provides read-only access to a small number of host settings required for toolkits similar to XSettings.
appearance
Package appearance is a helper package for reading appearance settings.
Package appearance is a helper package for reading appearance settings.
Package trash lets sandboxed applications send files to the trashcan.
Package trash lets sandboxed applications send files to the trashcan.
Package usb lets sandboxed applications monitor and request access to connected USB devices.
Package usb lets sandboxed applications monitor and request access to connected USB devices.
Package wallpaper is a simple interface that lets sandboxed applications set the user’s desktop background picture.
Package wallpaper is a simple interface that lets sandboxed applications set the user’s desktop background picture.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL