feat: hide duplicate desktop files by default

This commit is contained in:
imgurbot12 2024-07-10 00:34:46 -07:00
parent ab1b68e7db
commit e6b8018cb5
2 changed files with 19 additions and 2 deletions

View File

@ -6,9 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4.5.9", features = ["derive"] }
freedesktop-desktop-entry = "0.5.2"
freedesktop-icons = "0.2.6"
log = "0.4.21"
itertools = "0.13.0"
once_cell = "1.19.0"
rayon = "1.10.0"
regex = "1.10.4"

View File

@ -1,7 +1,9 @@
use std::fs::read_to_string;
use std::path::PathBuf;
use clap::Parser;
use freedesktop_desktop_entry::{DesktopEntry, Iter};
use itertools::Itertools;
use once_cell::sync::Lazy;
use rayon::prelude::*;
use regex::Regex;
@ -117,7 +119,15 @@ fn assign_icon(icon: String, map: &icons::IconMap) -> Option<String> {
Some(icon)
}
#[derive(Debug, Parser)]
struct Cli {
/// Only Allow Unique Desktop Entries
#[clap(short, long)]
non_unique: bool,
}
fn main() {
let cli = Cli::parse();
let locale = Some("en");
let sizes = vec![64, 32, 96, 22, 128];
@ -130,6 +140,13 @@ fn main() {
let app_paths = data_dirs("applications");
let mut desktops: Vec<Entry> = Iter::new(app_paths)
.into_iter()
.unique_by(|f| match cli.non_unique {
true => f.to_str().map(|s| s.to_owned()),
false => f
.file_name()
.and_then(|n| n.to_str())
.map(|s| s.to_string()),
})
.filter_map(|f| parse_desktop(&f, locale))
.map(|mut e| {
e.icon = e.icon.and_then(|s| assign_icon(s, &icons));