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 ¶
- Variables
- func InstallLauncher(ctx context.Context, l Launcher) error
- func LauncherExists(ctx context.Context, id string) (bool, error)
- func ReadSetting(ctx context.Context, namespace, key string) (any, error)
- func RetrieveSecret(ctx context.Context) ([]byte, error)
- func SetAutostart(ctx context.Context, a Autostart) error
- func UninstallLauncher(ctx context.Context, id string) error
- type Autostart
- type Launcher
Constants ¶
This section is empty.
Variables ¶
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 ¶
InstallLauncher asks the user, through the DynamicLauncher portal, to add the launcher l.
func LauncherExists ¶
LauncherExists reports whether InstallLauncher added the launcher id.
func ReadSetting ¶
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 ¶
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 ¶
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.
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.