freedesktop_desktop_entry 0.2.2 copy "freedesktop_desktop_entry: ^0.2.2" to clipboard
freedesktop_desktop_entry: ^0.2.2 copied to clipboard

outdated

A Dart package for parsing freedesktop (XDG) desktop entries on Linux.

A Dart package for parsing freedesktop (XDG) desktop entries on Linux.

Features #

  • obtain values by key
  • obtain localized values
  • obtain values from action groups
  • localize values according to the locale matching rules of the specification
  • localize entire desktop entries

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.

Usage #

Parse a desktop entry file #

import 'package:freedesktop_desktop_entry/freedesktop_desktop_entry.dart';
import 'dart:io';

final file = File("desktop-entry.desktop");
String content = await file.readAsString();
DesktopEntry desktopEntry = DesktopEntry.parse(content);

Localize an entire desktop entry #

LocalizedDesktopEntry localizedDesktopEntry = desktopEntry.localize(lang: 'fr', country: 'BE');

Get a localized value #

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.

Get the default value #

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();

Get a value by exact locale #

String? frenchComment = desktopEntry.entries[DesktopEntryKey.comment.string]?.localizedValues[Locale(lang: 'fr', country: 'BE')];
3
likes
0
points
88
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package for parsing freedesktop (XDG) desktop entries on Linux.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

freezed_annotation

More

Packages that depend on freedesktop_desktop_entry