desktop

package
v1.9.6 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: BSD-3-Clause Imports: 22 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 desktop holds the desktop services that Flutter leaves to plugins: the system tray, notifications, file dialogs and opening URIs.

Flutter: no counterpart in the framework (Flutter uses plugins such as tray_manager, flutter_local_notifications, file_selector and url_launcher).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseNotification

func CloseNotification(ctx context.Context, bc widgets.BuildContext, id NotificationID) error

CloseNotification closes a notification that is shown: its OnClosed gets NotificationClosedByApp. Closing one that is gone is not an error. The rules of the call are those of ShowNotification.

Flutter: no counterpart

func InstallBus

func InstallBus(b *widgets.WidgetsBinding, bus dbus.Bus)

InstallBus makes the app of the binding talk to bus instead of the session bus. It is for gluttertest, which gives the tests a fake desktop (gluttertest.Tester.FakeDesktop); the bus type is internal, so an app cannot name it.

Flutter: no counterpart

func KeepScreenOn

func KeepScreenOn(bc widgets.BuildContext, on bool) error

KeepScreenOn stops the screen from going idle (dimming, blanking and locking) while the window that the context belongs to is visible, or, with false, lets it go idle again. A video player or a presentation calls it with true while it plays and with false when it stops. The window gives the request up when it is closed.

On Wayland it uses zwp_idle_inhibit_manager_v1. It fails with the tag IdleInhibitUnavailable when the compositor, the platform or the host cannot do it (the X11 backend cannot yet). It panics with ViewOfWithoutView, like widgets.ViewOf, when the context has no View above it.

Flutter: no counterpart (Flutter apps use the wakelock_plus plugin)

func OpenURI

func OpenURI(ctx context.Context, bc widgets.BuildContext, uri string) error

OpenURI opens a URI with the application that the desktop chooses for it: a web page in the browser, a file in its viewer, a mailto: link in the mail program. It goes through the OpenURI portal (org.freedesktop.portal.OpenURI), which makes the app chooser of the desktop the parent of the window of bc, and falls back to xdg-open when there is no portal. Without either it fails with OpenURIUnavailable. If the user cancels the portal's app chooser, OpenURI returns nil.

On the web it is window.open(uri, "_blank", "noopener"): the browser lets a page open a window only soon after a click or a key press, so call it from the handler of one (on a goroutine, as always); a javascript: or vbscript: URI fails with OpenURISchemeBlocked, and the browser's pop-up blocker is not reported.

On Android it starts an ACTION_VIEW intent for the URI: a javascript: or vbscript: URI fails with OpenURISchemeBlocked, and a URI that no app can open (or a program with no activity to start it from) with OpenURIUnavailable. Android lets only an app that is on the screen start another.

On Windows it is ShellExecuteExW with the verb "open", which also starts programs, so a URI is refused with OpenURISchemeBlocked when its scheme has one letter (a path of a drive such as C:\x), is javascript: or vbscript:, or is a file: URI of a program or a script (.exe, .bat, .lnk, .ps1, ...); a URI that no program is registered for is OpenURIUnavailable.

It waits for the desktop, so it must be called from a goroutine and not on the UI thread (it fails with DesktopCallOnUIThread there); ctx ends the wait. A URI without a scheme fails with OpenURIInvalid.

Flutter: no counterpart (Flutter apps use the url_launcher plugin)

func TrayIconFromRGBA

func TrayIconFromRGBA(size int, rgba []byte) (ui.WindowIcon, error)

TrayIconFromRGBA makes the icon of a system tray from one square picture: the picture is scaled to each of the sizes 16, 22, 24, 32 and 48 pixels, so the desktop picks the one that fits its panel. rgba holds size*size*4 bytes, the rows from the top, each pixel as red, green, blue and alpha, not premultiplied. It fails with TrayIconInvalid when rgba has another length.

Flutter: no counterpart

Types

type FileFilter

type FileFilter struct {
	// Name is what the menu shows, such as "Images".
	Name string
	// Patterns are globs such as "*.png". The portal matches them exactly as written,
	// so write both cases ("*.png", "*.PNG") for a name that may have either.
	Patterns []string
	// MIMETypes are MIME types such as "image/png".
	MIMETypes []string
}

FileFilter is a kind of file that a file dialog can show: the dialog offers the filters in a menu, and shows only the files that match the one that is chosen.

Flutter: no counterpart (file_selector has XTypeGroup)

type FilesResult

type FilesResult struct {
	// Cancelled is true when the user closed the dialog without choosing. It is a
	// result, not an error; Paths is empty then.
	Cancelled bool
	// Paths are the files or folders that the user chose, as paths of the file
	// system. Inside a Flatpak sandbox they are the paths the document portal made
	// for them.
	Paths []string
	// Filter is the name of the filter that the user left selected, when the dialog
	// said so; empty otherwise.
	Filter string
}

FilesResult is the answer of a file dialog.

Flutter: no counterpart

func OpenFiles

func OpenFiles(ctx context.Context, bc widgets.BuildContext, opts ...OpenFilesOpts) (FilesResult, error)

OpenFiles shows the dialog of the desktop for opening files or folders (org.freedesktop.portal.FileChooser) as a child of the window of bc, and waits for the user. Closing the dialog without a choice is the result with Cancelled set, not an error. There is no fallback: without the portal it fails with FileChooserUnavailable.

It waits for the user, so it must be called from a goroutine and not on the UI thread (it fails with DesktopCallOnUIThread there); ctx closes the dialog.

On Windows it is the common item dialog (IFileOpenDialog), modal to the window of bc (not with NotModal), on a thread of its own; a file filter is its name and its patterns joined by ";" (the MIME types have no counterpart), the first one is selected, and the one the user left selected is FilesResult.Filter. Filters do not apply to folders. A dialog that cannot be made is FileChooserUnavailable and any other failure FileChooserFailed.

Flutter: no counterpart (Flutter apps use the file_selector plugin)

func SaveFile

func SaveFile(ctx context.Context, bc widgets.BuildContext, opts ...SaveFileOpts) (FilesResult, error)

SaveFile shows the dialog of the desktop for saving one file and waits for the user. The path in the result is where to write; the file is not made. See OpenFiles for the rules of the call, the cancel and the failures.

Flutter: no counterpart (Flutter apps use the file_selector plugin)

func SaveFiles

func SaveFiles(ctx context.Context, bc widgets.BuildContext, names []string, opts ...SaveFilesOpts) (FilesResult, error)

SaveFiles shows the dialog of the desktop for saving several files into one folder, with the names given, and waits for the user. The paths in the result are where to write them, in the order of names; none is made. A name is a file name without a folder. See OpenFiles for the rules of the call, the cancel and the failures. On Windows it asks before overwriting a file, and a file name with no extension gets the one of the first pattern of the first filter.

Flutter: no counterpart (Flutter apps use the file_selector plugin)

type NotificationAction

type NotificationAction struct {
	// ID is what OnAction gets when the user chooses the action. The ID "default" is the
	// action of a click on the notification itself, which a desktop may show no button
	// for.
	ID string
	// Label is the text of the button.
	Label string
}

NotificationAction is a button of a notification.

Flutter: no counterpart

type NotificationCloseReason

type NotificationCloseReason int

NotificationCloseReason is why a notification went away.

Flutter: no counterpart

const (
	// NotificationClosedUnknown is a reason that the app does not know.
	//
	// Flutter: no counterpart
	NotificationClosedUnknown NotificationCloseReason = iota
	// NotificationClosedExpired is a notification whose time was up.
	//
	// Flutter: no counterpart
	NotificationClosedExpired
	// NotificationClosedDismissed is a notification that the user dismissed.
	//
	// Flutter: no counterpart
	NotificationClosedDismissed
	// NotificationClosedByApp is a notification that CloseNotification closed.
	//
	// Flutter: no counterpart
	NotificationClosedByApp
)

The values of NotificationCloseReason are those of the Desktop Notifications specification.

type NotificationID

type NotificationID uint32

NotificationID names a notification that is shown: ShowNotification gives it, and CloseNotification and the replacement of a notification take it.

Flutter: no counterpart

func ShowNotification

func ShowNotification(ctx context.Context, bc widgets.BuildContext, summary string, opts ...NotificationOpts) (NotificationID, error)

ShowNotification shows a notification with the summary (its title) through the desktop's notification service (org.freedesktop.Notifications), or, inside a Flatpak sandbox (/.flatpak-info), through the Notification portal. It returns the ID of the notification, for CloseNotification and for replacing it. The actions that the user chooses and the end of the notification come back to NotificationOpts.OnAction and OnClosed on the UI thread. Without the service it fails with NotificationsUnavailable.

It must be called from a goroutine and not on the UI thread (it fails with DesktopCallOnUIThread there); ctx ends the wait for the service.

On the web it uses the Notifications API: the first call asks the user for the permission (the browser shows its prompt, and the call waits for the answer), and a permission that is refused is NotificationsUnavailable. A notification there has a title, a plain-text body, an icon that is a URL and a click: the action with the ID "default" is the click, and no other action is shown (buttons need a service worker). ReplacesID replaces a notification of the page, Timeout is kept by the page, and Category and AppName are not used.

On Android it posts through the NotificationManager, on one channel per urgency (Low is silent, Critical shows over the screen). Android 13 and later ask the user for the permission POST_NOTIFICATIONS at the first call (the call waits for the answer, off the UI thread); a refusal, and a user who turned the app's notifications off, are NotificationsUnavailable, and a refusal is not asked again in the same run. The notification wears the app's icon and name (Icon, Category and AppName are not used). The actions are buttons (the system shows three), and the action with the ID "default" is the click on the notification. ReplacesID replaces a notification with the same ID. Persistent and Critical notifications have no timeout; Timeout closes the others with NotificationClosedExpired. OnClosed gets NotificationClosedDismissed when the user swiped the notification away or clicked it or one of its buttons, NotificationClosedByApp for CloseNotification and NotificationClosedExpired; Android reports nothing else.

On Windows it is a balloon of the notification area (NIF_INFO), which Windows 10 and 11 show as a toast. A balloon has a title (63 characters at most), a body (255; the markup is stripped, and an empty body is a space), the icon of the urgency (Critical is the warning, Low is silent) and, from Icon, a large icon when it is the path of a PNG or JPEG file. It has no buttons: only the action with the ID "default" is used, a click on the balloon (OnAction("default"), then OnClosed with NotificationClosedDismissed); the other actions are not shown. Windows shows one balloon at a time and sets its time itself, so the notifications wait in a queue; Timeout ends the balloon sooner (NotificationClosedExpired), and one that the shell does not end is expired after 15 seconds. ReplacesID replaces a notification that is shown or waits, in place. When Focus Assist or Do not disturb hides the balloon, the app is not told. An app with no notification area is NotificationsUnavailable and a shell that refuses the balloon is WindowsBalloonFailed.

Flutter: no counterpart (Flutter apps use the flutter_local_notifications plugin)

type NotificationOpts

type NotificationOpts struct {
	// Body is the text under the summary. It is plain text: where the desktop reads
	// markup in a body, the characters &, < and > are escaped, unless BodyMarkup is set.
	Body string
	// BodyMarkup says that Body has the markup of the specification (<b>, <i>, <u>,
	// <a href>), which is passed as it is.
	BodyMarkup bool
	// Icon is the name of an icon of the theme, or the path of an image file.
	Icon string
	// Urgency is the importance of the notification.
	Urgency NotificationUrgency
	// Category is a kind of notification from the specification, such as "email.arrived"
	// or "transfer.complete", which desktops use to choose the sound and the place.
	Category string
	// ReplacesID replaces a notification that is shown (the ID that ShowNotification gave)
	// instead of adding another one; the zero value adds one.
	ReplacesID NotificationID
	// Timeout is how long the notification stays; zero is the desktop's default.
	Timeout time.Duration
	// Persistent keeps the notification until the user deals with it, whatever Timeout
	// says.
	Persistent bool
	// AppName is the name of the app that the notification shows; the default is the
	// application ID of the app, or "Glutter".
	AppName string
	// Actions are the buttons of the notification.
	Actions []NotificationAction
	// OnAction is called, on the UI thread, with the ID of the action that the user chose.
	OnAction func(actionID string)
	// OnClosed is called, on the UI thread, when the notification goes away. Inside a
	// Flatpak sandbox the portal does not tell, and it is not called.
	OnClosed func(reason NotificationCloseReason)
}

NotificationOpts are the optional parameters of ShowNotification.

Flutter: no counterpart

type NotificationUrgency

type NotificationUrgency int

NotificationUrgency is how important a notification is. The zero value is NotificationUrgencyUnspecified, which is Normal.

Flutter: no counterpart

const (
	// NotificationUrgencyUnspecified is Normal.
	//
	// Flutter: no counterpart
	NotificationUrgencyUnspecified NotificationUrgency = iota
	// NotificationUrgencyLow is for notifications that can wait, such as a download that
	// started.
	//
	// Flutter: no counterpart
	NotificationUrgencyLow
	// NotificationUrgencyNormal is the usual one.
	//
	// Flutter: no counterpart
	NotificationUrgencyNormal
	// NotificationUrgencyCritical is for what needs the user at once; desktops keep it
	// on screen until it is dealt with.
	//
	// Flutter: no counterpart
	NotificationUrgencyCritical
)

The values of NotificationUrgency.

type OpenFilesOpts

type OpenFilesOpts struct {
	// Title is the title of the dialog; the default is the portal's ("Open File").
	Title string
	// AcceptLabel is the text of the button that accepts the dialog.
	AcceptLabel string
	// Filters are the kinds of file the dialog offers; the first one is chosen when
	// the dialog opens.
	Filters []FileFilter
	// Multiple lets the user choose more than one file. Without it the result has one
	// path.
	Multiple bool
	// Directory makes the dialog choose folders instead of files; Filters do not apply.
	Directory bool
	// CurrentFolder is the folder the dialog opens in.
	CurrentFolder string
	// NotModal leaves the window of the app usable while the dialog is open; by
	// default the dialog blocks it.
	NotModal bool
}

OpenFilesOpts are the optional parameters of OpenFiles.

Flutter: no counterpart

type SaveFileOpts

type SaveFileOpts struct {
	// Title is the title of the dialog; the default is the portal's ("Save File").
	Title string
	// AcceptLabel is the text of the button that accepts the dialog.
	AcceptLabel string
	// Filters are the kinds of file the dialog offers.
	Filters []FileFilter
	// CurrentName is the name that the file starts with, such as "report.pdf".
	CurrentName string
	// CurrentFolder is the folder the dialog opens in.
	CurrentFolder string
	// CurrentFile is the path of the file that the dialog starts with selected, when the
	// user is saving over a file that exists; it sets the folder and the name.
	CurrentFile string
	// NotModal leaves the window of the app usable while the dialog is open.
	NotModal bool
}

SaveFileOpts are the optional parameters of SaveFile.

Flutter: no counterpart

type SaveFilesOpts

type SaveFilesOpts struct {
	// Title is the title of the dialog; the default is the portal's ("Save Files").
	Title string
	// AcceptLabel is the text of the button that accepts the dialog.
	AcceptLabel string
	// CurrentFolder is the folder the dialog opens in.
	CurrentFolder string
	// NotModal leaves the window of the app usable while the dialog is open.
	NotModal bool
}

SaveFilesOpts are the optional parameters of SaveFiles.

Flutter: no counterpart

type SystemTray

type SystemTray struct {
	widgets.StatefulWidget
	// contains filtered or unexported fields
}

SystemTray puts an icon in the system tray (the notification area of the panel) while it is in the widget tree, and keeps the icon, the tip, the status and the menu up to date when it is rebuilt with other values. It builds its child. It uses the StatusNotifierItem protocol with a dbusmenu menu (SPEC §8.9); KDE, XFCE, Cinnamon and others show it, and GNOME shows it only with the AppIndicator extension. On Windows it is a notify icon of the notification area (Shell_NotifyIconW) with a popup menu: the tooltip is 127 characters at most, a click calls OnActivate (without it, and with a Menu, the menu opens), a click with the middle button OnSecondaryActivate, a right click opens the menu, and the icon comes back when Explorer restarts; the status, the attention icon and OnScroll have no counterpart there, and the icon is the picture nearest to the size of a small icon. When no desktop shows icons, the error TrayUnavailable is reported once through the error reporter of the binding and the widget is just its child. An app has one tray at a time; a second one reports TrayDuplicate.

Flutter: no counterpart

func NewSystemTray

func NewSystemTray(icon ui.WindowIcon, child widgets.Widget, opts ...SystemTrayOpts) *SystemTray

NewSystemTray creates the widget. The icon is a name of the icon theme, pictures (TrayIconFromRGBA), or both; child is built in place of the widget and may be nil.

Flutter: no counterpart

func (*SystemTray) Child

func (w *SystemTray) Child() widgets.Widget

Child is the widget that is built in place of the tray.

Flutter: no counterpart

func (*SystemTray) CreateState

func (w *SystemTray) CreateState() widgets.State

CreateState creates the state.

Flutter: no counterpart

func (*SystemTray) Icon

func (w *SystemTray) Icon() ui.WindowIcon

Icon is the icon of the tray.

Flutter: no counterpart

type SystemTrayOpts

type SystemTrayOpts struct {
	// Key is the widget's key.
	Key foundation.Key
	// ID names the icon to the desktop (the Id of the StatusNotifierItem). The default is
	// the application ID of the window, or "glutter".
	ID string
	// Title is the name of the app in the places that list the icons; the default is
	// the application ID of the window, or "Glutter".
	Title string
	// Tooltip is the title of the tip that shows when the pointer rests on the icon.
	Tooltip string
	// TooltipBody is the text under the title of the tip.
	TooltipBody string
	// Status is how the icon is shown.
	Status TrayStatus
	// AttentionIcon is the icon that is shown with TrayStatusNeedsAttention.
	AttentionIcon ui.WindowIcon
	// OnActivate is called, on the UI thread, when the user clicks the icon (the primary
	// action). Without it, and with a Menu, a click opens the menu.
	OnActivate func()
	// OnSecondaryActivate is called when the user clicks the icon with the middle button.
	OnSecondaryActivate func()
	// OnScroll is called when the user scrolls over the icon: delta is the amount, and
	// horizontal says the direction.
	OnScroll func(delta int, horizontal bool)
	// Menu is the menu that opens from the icon.
	Menu []TrayMenuEntry
}

SystemTrayOpts are the optional parameters of NewSystemTray.

Flutter: no counterpart

type TrayMenuEntry

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

TrayMenuEntry is an entry of the menu of a system tray icon: a TrayMenuItem or a separator.

Flutter: no counterpart

type TrayMenuItem

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

TrayMenuItem is an item of the menu of a system tray icon: a label that the user chooses to call a function, or, with children, a submenu.

Flutter: no counterpart

func NewTrayMenuItem

func NewTrayMenuItem(label string, onPressed func(), opts ...TrayMenuItemOpts) *TrayMenuItem

NewTrayMenuItem creates an item of the menu of a system tray. onPressed is called on the UI thread when the user chooses the item; it may be nil. A single underscore in the label is kept as it is (the menu protocol's mnemonic is not used).

Flutter: no counterpart

func NewTrayMenuSubmenu

func NewTrayMenuSubmenu(label string, children []TrayMenuEntry, opts ...TrayMenuItemOpts) *TrayMenuItem

NewTrayMenuSubmenu creates an item that opens a submenu of the entries.

Flutter: no counterpart

func (*TrayMenuItem) Children

func (i *TrayMenuItem) Children() []TrayMenuEntry

Children are the entries of the submenu, none for an item that is not one.

Flutter: no counterpart

func (*TrayMenuItem) Label

func (i *TrayMenuItem) Label() string

Label is the text of the item.

Flutter: no counterpart

type TrayMenuItemOpts

type TrayMenuItemOpts struct {
	// Disabled greys the item out and makes it do nothing.
	Disabled bool
	// Hidden leaves the item out of the menu.
	Hidden bool
	// Checkable gives the item a check mark; Checked says whether it is set. The
	// item does not change by itself when the user chooses it: the app rebuilds the
	// tray with the new value.
	Checkable bool
	// Radio makes a checkable item a radio button instead of a check box.
	Radio bool
	// Checked is the state of a checkable item.
	Checked bool
	// Icon is the name of an icon of the icon theme.
	Icon string
}

TrayMenuItemOpts are the optional parameters of NewTrayMenuItem.

Flutter: no counterpart

type TrayMenuSeparator

type TrayMenuSeparator struct{}

TrayMenuSeparator is a line between two groups of items.

Flutter: no counterpart

func NewTrayMenuSeparator

func NewTrayMenuSeparator() *TrayMenuSeparator

NewTrayMenuSeparator creates a separator.

Flutter: no counterpart

type TrayStatus

type TrayStatus int

TrayStatus is how the desktop shows a system tray icon.

Flutter: no counterpart

const (
	// TrayStatusUnspecified is TrayStatusActive.
	//
	// Flutter: no counterpart
	TrayStatusUnspecified TrayStatus = iota
	// TrayStatusActive is an icon that is shown.
	//
	// Flutter: no counterpart
	TrayStatusActive
	// TrayStatusPassive is an icon the desktop may hide, because nothing happens.
	//
	// Flutter: no counterpart
	TrayStatusPassive
	// TrayStatusNeedsAttention shows the attention icon, and desktops draw the eye to it.
	//
	// Flutter: no counterpart
	TrayStatusNeedsAttention
)

The values of TrayStatus.

Jump to

Keyboard shortcuts

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