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 OnNotificationAction(ctx context.Context, fn func(NotificationAction)) (func(), 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 NotificationAction
- type NotificationButton
- 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 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 ¶
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
// 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.