portal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 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, and Settings for desktop appearance values. 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 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 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 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.

Jump to

Keyboard shortcuts

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