free-launch 0.2.9

A simple fuzzy launcher written in Rust.
Documentation
use crate::{
    launch_entries::launch_entry_trait::LaunchId as _,
    model::{desktop_item::DesktopItem, invocation::Invocation},
};

/// Represents an update to a launchable item in the search index.
///
/// This enum is used to communicate changes to items that can be launched,
/// such as new desktop entries being discovered or invocations being recorded.
pub enum ItemUpdate {
    Invocation(Invocation),
    DesktopItem(DesktopItem),
    // LaunchEntry(Shared<LaunchEntry>),
}

impl ItemUpdate {
    pub(crate) fn id(&self) -> String {
        match self {
            ItemUpdate::Invocation(invocation) => invocation.id().to_owned(),
            ItemUpdate::DesktopItem(desktop_item) => desktop_item.id(),
            // ItemUpdate::LaunchEntry(shared) => shared.id(),
        }
    }

    pub(crate) fn name(&self) -> String {
        match self {
            ItemUpdate::Invocation(invocation) => invocation.name().to_owned(),
            ItemUpdate::DesktopItem(desktop_item) => desktop_item.name().to_owned(),
            // ItemUpdate::LaunchEntry(shared) => shared.name().to_owned(),
        }
    }

    pub(crate) fn path(&self) -> String {
        match self {
            ItemUpdate::Invocation(invocation) => invocation.item_path.clone(),
            ItemUpdate::DesktopItem(desktop_item) => {
                desktop_item.desktop_file_path.to_string_lossy().to_string()
            } // ItemUpdate::LaunchEntry(shared) => shared.file_path(),
        }
    }
}