Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std lib's LazyLock over once_cell #5

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fix: avoid panics when it can be handled
joshuamegnauth54 authored Dec 12, 2024
commit c61b0735e3b670443ff23f670f6a9b636c5e7f1a
11 changes: 4 additions & 7 deletions src/theme/parse.rs
Original file line number Diff line number Diff line change
@@ -47,12 +47,9 @@ impl Theme {
}

fn get_directory<'a>(&'a self, name: &'a str) -> Option<Directory<'a>> {
self.index.section(Some(name)).map(|props| {
let size = props
.get("Size")
.and_then(|size| str::parse(size).ok())
.expect("Size not found for icon");
Directory {
self.index.section(Some(name)).and_then(|props| {
let size = props.get("Size").and_then(|size| str::parse(size).ok())?;
Some(Directory {
name,
size,
scale: props
@@ -76,7 +73,7 @@ impl Theme {
.get("Threshold")
.and_then(|thrsh| str::parse(thrsh).ok())
.unwrap_or(2),
}
})
})
}
}
6 changes: 4 additions & 2 deletions src/theme/paths.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ pub(crate) static BASE_PATHS: Lazy<Vec<PathBuf>> = Lazy::new(icon_theme_base_pat
/// Look in $HOME/.icons (for backwards compatibility), in $XDG_DATA_DIRS/icons, in $XDG_DATA_DIRS/pixmaps and in /usr/share/pixmaps (in that order).
/// Paths that are not found are filtered out.
fn icon_theme_base_paths() -> Vec<PathBuf> {
let home_icon_dir = home_dir().expect("No $HOME directory").join(".icons");
let mut data_dirs: Vec<_> = BaseDirectories::new()
.map(|bd| {
let mut data_dirs: Vec<_> = bd
@@ -27,7 +26,10 @@ fn icon_theme_base_paths() -> Vec<PathBuf> {
data_dirs
})
.unwrap_or_default();
data_dirs.push(home_icon_dir);
match home_dir().map(|home| home.join(".icons")) {
Some(home_icon_dir) => data_dirs.push(home_icon_dir),
None => tracing::warn!("No $HOME directory found"),
}
data_dirs.into_iter().filter(|p| p.exists()).collect()
}