Documentation
¶
Overview ¶
Package desktopentry is gio's desktop-entry layer: the key-file parser, the XDG application list with gio's load and visibility rules, Exec expansion, and launching.
Package desktopentry reads freedesktop desktop entries the way gio does (GKeyFile + GDesktopAppInfo): the key-file grammar with its escapes and localized keys, the application directories and desktop ids, visibility (NoDisplay, Hidden, OnlyShowIn/NotShowIn, TryExec), Exec field-code expansion, and launching - pure Go, no gio.
Index ¶
- Constants
- Variables
- func ApplicationDirs() []string
- func CurrentDesktops() []string
- func Describe(dirs []string, appID string) (name, icon string)
- func FileID(appID string) string
- func Icon(id string, dirs []string) (string, bool)
- func Languages() []string
- func MimeAppsLists() []string
- func SetDefault(id, mimeType string) error
- type App
- func (a App) ActionName(action string) string
- func (a App) Actions() []string
- func (a App) AppID() string
- func (a App) Categories() string
- func (a App) Comment() string
- func (a App) DisplayName() string
- func (a App) Exec() string
- func (a App) ExpandExec(execLine string) ([]string, error)
- func (a App) GenericName() string
- func (a App) Icon() string
- func (a App) Keywords() []string
- func (a App) Launch() error
- func (a App) LaunchAction(action string) error
- func (a App) MimeTypes() []string
- func (a App) ShouldShow() bool
- func (a App) ShownIn(desktops []string) bool
- func (a App) String(key string) (string, bool)
- func (a App) Terminal() bool
- type KeyFile
- func (kf *KeyFile) Bool(group, key string) bool
- func (kf *KeyFile) HasGroup(group string) bool
- func (kf *KeyFile) List(group, key string) []string
- func (kf *KeyFile) LocaleList(group, key string) []string
- func (kf *KeyFile) LocaleString(group, key string) (string, bool)
- func (kf *KeyFile) Raw(group, key string) (string, bool)
- func (kf *KeyFile) String(group, key string) (string, bool)
- type Link
Constants ¶
const DesktopGroup = "Desktop Entry"
DesktopGroup is the main group of a desktop entry.
Variables ¶
var ErrMalformed = errors.New("desktopentry: malformed key file")
ErrMalformed is a key file that does not parse.
Functions ¶
func ApplicationDirs ¶
func ApplicationDirs() []string
ApplicationDirs is the XDG applications search order: $XDG_DATA_HOME/applications (or ~/.local/share/applications), then each $XDG_DATA_DIRS entry (or /usr/local/share:/usr/share).
func Describe ¶
Describe names the app a desktop-portal request comes from, for the dialogs asking on its behalf: the desktop entry's display name and icon for appID (a desktop id without ".desktop"), the bare id when no entry matches, and "An application" for a host app (no id).
func Icon ¶
Icon returns the Icon key of the desktop entry with the given id (with or without the .desktop suffix), searching dirs in order; false when no entry loads or it names no icon. It is the lookup gio's DesktopAppInfo::new does for the media module's application icons (media helpers.rs lookup_desktop_entry).
func Languages ¶
func Languages() []string
Languages is g_get_language_names for the message locale: LC_ALL, then LC_MESSAGES, then LANG, widened from lang_COUNTRY@MOD to lang_COUNTRY, lang@MOD, and lang. C and POSIX name no language.
func MimeAppsLists ¶
func MimeAppsLists() []string
MimeAppsLists is the mimeapps.list search order, highest priority first: in $XDG_CONFIG_HOME, each $XDG_CONFIG_DIRS entry, then each applications directory, the current desktops' $desktop-mimeapps.list before the plain mimeapps.list.
func SetDefault ¶
SetDefault is g_app_info_set_as_default_for_type: id becomes the default for mimeType in the user's mimeapps.list and the first of its added associations; the rest of the file is kept.
Types ¶
type App ¶
type App struct {
// ID is the desktop id: the path under applications/ with '/' as
// '-' (org.gnome.Nautilus.desktop, kde4-dolphin.desktop).
ID string
// Path is the file the entry was read from.
Path string
// contains filtered or unexported fields
}
App is one application desktop entry, the GDesktopAppInfo a gio app list yields.
func AllApps ¶
AllApps is g_app_info_get_all: every loadable Type=Application entry, one per desktop id. An entry is not loadable when it is Hidden, when its TryExec or its Exec program is not installed, or when its Exec does not parse - gio's load_from_keyfile rules, so a remnant of an uninstalled package does not show.
func FindApps ¶
FindApps looks the desktop ids up in the application dirs in one walk, in the order given, skipping the ones not found or loadable.
func RecommendedFor ¶
RecommendedFor is g_app_info_get_recommended_for_type: the installed apps for mimeType - the default first, then the added associations, then every app declaring the type - without the removed ones.
func (App) ActionName ¶
ActionName is an action's localized Name.
func (App) AppID ¶
AppID is the application id the entry is for: the desktop id without ".desktop", the form the desktop portal speaks.
func (App) DisplayName ¶
DisplayName is g_app_info_get_display_name: X-GNOME-FullName, else Name, localized.
func (App) ExpandExec ¶
ExpandExec is gio's expand_macro over an Exec line launched with no files: %f %F %u %U vanish, %i is --icon <Icon>, %c the name, %k the entry's path, %% a percent; the deprecated codes vanish. A token that was only a vanishing code is dropped.
func (App) GenericName ¶
GenericName is the localized GenericName.
func (App) Launch ¶
Launch starts the application with no files (g_app_info_launch). A DBusActivatable entry is activated over the session bus (org.freedesktop.Application.Activate); if that fails, or the entry is not activatable, its Exec runs detached in its Path.
func (App) LaunchAction ¶
LaunchAction runs a desktop action (g_desktop_app_info_launch_action): ActivateAction over D-Bus for an activatable entry, else the action group's Exec.
func (App) ShouldShow ¶
ShouldShow is g_app_info_should_show: not NoDisplay, and shown in the current desktop per OnlyShowIn/NotShowIn against $XDG_CURRENT_DESKTOP.
func (App) ShownIn ¶
ShownIn is g_desktop_app_info_get_show_in over explicit desktop names: the first desktop listed in OnlyShowIn or NotShowIn decides; none listed means shown unless OnlyShowIn restricts it.
type KeyFile ¶
type KeyFile struct {
// contains filtered or unexported fields
}
KeyFile is a parsed key file: groups of key=value lines, with the localized variants (Name[de]) kept under their full key.
func LoadKeyFile ¶
LoadKeyFile reads and parses a key file from disk.
func ParseKeyFile ¶
ParseKeyFile parses a key file. Blank lines and # comments are skipped; a key before any [group] or a line without '=' is malformed, as GKeyFile refuses them.
func (*KeyFile) Bool ¶
Bool reads a boolean key: exactly "true" or "false" (GKeyFile also takes 1 and 0); absent or anything else is false.
func (*KeyFile) LocaleList ¶
LocaleList is List over the best localized variant.
func (*KeyFile) LocaleString ¶
LocaleString returns the best localized variant of a key (Name[de_DE], Name[de], ...), else the plain key.