Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Features

  • 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.

Usage

Parse a desktop entry file

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

final file = File("desktop-entry.desktop");
DesktopEntry desktopEntry = await DesktopEntry.parseFile(file);

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')];

Find an icon

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.

About

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

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages