portaldialogs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 9 Imported by: 3 modules, 0 packages

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 portaldialogs is the dev.stubbe.lys.PortalDialogs1 contract: the native dialogs lys-shell shows behind the desktop-portal backend's Access, Account, AppChooser, DynamicLauncher, Usb and Wallpaper preview, in place of xdg-desktop-portal-gtk, and the password prompt and administrator authentication other lys processes ask through it. It holds the requests and replies, the Host a shell implements, the Daemon serving one, the Client calling it, and what every portal dialog is told about the request it serves: its Caller and the Choices it carries.

Index

Constants

View Source
const (
	ServiceName = "dev.stubbe.lys.PortalDialogs1"
	ServicePath = dbus.ObjectPath("/dev/stubbe/lys/PortalDialogs")
)

D-Bus identity.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessRequest

type AccessRequest struct {
	Title, Subtitle, Body string
	GrantLabel, DenyLabel string
	// Icon is a themed icon name for the permission, "" for none.
	Icon string
	// Choices are extra questions shown with the prompt.
	Choices []Choice
}

AccessRequest is one grant/deny prompt.

type AccountInfo

type AccountInfo struct{ Name, Image string }

AccountInfo is what the Account dialog shares, (ss): the name and an avatar image path ("" for none).

type AuthAction

type AuthAction interface {
	AuthReply
	// contains filtered or unexported methods
}

AuthAction is what the user did in an authentication dialog other than answering its prompt: AuthCancel or AuthSwitch. With no Authenticate call waiting, the host signals it instead of replying.

type AuthAnswer

type AuthAnswer struct{ Response Response }

AuthAnswer is the response typed at the prompt for the selected identity.

type AuthCancel

type AuthCancel struct{}

AuthCancel is the user cancelling the authentication.

type AuthDetail

type AuthDetail struct{ Label, Value string }

AuthDetail is one labelled line about the action, (ss).

type AuthIdentity

type AuthIdentity struct {
	UID  uint32
	Name string
}

AuthIdentity is one user who may authenticate, (us): the uid and the name shown for it.

type AuthNote

type AuthNote struct {
	Error bool
	Text  string
}

AuthNote is one message of the conversation, (bs): Error says it is an error rather than information.

type AuthReply

type AuthReply interface {
	// contains filtered or unexported methods
}

AuthReply is how the user ended an Authenticate call: an AuthAnswer, or an AuthAction.

type AuthRequest

type AuthRequest struct {
	// Message is what the action asks for and Icon its themed icon
	// name, "" for none.
	Message, Icon string
	// Details are shown labelled, in order (the program and command
	// line).
	Details []AuthDetail
	// Identities are who may authenticate; Selected is the uid of the
	// one the prompt is for, and one of them.
	Identities []AuthIdentity
	Selected   uint32
	// Notes are the conversation's messages so far, in arrival order.
	Notes []AuthNote
	// Prompt is what the entry asks for; Echo shows what is typed.
	Prompt string
	Echo   bool
}

AuthRequest is one step of an administrator authentication (polkit's PAM conversation), (ssa(ss)a(us)ua(bs)sb): the dialog for a handle stays up across the steps and shows the latest.

type AuthSwitch

type AuthSwitch struct{ UID uint32 }

AuthSwitch is the user choosing to authenticate as the identity UID instead; the caller restarts the conversation for it.

type AuthWatch

type AuthWatch struct {
	// contains filtered or unexported fields
}

AuthWatch delivers what the user does in one authentication dialog while no Authenticate call waits. It hears only the host that owned ServiceName when the watch began: signals from any other peer are not the dialog's. It ends when its context ends, on Close, or when it fails: the connection closes, the host loses ServiceName (it quit or another took over), which takes the dialog with it, or the host signals something about the request the contract does not define, which means it speaks another one. Every watch must be closed, which reports why it failed.

func (*AuthWatch) Actions

func (w *AuthWatch) Actions() <-chan AuthAction

Actions delivers the user's actions in the order the host signalled them; it closes when the watch ends.

func (*AuthWatch) Close

func (w *AuthWatch) Close() error

Close ends the watch, waits until its match rule is removed, and returns why it failed, joined with any error removing the rule: nil when it ended through its context or Close. Closing again returns the same.

type Caller

type Caller struct {
	Handle, AppID, ParentWindow string
	Modal                       bool
}

Caller identifies the portal request behind a shell dialog: Handle is the request's object path, the key the services' Dismiss names; AppID is the app asking ("" for a host app); ParentWindow is the app's window identifier ("wayland:<xdg-foreign handle>", or ""); Modal is whether the dialog should hold the keyboard until answered (the portal's modal option, true unless the app said otherwise). Over D-Bus it is the struct (sssb).

type Choice

type Choice struct {
	ID, Label string
	Options   []Option
	Initial   string
}

Choice is one of the extra questions a portal dialog may carry (the FileChooser's and Access' choices option, (ssa(ss)s)): an id, a label, the options, and the initial option ("" lets the dialog pick). No options is a yes/no question with the values "true" and "false".

func (Choice) Boolean

func (c Choice) Boolean() bool

Boolean reports whether the choice is a yes/no question.

func (Choice) Start

func (c Choice) Start() string

Start is the value the choice starts at: the initial option when it is one of the options, else the first (or "false" for a yes/no).

type ChooserRequest

type ChooserRequest struct {
	// Choices are the app ids offered; none offers the apps for
	// ContentType.
	Choices []string
	// LastChoice is the app id preselected, "" for none.
	LastChoice string
	// ContentType is the type opened, "" when unknown.
	ContentType string
	// Target names what is opened (a file's basename or a URI), ""
	// for nothing to name.
	Target string
}

ChooserRequest is one app chooser, (asss). App ids are desktop ids without ".desktop", as the portal speaks them.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client calls the shell's dialogs; a dialog waits on the user, so the calls are bounded only by ctx.

func NewClient

func NewClient(conn *dbus.Conn) *Client

NewClient addresses the host over conn.

func (*Client) Access

func (c *Client) Access(ctx context.Context, caller Caller, r AccessRequest) (granted bool, picked []Selection, err error)

Access shows the grant/deny prompt.

func (*Client) Account

func (c *Client) Account(ctx context.Context, caller Caller, reason string, info AccountInfo) (shared bool, edited AccountInfo, err error)

Account asks to share info, which the user may edit first.

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context, caller Caller, r AuthRequest) (AuthReply, error)

Authenticate shows one prompt of an administrator authentication and waits for the user: an AuthAnswer for r.Selected, an AuthSwitch to another of r.Identities, or an AuthCancel.

func (*Client) ChooseApplication

func (c *Client) ChooseApplication(ctx context.Context, caller Caller, r ChooserRequest) (id string, err error)

ChooseApplication picks a handler's app id; "" is a cancel.

func (*Client) ChooseDevices

func (c *Client) ChooseDevices(ctx context.Context, caller Caller, devices []Device) (allowed bool, picked []string, err error)

ChooseDevices asks which USB devices an app may open, replying the ids picked.

func (*Client) ConfirmInstall

func (c *Client) ConfirmInstall(ctx context.Context, caller Caller, r LauncherRequest) (ok bool, name string, err error)

ConfirmInstall asks to install a dynamic launcher, replying the name the user chose.

func (*Client) ConfirmWallpaper

func (c *Client) ConfirmWallpaper(ctx context.Context, caller Caller, uri string) (ok bool, err error)

ConfirmWallpaper previews uri and asks to set it.

func (*Client) Dismiss

func (c *Client) Dismiss(ctx context.Context, handle string) error

Dismiss takes down the dialog showing for the request at handle.

func (*Client) Password

func (c *Client) Password(ctx context.Context, caller Caller, r PasswordRequest) (ok bool, password string, err error)

Password asks for a password; ok is false when the user cancelled.

func (*Client) ShowAuthentication

func (c *Client) ShowAuthentication(ctx context.Context, caller Caller, r AuthRequest) error

ShowAuthentication updates an administrator authentication without a prompt; WatchAuthentication reports what the user does meanwhile.

func (*Client) UpdateChoices

func (c *Client) UpdateChoices(ctx context.Context, handle string, choices []string) (found bool, err error)

UpdateChoices replaces the app ids the chooser open for handle offers; false when none is open for it.

func (*Client) WatchAuthentication

func (c *Client) WatchAuthentication(ctx context.Context, handle string) (*AuthWatch, error)

WatchAuthentication watches the authentication dialog for the request at handle, shown by the current owner of ServiceName, from when it returns until ctx ends or the watch is closed. With no host owning ServiceName there is no dialog to watch, which is an error.

type Daemon

type Daemon struct {
	// contains filtered or unexported fields
}

Daemon serves a Host as dev.stubbe.lys.PortalDialogs1.

func NewDaemon

func NewDaemon(host Host) *Daemon

NewDaemon wraps the host for export.

func (*Daemon) Access

func (d *Daemon) Access(c Caller, title, subtitle, body, grantLabel, denyLabel, icon string, choices []Choice) (bool, []Selection, *dbus.Error)

Access is the grant/deny prompt.

func (*Daemon) Account

func (d *Daemon) Account(c Caller, reason string, info AccountInfo) (bool, AccountInfo, *dbus.Error)

Account is the account-info consent.

func (*Daemon) Authenticate

func (d *Daemon) Authenticate(c Caller, r AuthRequest) (bool, uint32, string, *dbus.Error)

Authenticate is one prompt of an administrator authentication.

func (*Daemon) ChooseApplication

func (d *Daemon) ChooseApplication(c Caller, r ChooserRequest) (string, *dbus.Error)

ChooseApplication is the app chooser.

func (*Daemon) ChooseDevices

func (d *Daemon) ChooseDevices(c Caller, devices []Device) (bool, []string, *dbus.Error)

ChooseDevices is the USB device consent.

func (*Daemon) ConfirmInstall

func (d *Daemon) ConfirmInstall(c Caller, r LauncherRequest) (bool, string, *dbus.Error)

ConfirmInstall is the dynamic-launcher install confirmation.

func (*Daemon) ConfirmWallpaper

func (d *Daemon) ConfirmWallpaper(c Caller, uri string) (bool, *dbus.Error)

ConfirmWallpaper is the wallpaper preview confirmation.

func (*Daemon) Dismiss

func (d *Daemon) Dismiss(handle string) *dbus.Error

Dismiss takes down the dialog showing for the request at handle.

func (*Daemon) Export

func (d *Daemon) Export(conn *dbus.Conn) (func(), error)

Export serves the interface under its name; the returned release drops the name.

func (*Daemon) Password

func (d *Daemon) Password(c Caller, r PasswordRequest) (bool, string, *dbus.Error)

Password is the password prompt.

func (*Daemon) ShowAuthentication

func (d *Daemon) ShowAuthentication(c Caller, r AuthRequest) *dbus.Error

ShowAuthentication updates an administrator authentication without a prompt.

func (*Daemon) UpdateChoices

func (d *Daemon) UpdateChoices(handle string, choices []string) (bool, *dbus.Error)

UpdateChoices updates the app chooser open for handle.

type Device

type Device struct {
	// ID is the frontend's device id; Name is how the user knows it.
	ID, Name string
	// Writable is whether the app asks to write to it.
	Writable bool
}

Device is one USB device an app asks to open, (ssb).

type Emitter

type Emitter struct {
	// contains filtered or unexported fields
}

Emitter signals what the user does in an authentication dialog while no Authenticate call waits.

func NewEmitter

func NewEmitter(conn *dbus.Conn) *Emitter

NewEmitter signals over conn, the one the Daemon is exported on.

func (*Emitter) AuthAction

func (e *Emitter) AuthAction(handle string, a AuthAction) error

AuthAction signals the action taken in the dialog for the request at handle: AuthenticationCancelled(s) or AuthenticationIdentity(su).

type Host

type Host interface {
	// Access replies whether the user granted and, when granted, what
	// they picked for each choice.
	Access(Caller, AccessRequest) (bool, []Selection)
	// Account offers info for sharing and replies whether the user
	// shares it, and what they left of it after editing.
	Account(c Caller, reason string, info AccountInfo) (bool, AccountInfo)
	// ConfirmWallpaper previews a file:// image and replies whether to
	// set it.
	ConfirmWallpaper(c Caller, uri string) bool
	// ChooseApplication replies the chosen app id, "" on cancel.
	ChooseApplication(Caller, ChooserRequest) string
	// UpdateChoices replaces the app ids offered by the app chooser
	// for the request at handle, showing or waiting; false when no
	// chooser is open for it.
	UpdateChoices(handle string, choices []string) bool
	// ChooseDevices replies whether the user allowed the app USB
	// devices and the ids of the ones they picked.
	ChooseDevices(Caller, []Device) (bool, []string)
	// ConfirmInstall replies whether to install a dynamic launcher,
	// and under what name.
	ConfirmInstall(Caller, LauncherRequest) (bool, string)
	// Password replies whether the user entered a password, and it.
	Password(Caller, PasswordRequest) (bool, string)
	// Authenticate shows the authentication dialog for the request at
	// the caller's handle, or updates the one showing, and replies once
	// the user answers its prompt, cancels or picks another identity.
	// The dialog stays up until Dismiss.
	Authenticate(Caller, AuthRequest) AuthReply
	// ShowAuthentication shows the authentication dialog for the
	// request at the caller's handle, or updates the one showing,
	// without a prompt: its notes only. What the user does meanwhile
	// goes out through an Emitter.
	ShowAuthentication(Caller, AuthRequest)
	// Dismiss takes down the dialog showing for the request at handle,
	// when one is; the app closed the request.
	Dismiss(handle string)
}

Host shows the dialogs; each call blocks until the user answers or the request is dismissed, which answers no ("" for a chooser).

type LauncherRequest

type LauncherRequest struct {
	// Name is the launcher's default name.
	Name string
	// Icon is the launcher's image (PNG, JPEG or SVG), empty for none.
	Icon []byte
	// Target is the URL a web app opens, "" for an application.
	Target string
	// EditableName lets the user change the name.
	EditableName bool
}

LauncherRequest is one dynamic launcher to confirm, (saysb).

type Option

type Option struct{ ID, Label string }

Option is one entry of a Choice: its id and its label, (ss).

type PasswordRequest

type PasswordRequest struct {
	Title, Body    string
	Confirm, Retry bool
}

PasswordRequest asks for a password, (ssbb): Confirm asks for a new one, typed twice; Retry says the previous answer was wrong.

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response is the answer typed at an authentication prompt. It formats and logs as redacted; only Reveal gives the text.

func NewResponse

func NewResponse(text string) Response

NewResponse holds text as a response.

func (Response) Format

func (Response) Format(f fmt.State, _ rune)

Format writes the response as redacted for every verb.

func (Response) LogValue

func (Response) LogValue() slog.Value

LogValue logs the response as redacted.

func (Response) Reveal

func (r Response) Reveal() string

Reveal is the text typed.

type Selection

type Selection struct{ ID, Value string }

Selection is one answered choice, (ss): the choice's id and the option picked.

Jump to

Keyboard shortcuts

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