desktopentry

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 16 Imported by: 0 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 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

View Source
const DesktopGroup = "Desktop Entry"

DesktopGroup is the main group of a desktop entry.

Variables

View Source
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 CurrentDesktops

func CurrentDesktops() []string

CurrentDesktops splits $XDG_CURRENT_DESKTOP.

func Describe

func Describe(dirs []string, appID string) (name, icon string)

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 FileID

func FileID(appID string) string

FileID is the desktop id of the entry for appID, the inverse of AppID.

func Icon

func Icon(id string, dirs []string) (string, bool)

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

func SetDefault(id, mimeType string) error

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.

func SetDefaults

func SetDefaults(id string, mimeTypes []string) error

SetDefaults makes id the default for every one of mimeTypes, as SetDefault does for one, in one atomic replacement of the user's mimeapps.list: other groups, keys and comments are kept byte for byte, and a desktop-specific list is read by Default but never written.

func SetKey

func SetKey(data []byte, group, key, value string) []byte

SetKey is data, a key file, with key=value in group: the key's line replaced, or added at the end of its group, or the group added at the end; every other line is kept byte for byte.

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

func AllApps(dirs []string) []App

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 Default

func Default(dirs, lists []string, mimeType string) (App, bool)

Default is the app mimeType opens with, as xdg-mime query default answers: the first installed default the lists name, in their order and not removed by a list above, else the first installed app that declares the type.

func FindApp

func FindApp(dirs []string, id string) (App, bool)

FindApp looks one desktop id up in the application dirs.

func FindApps

func FindApps(dirs, ids []string) []App

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 LoadApp

func LoadApp(id, path string) (App, bool)

LoadApp reads one entry, applying gio's load rules (see AllApps).

func RecommendedFor

func RecommendedFor(dirs, lists []string, mimeType string) []App

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

func (a App) ActionName(action string) string

ActionName is an action's localized Name.

func (App) Actions

func (a App) Actions() []string

Actions is the Actions list: the ids of [Desktop Action <id>] groups.

func (App) AppID

func (a App) AppID() string

AppID is the application id the entry is for: the desktop id without ".desktop", the form the desktop portal speaks.

func (App) Categories

func (a App) Categories() string

Categories is the raw Categories string.

func (App) Comment

func (a App) Comment() string

Comment is the localized Comment (gio's description).

func (App) DisplayName

func (a App) DisplayName() string

DisplayName is g_app_info_get_display_name: X-GNOME-FullName, else Name, localized.

func (App) Exec

func (a App) Exec() string

Exec is the Exec line as written (gio's commandline).

func (App) ExpandExec

func (a App) ExpandExec(execLine string) ([]string, error)

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

func (a App) GenericName() string

GenericName is the localized GenericName.

func (App) Icon

func (a App) Icon() string

Icon is the Icon key: a theme name or an absolute path; empty for none.

func (App) Keywords

func (a App) Keywords() []string

Keywords is the localized Keywords list.

func (App) Launch

func (a App) Launch() error

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

func (a App) LaunchAction(action string) error

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) MimeTypes

func (a App) MimeTypes() []string

MimeTypes is the entry's MimeType list.

func (App) ShouldShow

func (a App) ShouldShow() bool

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

func (a App) ShownIn(desktops []string) bool

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.

func (App) String

func (a App) String(key string) (string, bool)

String returns a raw Desktop Entry key, for callers that need a key App does not model.

func (App) Terminal

func (a App) Terminal() bool

Terminal reports Terminal=true.

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

func LoadKeyFile(path string) (*KeyFile, error)

LoadKeyFile reads and parses a key file from disk.

func ParseKeyFile

func ParseKeyFile(data []byte) (*KeyFile, error)

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

func (kf *KeyFile) Bool(group, key string) bool

Bool reads a boolean key: exactly "true" or "false" (GKeyFile also takes 1 and 0); absent or anything else is false.

func (*KeyFile) HasGroup

func (kf *KeyFile) HasGroup(group string) bool

HasGroup reports whether the group exists.

func (*KeyFile) List

func (kf *KeyFile) List(group, key string) []string

List reads a ;-separated list, escapes decoded and \; kept literal.

func (*KeyFile) LocaleList

func (kf *KeyFile) LocaleList(group, key string) []string

LocaleList is List over the best localized variant.

func (*KeyFile) LocaleString

func (kf *KeyFile) LocaleString(group, key string) (string, bool)

LocaleString returns the best localized variant of a key (Name[de_DE], Name[de], ...), else the plain key.

func (*KeyFile) Raw

func (kf *KeyFile) Raw(group, key string) (string, bool)

Raw returns a key's value with no unescaping.

func (*KeyFile) ShownIn

func (kf *KeyFile) ShownIn(desktops []string) bool

ShownIn is the entry's OnlyShowIn and NotShowIn applied to desktops, for a key file read whatever its Hidden or Type (an autostart entry).

func (*KeyFile) String

func (kf *KeyFile) String(group, key string) (string, bool)

String returns a key's value with the string escapes (\s \n \t \r \\) decoded.

type Link struct {
	ID   string
	Name string
	URL  string
	Icon string
}

Link is a Type=Link entry, which gio's app list skips and rofi shows.

func Links(dirs []string) []Link

Links lists the Type=Link entries gio's app list skips, earlier dirs winning a desktop id; NoDisplay and Hidden ones are left out, and an entry without a name or URL is not a link.

type MimeApps

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

MimeApps is the mimeapps.list files that exist, read once, highest priority first.

func ReadMimeApps

func ReadMimeApps(lists []string) MimeApps

ReadMimeApps reads the lists that exist, in order.

func (MimeApps) Default

func (m MimeApps) Default(all []App, mimeType string) (App, bool)

Default is the package Default over apps already listed and lists already read, for a caller resolving many types from one scan.

Jump to

Keyboard shortcuts

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