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

Fix: Only fetch icons on demand. #831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cosmic-settings/src/pages/desktop/appearance/icon_themes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ pub async fn fetch() -> Message {
theme_paths.entry(name.clone()).or_insert(path);

let theme = id.clone();
/* This section is performance critical */
// `icon::from_name` may perform blocking I/O
if let Ok(handles) =
tokio::task::spawn_blocking(|| preview_handles(theme, valid_dirs)).await
{
icon_themes.insert(IconTheme { id, name }, handles);
}
/* END */
}
}
}
Expand Down
27 changes: 21 additions & 6 deletions cosmic-settings/src/pages/desktop/appearance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ enum ContextView {
MonospaceFont,
SystemFont,
}

#[allow(clippy::struct_excessive_bools)]
pub struct Page {
entity: page::Entity,
on_enter_handle: Option<cosmic::iced::task::Handle>,
Expand All @@ -79,6 +79,10 @@ pub struct Page {
font_filter: Vec<Arc<str>>,
font_search: String,

/** Only fetch icons once. Allows for better cleanup. Also icon fetching can take for ages. */
icons_fetched: bool,
icon_fetch_handle: Option<cosmic::iced::task::Handle>,

icon_theme_active: Option<usize>,
icon_themes: IconThemes,
icon_handles: IconHandles,
Expand Down Expand Up @@ -203,6 +207,8 @@ impl
font_config: font_config::Model::new(),
font_filter: Vec::new(),
font_search: String::new(),
icons_fetched: false,
icon_fetch_handle: None,
icon_theme_active: None,
icon_themes: Vec::new(),
icon_handles: Vec::new(),
Expand Down Expand Up @@ -1081,10 +1087,17 @@ impl Page {

Message::IconsAndToolkit => {
self.context_view = Some(ContextView::IconsAndToolkit);
return cosmic::task::message(crate::app::Message::OpenContextDrawer(
self.entity,
"".into(),
let mut tasks = Vec::new();
tasks.push(cosmic::task::message(
crate::app::Message::OpenContextDrawer(self.entity, "".into()),
));
if !self.icons_fetched {
self.icons_fetched = true;
let (task, handle) = cosmic::task::future(icon_themes::fetch()).abortable();
self.icon_fetch_handle = Some(handle);
tasks.push(task);
}
return Task::batch(tasks);
}

Message::Daytime(day_time) => {
Expand Down Expand Up @@ -1457,7 +1470,7 @@ impl page::Page<crate::pages::Message> for Page {
) -> Task<crate::pages::Message> {
let (task, handle) = cosmic::task::batch(vec![
// Load icon themes
cosmic::task::future(icon_themes::fetch()).map(crate::pages::Message::Appearance),
// cosmic::task::future(icon_themes::fetch()).map(crate::pages::Message::Appearance),
// Load font families
cosmic::task::future(async move {
let (mono, interface) = font_config::load_font_families();
Expand All @@ -1475,7 +1488,9 @@ impl page::Page<crate::pages::Message> for Page {
if let Some(handle) = self.on_enter_handle.take() {
handle.abort();
}

if let Some(handle) = self.icon_fetch_handle.take() {
handle.abort();
}
cosmic::task::message(crate::pages::Message::Appearance(Message::Left))
}

Expand Down