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 ¶
- func CloseNotification(ctx context.Context, bc widgets.BuildContext, id NotificationID) error
- func InstallBus(b *widgets.WidgetsBinding, bus dbus.Bus)
- func KeepScreenOn(bc widgets.BuildContext, on bool) error
- func OpenURI(ctx context.Context, bc widgets.BuildContext, uri string) error
- func TrayIconFromRGBA(size int, rgba []byte) (ui.WindowIcon, error)
- type FileFilter
- type FilesResult
- func OpenFiles(ctx context.Context, bc widgets.BuildContext, opts ...OpenFilesOpts) (FilesResult, error)
- func SaveFile(ctx context.Context, bc widgets.BuildContext, opts ...SaveFileOpts) (FilesResult, error)
- func SaveFiles(ctx context.Context, bc widgets.BuildContext, names []string, ...) (FilesResult, error)
- type NotificationAction
- type NotificationCloseReason
- type NotificationID
- type NotificationOpts
- type NotificationUrgency
- type OpenFilesOpts
- type SaveFileOpts
- type SaveFilesOpts
- type SystemTray
- type SystemTrayOpts
- type TrayMenuEntry
- type TrayMenuItem
- type TrayMenuItemOpts
- type TrayMenuSeparator
- type TrayStatus
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 ¶
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.
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.
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.
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.
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. 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.