Skip to content

Commit f622577

Browse files
committed
Custom icon theme support
1 parent 5c20f91 commit f622577

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

src/apps/desktop_entry.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,58 @@
33
use std::{
44
collections::HashMap,
55
path::{Path, PathBuf},
6+
sync::LazyLock,
67
vec::Vec,
78
};
89

910
use icon;
1011
use walkdir::WalkDir;
1112

1213
use super::{App, Icon};
14+
use crate::constants;
1315
use crate::serworse;
1416

1517
#[derive(Default)]
1618
pub struct LinuxAppSearcher {
1719
icon_searcher: icon::Icons,
1820
}
1921

22+
static ICON_THEME_NAME: LazyLock<String> = LazyLock::new(|| {
23+
let get_gtk3 = || -> Option<String> {
24+
Some(
25+
serworse::parse_ini_format(
26+
&std::fs::read_to_string(
27+
constants::HOME_DIR.clone() + "/.config/gtk-3.0/settings.ini",
28+
)
29+
.ok()?,
30+
)
31+
.ok()?
32+
.get("Settings")?
33+
.get("gtk-icon-theme-name")?
34+
.to_string(),
35+
)
36+
};
37+
38+
let get_gtk2 = || -> Option<String> {
39+
Some(
40+
serworse::parse_xsv::<String>(
41+
&std::fs::read_to_string(constants::HOME_DIR.clone() + "/.gtkrc-2.0").ok()?,
42+
'=',
43+
)
44+
.ok()?
45+
.get("gtk-icon-theme-name")
46+
.expect("asdf")
47+
.to_string(),
48+
)
49+
};
50+
51+
let theme = get_gtk3()
52+
.or_else(get_gtk2)
53+
.unwrap_or("Adwaita".to_string());
54+
log::warn!("Icon theme picked was: {theme}");
55+
theme
56+
});
57+
2058
impl super::OSAppSearcher for LinuxAppSearcher {
2159
fn get_apps(&self) -> Vec<App> {
2260
load_desktop_entries()
@@ -32,7 +70,7 @@ impl super::OSAppSearcher for LinuxAppSearcher {
3270
}
3371

3472
self.icon_searcher
35-
.find_icon(s.as_str(), 64, 1, "Adwaita") // TODO. Dont hardcode theme
73+
.find_icon(s.as_str(), 64, 1, &ICON_THEME_NAME)
3674
.map(|i| i.path().to_path_buf())
3775
}
3876

0 commit comments

Comments
 (0)