mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-18 16:30:32 +08:00
refactor: simplify icon file search logic in find_target_icons function
Try with 1.91.0 new API
This commit is contained in:
parent
f644036e08
commit
3e81dcd78f
@ -103,31 +103,18 @@ pub fn app_icons_dir() -> Result<PathBuf> {
|
|||||||
|
|
||||||
pub fn find_target_icons(target: &str) -> Result<Option<String>> {
|
pub fn find_target_icons(target: &str) -> Result<Option<String>> {
|
||||||
let icons_dir = app_icons_dir()?;
|
let icons_dir = app_icons_dir()?;
|
||||||
let mut matching_files = Vec::new();
|
let icon_path = fs::read_dir(&icons_dir)?
|
||||||
|
.filter_map(|entry| entry.ok().map(|e| e.path()))
|
||||||
|
.find(|path| {
|
||||||
|
path.file_prefix().is_some_and(|prefix| prefix == target)
|
||||||
|
&& path
|
||||||
|
.extension()
|
||||||
|
.is_some_and(|ext| ext == "ico" || ext == "png")
|
||||||
|
});
|
||||||
|
|
||||||
for entry in fs::read_dir(icons_dir)? {
|
icon_path
|
||||||
let entry = entry?;
|
.map(|path| path_to_str(&path).map(|s| s.into()))
|
||||||
let path = entry.path();
|
.transpose()
|
||||||
|
|
||||||
if let Some(file_name) = path.file_name().and_then(|n| n.to_str())
|
|
||||||
&& file_name.starts_with(target)
|
|
||||||
&& (file_name.ends_with(".ico") || file_name.ends_with(".png"))
|
|
||||||
{
|
|
||||||
matching_files.push(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if matching_files.is_empty() {
|
|
||||||
Ok(None)
|
|
||||||
} else {
|
|
||||||
match matching_files.first() {
|
|
||||||
Some(first_path) => {
|
|
||||||
let first = path_to_str(first_path)?;
|
|
||||||
Ok(Some(first.into()))
|
|
||||||
}
|
|
||||||
None => Ok(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// logs dir
|
/// logs dir
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user