fix: log instead of panic on icon path errors
This commit is contained in:
parent
c9d32ca725
commit
05f9d99409
2 changed files with 13 additions and 6 deletions
|
|
@ -15,6 +15,7 @@ rust-ini = "0.20.0"
|
||||||
thiserror = "1.0.56"
|
thiserror = "1.0.56"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
xdg = "2.5.2"
|
xdg = "2.5.2"
|
||||||
|
tracing = "0.1.41"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
speculoos = "0.11.0"
|
speculoos = "0.11.0"
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,7 @@ mod paths;
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, ThemeError>;
|
type Result<T> = std::result::Result<T, ThemeError>;
|
||||||
|
|
||||||
pub static THEMES: Lazy<BTreeMap<String, Vec<Theme>>> =
|
pub static THEMES: Lazy<BTreeMap<String, Vec<Theme>>> = Lazy::new(|| get_all_themes());
|
||||||
Lazy::new(|| get_all_themes().expect("Failed to get theme paths"));
|
|
||||||
|
|
||||||
pub struct Theme {
|
pub struct Theme {
|
||||||
pub path: ThemePath,
|
pub path: ThemePath,
|
||||||
|
|
@ -140,14 +139,21 @@ 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() -> 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 found_indices = BTreeMap::new();
|
||||||
let mut to_revisit = Vec::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()? {
|
let dir_iter = match theme_base_dir.read_dir() {
|
||||||
let entry = entry?;
|
Ok(dir) => dir,
|
||||||
|
Err(why) => {
|
||||||
|
tracing::error!(?why, dir = ?theme_base_dir, "unable to read icon theme directory");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for entry in dir_iter.filter_map(std::io::Result::ok) {
|
||||||
let name = entry.file_name();
|
let name = entry.file_name();
|
||||||
let fallback_index = found_indices.get(&name);
|
let fallback_index = found_indices.get(&name);
|
||||||
if let Some(theme) = Theme::from_path(entry.path(), fallback_index) {
|
if let Some(theme) = Theme::from_path(entry.path(), fallback_index) {
|
||||||
|
|
@ -171,7 +177,7 @@ pub(super) fn get_all_themes() -> Result<BTreeMap<String, Vec<Theme>>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(icon_themes)
|
icon_themes
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Theme {
|
impl Theme {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue