Skip to content

BL-CZY/desktop_file_parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Freedesktop Desktop Entry Parser

A Rust library for parsing and manipulating Linux .desktop files according to the freedesktop.org Desktop Entry Specification.

Features

  • Full support for Desktop Entry Specification v1.5
  • Locale-aware string handling
  • Icon resolution using freedesktop icon theme
  • Support for desktop actions
  • Strong type safety with Rust's type system

Usage

Add this to your Cargo.toml:

[dependencies]
freedesktop-file-parser = "0.3.0"

Basic Example

use freedesktop_file_parser::{parse, EntryType};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let content = r#"[Desktop Entry]
Type=Application
Name=Firefox
Exec=firefox %u
Icon=firefox
Categories=Network;WebBrowser;
    "#;

    let desktop_file = parse(content)?;
    
    // Access basic properties
    println!("Name: {}", desktop_file.entry.name.default);
    
    // Check entry type
    if let EntryType::Application(app) = &desktop_file.entry.entry_type {
        println!("Exec: {}", app.exec.as_ref().unwrap());
    }

    Ok(())
}

Handling Localized Strings

use freedesktop_file_parser::LocaleString;

// Access different translations
if let Some(de_name) = desktop_file.entry.name.variants.get_variant("de") {
    println!("German name: {}", de_name);
}

Working with Actions

// Access application actions
for (action_name, action) in &desktop_file.actions {
    println!("Action: {}", action.name.default);
    if let Some(exec) = &action.exec {
        println!("Action command: {}", exec);
    }
}

Supported Fields

The library supports all standard fields from the Desktop Entry Specification, including:

  • Basic fields (Type, Name, GenericName, NoDisplay, Comment, Icon)
  • Application fields (Exec, TryExec, Path, Terminal, MimeType, Categories)
  • Startup fields (StartupNotify, StartupWMClass)
  • Display fields (Hidden, OnlyShowIn, NotShowIn)
  • Actions
  • DBus activation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Status

This project is under active development. While it implements the full specification, please report any bugs or missing features.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6

Languages