Skip to content

Commit

Permalink
Revert "Revert "notifications: Try to guess app id if getting from hi…
Browse files Browse the repository at this point in the history
…nts fails (#479)""

This reverts commit e0a7aba.
  • Loading branch information
fossfreedom committed Oct 18, 2023
1 parent d7f45c8 commit 9a05873
Showing 1 changed file with 22 additions and 6 deletions.
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;
}
}
}
}

0 comments on commit 9a05873

Please sign in to comment.