fix: search all base path's hicolor theme, or as a bare path as a last resort

This commit is contained in:
Ashley Wulber 2022-11-22 17:49:56 -05:00 committed by Paul Delafosse
parent aa175c8812
commit 9b68d41b77
3 changed files with 34 additions and 17 deletions

View file

@ -2,7 +2,7 @@ use crate::theme::error::ThemeError;
use crate::theme::paths::ThemePath;
use ini::Ini;
use once_cell::sync::Lazy;
use paths::BASE_PATHS;
pub(crate) use paths::BASE_PATHS;
use std::collections::BTreeMap;
use std::fmt::{Debug, Formatter};
use std::path::{Path, PathBuf};
@ -96,6 +96,7 @@ pub(super) fn try_build_icon_path<P: AsRef<Path>>(
fn try_build_svg<P: AsRef<Path>>(name: &str, path: P) -> Option<PathBuf> {
let path = path.as_ref();
let svg = path.join(format!("{name}.svg"));
if svg.exists() {
Some(svg)
} else {
@ -106,6 +107,7 @@ fn try_build_svg<P: AsRef<Path>>(name: &str, path: P) -> Option<PathBuf> {
fn try_build_png<P: AsRef<Path>>(name: &str, path: P) -> Option<PathBuf> {
let path = path.as_ref();
let png = path.join(format!("{name}.png"));
if png.exists() {
Some(png)
} else {
@ -139,7 +141,7 @@ pub(super) fn get_all_themes() -> Result<BTreeMap<String, Theme>> {
}
impl Theme {
fn from_path<P: AsRef<Path>>(path: P) -> Option<Self> {
pub(crate) fn from_path<P: AsRef<Path>>(path: P) -> Option<Self> {
let path = path.as_ref();
let has_index = path.join("index.theme").exists();

View file

@ -3,8 +3,8 @@ use crate::theme::error::ThemeError;
use dirs::home_dir;
use ini::Ini;
use once_cell::sync::Lazy;
use xdg::BaseDirectories;
use std::path::PathBuf;
use xdg::BaseDirectories;
pub(crate) static BASE_PATHS: Lazy<Vec<PathBuf>> = Lazy::new(icon_theme_base_paths);
@ -12,13 +12,16 @@ pub(crate) static BASE_PATHS: Lazy<Vec<PathBuf>> = Lazy::new(icon_theme_base_pat
/// 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 = BaseDirectories::new().map(|bd| bd.get_data_dirs()).unwrap_or_default();
let mut data_dirs: Vec<_> = BaseDirectories::new()
.map(|bd| {
bd.get_data_dirs()
.into_iter()
.map(|p| p.join("icons"))
.collect()
})
.unwrap_or_default();
data_dirs.push(home_icon_dir);
data_dirs
.into_iter()
.filter(|p| p.exists())
.collect()
data_dirs.into_iter().filter(|p| p.exists()).collect()
}
#[derive(Debug)]