portal

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 11 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package portal calls the xdg-desktop-portal interfaces a Flatpak app uses instead of writing host folders: the Background portal for starting at sign-in, DynamicLauncher for desktop launchers, Secret for a per-app master secret, Settings for desktop appearance values, and Notification for desktop notifications. Every call opens the session bus, makes one request and closes it. Portal dialogs wait on the user, so every call takes a context: set a deadline, since none is imposed here. Off Linux every call returns ErrUnsupported.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCancelled is returned when the user dismisses the portal's dialog.
	ErrCancelled = errors.New("portal: cancelled by the user")
	// ErrNotAllowed is returned when autostart was asked for and the portal did not grant it.
	ErrNotAllowed = errors.New("portal: request was not allowed")
	// ErrNotFound is returned by ReadSetting when the portal has no such setting.
	ErrNotFound = errors.New("portal: setting not found")
	// ErrUnsupported is returned by every call on a platform without desktop portals.
	ErrUnsupported = errors.New("portal: desktop portals exist only on Linux")
)

Declared without a build tag so every platform's build has the same errors.

Functions

func AddNotification added in v0.5.0

func AddNotification(ctx context.Context, n Notification) error

AddNotification shows n through the Notification portal, which needs no talk-name on the notification service. The portal answers no Request: it returns once it has accepted the notification.

func InstallLauncher

func InstallLauncher(ctx context.Context, l Launcher) error

InstallLauncher asks the user, through the DynamicLauncher portal, to add the launcher l.

func LauncherExists

func LauncherExists(ctx context.Context, id string) (bool, error)

LauncherExists reports whether InstallLauncher added the launcher id.

func OnNotificationAction added in v0.6.0

func OnNotificationAction(ctx context.Context, fn func(NotificationAction)) (func(), error)

OnNotificationAction calls fn, on its own goroutine, for each ActionInvoked signal the portal sends: a click on a notification's non-exported default action or button. Actions named "app.…" are exported and the portal activates them through D-Bus activation instead, so they never arrive here. It holds one session-bus connection until ctx ends or the returned stop is called; stop is idempotent and does not wait for a running fn.

func ReadSetting

func ReadSetting(ctx context.Context, namespace, key string) (any, error)

ReadSetting returns the Settings portal value for namespace/key with every enclosing variant removed (older portals wrap the value twice), or ErrNotFound when the portal has no such setting. For example ("org.freedesktop.appearance", "accent-color") answers the desktop's accent colour as []any of three float64.

func RemoveNotification added in v0.5.0

func RemoveNotification(ctx context.Context, id string) error

RemoveNotification withdraws a notification AddNotification showed; the portal ignores an unknown id.

func RetrieveSecret

func RetrieveSecret(ctx context.Context) ([]byte, error)

RetrieveSecret returns the Secret portal's per-app master secret: the same bytes on every call for this app id, which the portal derives from the app id, not from the request. It answers only a sandboxed caller with an app id.

func SetAutostart

func SetAutostart(ctx context.Context, a Autostart) error

SetAutostart asks the Background portal to start a.Command (run inside the sandbox) at sign-in, or to stop doing so. It returns ErrNotAllowed when enabling was not granted.

func UninstallLauncher

func UninstallLauncher(ctx context.Context, id string) error

UninstallLauncher removes a launcher InstallLauncher added; a missing one is not an error.

Types

type Autostart

type Autostart struct {
	Enable  bool
	Command []string // run inside the sandbox at sign-in
	Reason  string   // shown in the permission dialog; empty sends none
}

Autostart is a request to start Command at sign-in, or to stop doing so.

type Launcher

type Launcher struct {
	ID         string   // must start with the app id and end in .desktop (portal rule)
	Name       string   // proposed; the user may rename it in the dialog
	IconPNG    []byte   // the launcher's icon
	Exec       []string // argv, quoted and escaped by desktopentry.Exec
	Comment    string   // optional
	Categories []string // optional
}

Launcher is a desktop launcher for the DynamicLauncher portal.

type Notification added in v0.5.0

type Notification struct {
	ID       string   // names the notification; adding the same ID again replaces it
	Title    string   // required by the portal
	Body     string   // optional
	Priority Priority // empty sends none, which the portal treats as normal
	IconPNG  []byte   // optional

	// DefaultAction runs when the user clicks the notification. Without the "app." prefix it arrives through
	// OnNotificationAction; with it the portal activates the app's exported action instead.
	DefaultAction       string
	DefaultActionTarget string // sent as a string variant with DefaultAction; empty sends none
	Buttons             []NotificationButton
}

Notification is a desktop notification for the Notification portal.

type NotificationAction added in v0.6.0

type NotificationAction struct {
	ID              string // the Notification.ID
	Action          string
	Target          string // empty when the notification set none
	ActivationToken string // XDG Activation token for focusing a window; empty from portals older than version 2
	Response        string // text of a purpose-based action such as im.reply-with-text; empty otherwise
}

NotificationAction is the user's activation of a notification's default action or a button, as the portal's ActionInvoked signal reports it.

type NotificationButton added in v0.6.0

type NotificationButton struct {
	Label  string // user-visible
	Action string // same rules as Notification.DefaultAction
	Target string // sent as a string variant; empty sends none
}

NotificationButton is an action button under a notification.

type Priority added in v0.5.0

type Priority string

Priority is a notification's urgency, as the Notification portal names it.

const (
	PriorityLow    Priority = "low"
	PriorityNormal Priority = "normal"
	PriorityHigh   Priority = "high"
	PriorityUrgent Priority = "urgent"
)

The portal's four priorities. Urgent notifications stay until dismissed on most desktops.

Jump to

Keyboard shortcuts

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