fix: check the cosmic icon theme and don't filter out apps without an app id

This commit is contained in:
Ashley Wulber 2023-12-27 19:11:29 -05:00 • committed by Ashley Wulber
parent 1f8ee2e42d
commit d7163f3b5d

View file

@ -53,6 +53,7 @@ use itertools::Itertools;
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
@ -278,11 +279,18 @@ fn desktop_info_for_app_ids(mut app_ids: Vec<String>) -> Vec<DesktopInfo> {
if let Some(i) = app_ids.iter().position(|s| { if let Some(i) = app_ids.iter().position(|s| {
s == de.appid || s.eq(&de.startup_wm_class().unwrap_or_default()) s == de.appid || s.eq(&de.startup_wm_class().unwrap_or_default())
}) { }) {
let icon = freedesktop_icons::lookup(de.icon().unwrap_or(de.appid)) // check if absolute path exists and otherwise treat it as a name
.with_size(128) let icon_path = Path::new(de.icon().unwrap_or(de.appid));
.with_cache() let icon = if icon_path.is_absolute() && icon_path.exists() {
.find() icon_path.into()
.unwrap_or_else(default_app_icon); } else {
freedesktop_icons::lookup(de.icon().unwrap_or(de.appid))
.with_size(128)
.with_theme("Cosmic")
.with_cache()
.find()
.unwrap_or_else(default_app_icon)
};
app_ids.remove(i); app_ids.remove(i);
Some(DesktopInfo { Some(DesktopInfo {
@ -719,10 +727,7 @@ impl cosmic::Application for CosmicAppList {
.map(cosmic::app::message::app); .map(cosmic::app::message::app);
} }
WaylandUpdate::Toplevel(event) => match event { WaylandUpdate::Toplevel(event) => match event {
ToplevelUpdate::Add(handle, info) => { ToplevelUpdate::Add(handle, mut info) => {
if info.app_id.is_empty() {
return Command::none();
}
if let Some(t) = self if let Some(t) = self
.active_list .active_list
.iter_mut() .iter_mut()
@ -734,9 +739,21 @@ impl cosmic::Application for CosmicAppList {
{ {
t.toplevels.push((handle, info)); t.toplevels.push((handle, info));
} else { } else {
let desktop_info = if info.app_id.is_empty() {
desktop_info_for_app_ids(vec![info.app_id.clone()]).remove(0); info.app_id = format!("Unknown Application {}", self.item_ctr);
}
self.item_ctr += 1; self.item_ctr += 1;
let desktop_info =
desktop_info_for_app_ids(vec![info.app_id.clone()])
.pop()
.unwrap_or_else(|| DesktopInfo {
id: info.app_id.clone(),
wm_class: None,
icon: default_app_icon(),
exec: String::new(),
name: info.app_id.clone(),
path: PathBuf::new(),
});
self.active_list.push(DockItem { self.active_list.push(DockItem {
id: self.item_ctr, id: self.item_ctr,
toplevels: vec![(handle, info)], toplevels: vec![(handle, info)],