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

notifications: Try to guess app id if getting from hints fails #479

Merged
merged 2 commits into from
Oct 18, 2023
Merged
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
28 changes: 22 additions & 6 deletions src/lib/notification.vala
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,27 @@
category = variant.get_string();
}

// Set the application ID and app info
// Try to set the application ID and app info
if ((variant = hints.lookup("desktop-entry")) != null && variant.is_of_type(VariantType.STRING)) {
app_id = variant.get_string();
app_id.replace(".desktop", "");
app_info = new DesktopAppInfo("%s.desktop".printf(app_id));
}

// Because following specs is a lost art, sometimes the desktop-entry
// value does not correspond to the desktop file. So, try to best-guess
// the desktop id instead.
if (app_info == null) {
app_id = app_name.replace(" ", "-").down();
app_info = new DesktopAppInfo("%s.desktop".printf(app_id));
}

if (app_info != null) app_name = app_info.get_string("Name") ?? app_name;
// Make sure we have the best app name
if (app_info != null) {
app_name = app_info.get_string("Name") ?? app_name;
}

// Try to get the application's image
app_image = get_appinfo_image(Gtk.IconSize.DND, app_id.down());

bool image_found = false;
Expand Down Expand Up @@ -255,9 +267,13 @@

private Gtk.Image? get_appinfo_image(Gtk.IconSize size, string? fallback) {
if (app_info == null) {
var fallback_image = new Gtk.Image.from_icon_name(fallback, size);
var invalid_image = (fallback_image == null) || (fallback_image.icon_name == null) || (fallback_image.icon_name == "image-missing") || (fallback_image.icon_name == "");
return invalid_image ? null : fallback_image;
var theme = Gtk.IconTheme.get_default();

if (!theme.has_icon(fallback)) {
return null;
}

return new Gtk.Image.from_icon_name(fallback, size);
}

var app_icon_name = app_info.get_string("Icon"); // Use the Icon from the respective DesktopAppInfo or fallback to generic applications-internet
Expand All @@ -272,4 +288,4 @@
return null;
}
}
}
}