Extracts the app-launcher substance (desktop-entry parsing, fuzzy matching/ranking, launch history, launching) out of breadbox into a reusable ecosystem crate, so breadbar's future embedded capsule and breadbox's overlay window can share one implementation instead of two (THEME_SYSTEM_PLAN.md Phase 4/6a). The GTK4 results-list widget lives behind a `gtk` feature, mirroring bread-theme's `gtk`/`adw` gating, so a headless consumer isn't forced to link GTK. Adds unit tests for fuzzy_score/matches_term/priority_rank, which were previously untested pure functions inside breadbox's main.rs.
26 lines
735 B
Rust
26 lines
735 B
Rust
use std::{fs, path::PathBuf};
|
|
|
|
pub struct IconCache {
|
|
pub dir: PathBuf,
|
|
}
|
|
|
|
impl IconCache {
|
|
/// `app` picks the cache subdirectory (see [`crate::cache_dir`]) — pass
|
|
/// the same name across a process's calls so `path_for` and
|
|
/// `manifest_path` agree on where icons live.
|
|
pub fn new(app: &str) -> Self {
|
|
IconCache { dir: crate::paths::cache_dir(app).join("icons") }
|
|
}
|
|
|
|
pub fn path_for(&self, icon_name: &str) -> PathBuf {
|
|
self.dir.join(format!("{}.png", icon_name))
|
|
}
|
|
|
|
pub fn manifest_path(app: &str) -> PathBuf {
|
|
crate::paths::cache_dir(app).join("manifest.json")
|
|
}
|
|
|
|
pub fn ensure_dir(&self) -> std::io::Result<()> {
|
|
fs::create_dir_all(&self.dir)
|
|
}
|
|
}
|