From fe37c15f955de9450b8ca13512619b4647c92342 Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Sat, 25 Dec 2021 21:16:19 +0100 Subject: [PATCH] feat: deduplicate desktop entries We don't want duplicate entries because there are not distinguishable by Name. People will sometimes override in there HOME dir some desktop files entries in order to do some modifications. The actual reading order is good and so `unique_by` name do the job. --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 1 + src/desktop.rs | 2 ++ 3 files changed, 19 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index cd88c52..3da9a07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,6 +152,12 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e" +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "fake-simd" version = "0.1.2" @@ -185,6 +191,15 @@ dependencies = [ "typenum", ] +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "0.4.7" @@ -791,6 +806,7 @@ dependencies = [ "dlib", "fontconfig", "fuzzy-matcher", + "itertools", "lazy_static", "libpulse-binding", "memmap", diff --git a/Cargo.toml b/Cargo.toml index 352e88d..e2d8710 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ rust-ini = "0.14" shlex = "0.1" timerfd = "1.0.0" walkdir = "2.3.2" +itertools = "0.10.3" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", optional = true } diff --git a/src/desktop.rs b/src/desktop.rs index 22bda1f..af2c36e 100644 --- a/src/desktop.rs +++ b/src/desktop.rs @@ -1,5 +1,6 @@ extern crate ini; use ini::{Ini, ParseOption}; +use itertools::Itertools; use std::cmp::Ordering; use std::env; use std::error::Error; @@ -107,5 +108,6 @@ pub fn load_desktop_files() -> Vec { .filter(|d| { !d.hidden && !d.no_display && (d.entry_type == "Application" || d.entry_type == "Link") }) + .unique_by(|x| x.name.clone()) .collect() }