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 ¶
- Variables
- func AddNotification(ctx context.Context, n Notification) error
- 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 RemoveNotification(ctx context.Context, id string) 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
- type Notification
- type Priority
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 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 ¶
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 RemoveNotification ¶ added in v0.5.0
RemoveNotification withdraws a notification AddNotification showed; the portal ignores an unknown id.
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.
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
}
Notification is a desktop notification for the Notification portal.