A Dart package for parsing freedesktop (XDG) desktop entries on Linux.
- Obtain values by key, including action groups.
- Obtain localized values.
- Icon lookup.
This package provides the DesktopEntryKey enum for convenience, but it doesn't make any assumptions
about value types and whether a key is required or not. All keys are considered optional.
import 'package:freedesktop_desktop_entry/freedesktop_desktop_entry.dart';
import 'dart:io';
final file = File("desktop-entry.desktop");
DesktopEntry desktopEntry = await DesktopEntry.parseFile(file);LocalizedDesktopEntry localizedDesktopEntry = desktopEntry.localize(lang: 'fr', country: 'BE');String? localizedComment = localizedDesktopEntry.entries[DesktopEntryKey.comment.string];
// OR
String? localizedComment = desktopEntry.entries[DesktopEntryKey.comment.string]?.localize(lang: 'fr', country: 'BE');Unless you are only interested in a few fields, prefer localizing the entire desktop entry to avoid having to specify the locale every time.
The localize methods will localize the values according to official locale matching rules, and
uses the default value if no locale is matched. This is most probably what you want to do.
String? name = desktopEntry.entries[DesktopEntryKey.name.string]?.value;
bool? terminal = desktopEntry.entries[DesktopEntryKey.terminal.string]?.value.getBoolean();
List<String>? keywords = desktopEntry.entries[DesktopEntryKey.keywords.string]?.value.getStringList();
bool? startupNotify = desktopEntry.entries['X-KDE-StartupNotify']?.value.getBoolean();String? frenchComment = desktopEntry.entries[DesktopEntryKey.comment.string]?.localizedValues[Locale(lang: 'fr', country: 'BE')];final themeList = await FreedesktopIconTheme.installedThemes;
final theme = await FreedesktopIconTheme.loadTheme(theme: themeList.first);
File? file = await theme.findIcon(
IconQuery(
name: 'firefox',
size: 32,
scale: 2,
extensions: ['png'],
),
);If new icons are installed, the next time you call FreedesktopIconThemes.findIcon it will index the theme once again
before returning you an icon.