Filter out duplicated dirs
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -1087,6 +1087,15 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.9"
|
||||
@@ -1628,6 +1637,7 @@ dependencies = [
|
||||
"freedesktop-icons-greedy",
|
||||
"glam",
|
||||
"image",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
"linicon-theme",
|
||||
"manifest-dir-macros",
|
||||
|
||||
@@ -13,6 +13,7 @@ ez-pixmap = "0.2.2"
|
||||
freedesktop-icons-greedy = "0.2.5"
|
||||
glam = { version = "0.24.0", features = ["mint"] }
|
||||
image = "0.24.5"
|
||||
itertools = "0.11.0"
|
||||
lazy_static = "1.4.0"
|
||||
linicon-theme = "1.2.0"
|
||||
manifest-dir-macros = "0.1.16"
|
||||
|
||||
@@ -48,7 +48,6 @@ struct AppGrid {
|
||||
impl AppGrid {
|
||||
fn new(client: &Client) -> Self {
|
||||
let apps = get_desktop_files()
|
||||
.into_iter()
|
||||
.filter_map(|d| parse_desktop_file(d).ok())
|
||||
.filter(|d| !d.no_display)
|
||||
.enumerate()
|
||||
|
||||
@@ -98,7 +98,6 @@ impl AppHexGrid {
|
||||
fn new(client: &Client) -> Self {
|
||||
let button = Button::new(client).unwrap();
|
||||
let mut desktop_files: Vec<DesktopFile> = get_desktop_files()
|
||||
.into_iter()
|
||||
.filter_map(|d| parse_desktop_file(d).ok())
|
||||
.filter(|d| !d.no_display)
|
||||
.collect();
|
||||
|
||||
60
src/xdg.rs
60
src/xdg.rs
@@ -1,5 +1,6 @@
|
||||
use color_eyre::eyre::Result;
|
||||
use freedesktop_icons_greedy::lookup;
|
||||
use itertools::Itertools;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use resvg::render;
|
||||
@@ -70,7 +71,9 @@ fn get_data_dirs() -> Vec<PathBuf> {
|
||||
.filter_map(|dir| PathBuf::from_str(dir).ok())
|
||||
.chain(dirs::home_dir().into_iter().map(|d| d.join(".local/share"))) // $HOME/.local/share
|
||||
.chain(PathBuf::from_str("/usr/share").into_iter()) // /usr/share
|
||||
.chain(PathBuf::from_str("/usr/local/share").into_iter()) // /usr/local/share
|
||||
.filter(|dir| dir.exists() && dir.is_dir())
|
||||
.unique()
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -82,11 +85,9 @@ fn get_app_dirs() -> Vec<PathBuf> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn get_desktop_files() -> Vec<PathBuf> {
|
||||
let desktop_extension = OsString::from_str("desktop").unwrap();
|
||||
pub fn get_desktop_files() -> impl Iterator<Item = PathBuf> {
|
||||
// Get the list of directories to search
|
||||
let app_dirs = get_app_dirs();
|
||||
app_dirs
|
||||
get_app_dirs()
|
||||
.into_iter()
|
||||
.flat_map(|dir| {
|
||||
// Follow symlinks and recursively search directories
|
||||
@@ -97,17 +98,14 @@ pub fn get_desktop_files() -> Vec<PathBuf> {
|
||||
.filter(|entry| entry.file_type().is_file())
|
||||
.map(|entry| entry.path().to_path_buf())
|
||||
})
|
||||
.filter(|path| path.extension() == Some(&desktop_extension))
|
||||
.collect::<Vec<PathBuf>>()
|
||||
.filter(|path| path.extension() == Some(&OsString::from_str("desktop").unwrap()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_desktop_files() {
|
||||
let desktop_files = get_desktop_files();
|
||||
dbg!(&desktop_files);
|
||||
assert!(desktop_files
|
||||
.iter()
|
||||
.any(|file| file.ends_with("gimp.desktop")));
|
||||
let mut desktop_files = get_desktop_files();
|
||||
assert!(desktop_files.any(|file| file.ends_with("gimp.desktop")));
|
||||
dbg!(desktop_files.collect::<Vec<PathBuf>>());
|
||||
}
|
||||
|
||||
pub fn parse_desktop_file(path: PathBuf) -> Result<DesktopFile, String> {
|
||||
@@ -306,29 +304,25 @@ impl Icon {
|
||||
}
|
||||
|
||||
pub fn cached_process(self, size: u16) -> Result<Icon, std::io::Error> {
|
||||
if !IMAGE_CACHE.lock().unwrap().map.contains_key(&(
|
||||
self.path
|
||||
.with_extension("")
|
||||
.file_name()
|
||||
let image_name = self
|
||||
.path
|
||||
.with_extension("")
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_owned();
|
||||
|
||||
if !IMAGE_CACHE
|
||||
.lock()
|
||||
.unwrap()
|
||||
.map
|
||||
.contains_key(&(image_name.clone(), size))
|
||||
{
|
||||
IMAGE_CACHE
|
||||
.lock()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_owned(),
|
||||
size,
|
||||
)) {
|
||||
IMAGE_CACHE.lock().unwrap().insert(
|
||||
(
|
||||
self.path
|
||||
.with_extension("")
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_owned(),
|
||||
size,
|
||||
),
|
||||
self.path.clone(),
|
||||
);
|
||||
.insert((image_name, size), self.path.clone());
|
||||
IMAGE_CACHE.lock().unwrap().save();
|
||||
}
|
||||
match self.icon_type {
|
||||
|
||||
Reference in New Issue
Block a user