mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 18:51:04 +02:00
fix(launcher): incorrectly resolving some applications
Potentially also fixes some mismatches with icons. Fixes #222.
This commit is contained in:
parent
fc820746a4
commit
4ca17d1337
1 changed files with 61 additions and 26 deletions
|
@ -65,33 +65,40 @@ pub fn find_desktop_file(app_id: &str) -> Option<PathBuf> {
|
||||||
// this is necessary to invalidate the cache
|
// this is necessary to invalidate the cache
|
||||||
let files = find_desktop_files();
|
let files = find_desktop_files();
|
||||||
|
|
||||||
if let Some(path) = find_desktop_file_by_filename(app_id, &files) {
|
find_desktop_file_by_filename(app_id, &files)
|
||||||
return Some(path);
|
.or_else(|| find_desktop_file_by_filedata(app_id, &files))
|
||||||
}
|
|
||||||
|
|
||||||
find_desktop_file_by_filedata(app_id, &files)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the correct desktop file using a simple condition check
|
/// Finds the correct desktop file using a simple condition check
|
||||||
fn find_desktop_file_by_filename(app_id: &str, files: &[PathBuf]) -> Option<PathBuf> {
|
fn find_desktop_file_by_filename(app_id: &str, files: &[PathBuf]) -> Option<PathBuf> {
|
||||||
let app_id = app_id.to_lowercase();
|
let with_names = files
|
||||||
|
|
||||||
files
|
|
||||||
.iter()
|
.iter()
|
||||||
.find(|file| {
|
.map(|f| {
|
||||||
let file_name: String = file
|
(
|
||||||
.file_name()
|
f,
|
||||||
.expect("file name doesn't end with ...")
|
f.file_stem()
|
||||||
|
.unwrap_or_default()
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_lowercase();
|
.to_lowercase(),
|
||||||
|
)
|
||||||
file_name.contains(&app_id)
|
|
||||||
|| app_id
|
|
||||||
.split(&[' ', ':', '@', '.', '_'][..])
|
|
||||||
.any(|part| file_name.contains(part)) // this will attempt to find flatpak apps that are like this
|
|
||||||
// `com.company.app` or `com.app.something`
|
|
||||||
})
|
})
|
||||||
.map(ToOwned::to_owned)
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
with_names
|
||||||
|
.iter()
|
||||||
|
// first pass - check for exact match
|
||||||
|
.find(|(_, name)| name.eq_ignore_ascii_case(app_id))
|
||||||
|
// second pass - check for substring
|
||||||
|
.or_else(|| {
|
||||||
|
with_names.iter().find(|(_, name)| {
|
||||||
|
// this will attempt to find flatpak apps that are in the format
|
||||||
|
// `com.company.app` or `com.app.something`
|
||||||
|
app_id
|
||||||
|
.split(&[' ', ':', '@', '.', '_'][..])
|
||||||
|
.any(|part| name.contains(part))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.map(|(file, _)| file.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the correct desktop file using the keys in `DESKTOP_FILES_LOOK_OUT_KEYS`
|
/// Finds the correct desktop file using the keys in `DESKTOP_FILES_LOOK_OUT_KEYS`
|
||||||
|
@ -99,7 +106,7 @@ fn find_desktop_file_by_filedata(app_id: &str, files: &[PathBuf]) -> Option<Path
|
||||||
let app_id = &app_id.to_lowercase();
|
let app_id = &app_id.to_lowercase();
|
||||||
let mut desktop_files_cache = lock!(DESKTOP_FILES);
|
let mut desktop_files_cache = lock!(DESKTOP_FILES);
|
||||||
|
|
||||||
files
|
let files = files
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|file| {
|
.filter_map(|file| {
|
||||||
let Some(parsed_desktop_file) = parse_desktop_file(file) else { return None };
|
let Some(parsed_desktop_file) = parse_desktop_file(file) else { return None };
|
||||||
|
@ -107,13 +114,41 @@ fn find_desktop_file_by_filedata(app_id: &str, files: &[PathBuf]) -> Option<Path
|
||||||
desktop_files_cache.insert(file.clone(), parsed_desktop_file.clone());
|
desktop_files_cache.insert(file.clone(), parsed_desktop_file.clone());
|
||||||
Some((file.clone(), parsed_desktop_file))
|
Some((file.clone(), parsed_desktop_file))
|
||||||
})
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let file = files
|
||||||
|
.iter()
|
||||||
|
// first pass - check name key for exact match
|
||||||
.find(|(_, desktop_file)| {
|
.find(|(_, desktop_file)| {
|
||||||
|
desktop_file
|
||||||
|
.get("Name")
|
||||||
|
.map(|names| names.iter().any(|name| name.eq_ignore_ascii_case(app_id)))
|
||||||
|
.unwrap_or_default()
|
||||||
|
})
|
||||||
|
// second pass - check name key for substring
|
||||||
|
.or_else(|| {
|
||||||
|
files.iter().find(|(_, desktop_file)| {
|
||||||
|
desktop_file
|
||||||
|
.get("Name")
|
||||||
|
.map(|names| {
|
||||||
|
names
|
||||||
|
.iter()
|
||||||
|
.any(|name| name.to_lowercase().contains(app_id))
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
// third pass - check all keys for substring
|
||||||
|
.or_else(|| {
|
||||||
|
files.iter().find(|(_, desktop_file)| {
|
||||||
desktop_file
|
desktop_file
|
||||||
.values()
|
.values()
|
||||||
.flatten()
|
.flatten()
|
||||||
.any(|value| value.to_lowercase().contains(app_id))
|
.any(|value| value.to_lowercase().contains(app_id))
|
||||||
})
|
})
|
||||||
.map(|(path, _)| path)
|
});
|
||||||
|
|
||||||
|
file.map(|(path, _)| path).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a desktop file into a hashmap of keys/vector(values).
|
/// Parses a desktop file into a hashmap of keys/vector(values).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue