fix: use the first discovered index.theme from base directories for each theme
This commit is contained in:
parent
d579766149
commit
39408c71c9
2 changed files with 36 additions and 16 deletions
14
src/lib.rs
14
src/lib.rs
|
|
@ -51,7 +51,7 @@
|
||||||
//! .find();
|
//! .find();
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
use theme::{Theme, BASE_PATHS};
|
use theme::BASE_PATHS;
|
||||||
|
|
||||||
use crate::cache::{CacheEntry, CACHE};
|
use crate::cache::{CacheEntry, CACHE};
|
||||||
use crate::theme::{try_build_icon_path, THEMES};
|
use crate::theme::{try_build_icon_path, THEMES};
|
||||||
|
|
@ -257,15 +257,11 @@ impl<'a> LookupBuilder<'a> {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
for theme_base_dir in BASE_PATHS.iter() {
|
THEMES.get("hicolor").and_then(|icon_themes| {
|
||||||
let theme = Theme::from_path(theme_base_dir.join("hicolor"));
|
icon_themes.iter().find_map(|theme| {
|
||||||
if let Some(icon) = theme.and_then(|theme| {
|
|
||||||
theme.try_get_icon(self.name, self.size, self.scale, self.force_svg)
|
theme.try_get_icon(self.name, self.size, self.scale, self.force_svg)
|
||||||
}) {
|
})
|
||||||
return Some(icon);
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
})
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
for theme_base_dir in BASE_PATHS.iter() {
|
for theme_base_dir in BASE_PATHS.iter() {
|
||||||
|
|
|
||||||
|
|
@ -142,23 +142,43 @@ fn try_build_xmp<P: AsRef<Path>>(name: &str, path: P) -> Option<PathBuf> {
|
||||||
// Iter through the base paths and get all theme directories
|
// Iter through the base paths and get all theme directories
|
||||||
pub(super) fn get_all_themes() -> Result<BTreeMap<String, Vec<Theme>>> {
|
pub(super) fn get_all_themes() -> Result<BTreeMap<String, Vec<Theme>>> {
|
||||||
let mut icon_themes = BTreeMap::<_, Vec<_>>::new();
|
let mut icon_themes = BTreeMap::<_, Vec<_>>::new();
|
||||||
|
let mut found_indices = BTreeMap::new();
|
||||||
|
let mut to_revisit = Vec::new();
|
||||||
|
|
||||||
for theme_base_dir in BASE_PATHS.iter() {
|
for theme_base_dir in BASE_PATHS.iter() {
|
||||||
for entry in theme_base_dir.read_dir()? {
|
for entry in theme_base_dir.read_dir()? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
if let Some(theme) = Theme::from_path(entry.path()) {
|
let name = entry.file_name();
|
||||||
let name = entry.file_name().to_string_lossy().to_string();
|
let fallback_index = found_indices.get(&name);
|
||||||
|
if let Some(theme) = Theme::from_path(entry.path(), fallback_index) {
|
||||||
|
if fallback_index.is_none() {
|
||||||
|
found_indices.insert(name.clone(), theme.index.clone());
|
||||||
|
}
|
||||||
|
let name = name.to_string_lossy().to_string();
|
||||||
|
icon_themes.entry(name).or_default().push(theme);
|
||||||
|
} else if entry.path().is_dir() {
|
||||||
|
to_revisit.push(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for entry in to_revisit {
|
||||||
|
let name = entry.file_name();
|
||||||
|
let fallback_index = found_indices.get(&name);
|
||||||
|
if let Some(theme) = Theme::from_path(entry.path(), fallback_index) {
|
||||||
|
let name = name.to_string_lossy().to_string();
|
||||||
icon_themes.entry(name).or_default().push(theme);
|
icon_themes.entry(name).or_default().push(theme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(icon_themes)
|
Ok(icon_themes)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Theme {
|
impl Theme {
|
||||||
pub(crate) fn from_path<P: AsRef<Path>>(path: P) -> Option<Self> {
|
pub(crate) fn from_path<P: AsRef<Path>>(path: P, index: Option<&Ini>) -> Option<Self> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
|
|
||||||
let has_index = path.join("index.theme").exists();
|
let has_index = path.join("index.theme").exists() || index.is_some();
|
||||||
|
|
||||||
if !has_index || !path.is_dir() {
|
if !has_index || !path.is_dir() {
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -166,9 +186,13 @@ impl Theme {
|
||||||
|
|
||||||
let path = ThemePath(path.into());
|
let path = ThemePath(path.into());
|
||||||
|
|
||||||
match path.index() {
|
match (index, path.index()) {
|
||||||
Ok(index) => Some(Theme { path, index }),
|
(Some(index), _) => Some(Theme {
|
||||||
Err(_) => None,
|
path,
|
||||||
|
index: index.clone(),
|
||||||
|
}),
|
||||||
|
(None, Ok(index)) => Some(Theme { path, index }),
|
||||||
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue