diff --git a/src/Core/Package.vala b/src/Core/Package.vala index bd19136db..12cdfb10f 100644 --- a/src/Core/Package.vala +++ b/src/Core/Package.vala @@ -108,6 +108,7 @@ public class AppCenterCore.Package : Object { public GLib.Cancellable action_cancellable { public get; private set; } public State state { public get; private set; default = State.NOT_INSTALLED; } public bool uses_generic_icon { public get; private set; } + public bool icon_available { public get; private set; } public double progress { get { @@ -652,17 +653,15 @@ public class AppCenterCore.Package : Object { public GLib.Icon get_icon (uint size, uint scale_factor) { uint pixel_size = size * scale_factor; - uint remote_current_size = 0; - uint remote_current_scale = 0; uint cached_current_size = 0; uint cached_current_scale = 0; AppStream.Icon? stock_icon = null; AppStream.Icon? cached_icon = null; AppStream.Icon? local_icon = null; - AppStream.Icon? remote_icon = null; uses_generic_icon = false; + icon_available = true; unowned var all_icons = component.get_icons (); foreach (var icon in all_icons) { switch (icon.get_kind ()) { @@ -692,23 +691,12 @@ public class AppCenterCore.Package : Object { } break; case AppStream.IconKind.REMOTE: - var icon_scale = icon.get_scale (); - var icon_width = icon.get_width () * icon_scale; - - bool is_bigger = icon_width > remote_current_size - && remote_current_size < pixel_size; - bool has_better_dpi = icon_width == remote_current_size - && remote_current_scale < icon_scale - && scale_factor <= icon_scale; - - if (is_bigger || has_better_dpi) { - remote_icon = icon; - remote_current_size = icon_width; - remote_current_scale = icon_scale; - } + debug ("'%s' is an unknown kind of AppStream icon", icon.get_name ()); + // We are not loading remote icons for now due to blocking events downloading the file + // TODO: Dynamically load remote icons without blocking get_icon method break; case AppStream.IconKind.UNKNOWN: - message ("'%s' is an unknown kind of AppStream icon", icon.get_name ()); + debug ("'%s' is an unknown kind of AppStream icon", icon.get_name ()); break; } } @@ -723,34 +711,13 @@ public class AppCenterCore.Package : Object { file = File.new_for_path (cached_icon.get_filename ()); } else if (local_icon != null) { file = File.new_for_path (local_icon.get_filename ()); - } else if (remote_icon != null) { - // We need to check if URL is valid and an actual image before loading - var url = remote_icon.get_url (); - try { - var session = new Soup.Session (); - session.set_timeout (2); - var msg = new Soup.Message ("GET", url); - session.send_and_read (msg); - - var content_type = msg.response_headers.get_content_type (null); - if (msg.status_code == 200 && content_type != null && content_type.contains ("image")) { - file = File.new_for_uri (url); - } else { - warning ("Could not load remote_icon %s: Status error, bad url, or not an image", url); - } - session.abort (); - } catch (Error e) { - warning ("Could not load remote_icon %s: %s", url, e.message); - } + } else { + // Either a remote or unkonw icon type + icon_available = false; } - try { - if (file != null && file.query_exists ()) { - // Using FileIcon for some remote icons causes a crash, BytesIcon works though! - return new BytesIcon (file.load_bytes ()); - } - } catch (Error e) { - warning ("Failed to load icon %s: %s", get_name (), e.message); + if (file != null && file.query_exists ()) { + return new FileIcon (file); } uses_generic_icon = true; diff --git a/src/Views/AppInfoView.vala b/src/Views/AppInfoView.vala index 7d9f46c1e..2a7460429 100644 --- a/src/Views/AppInfoView.vala +++ b/src/Views/AppInfoView.vala @@ -190,7 +190,7 @@ public class AppCenter.Views.AppInfoView : Adw.NavigationPage { valign = Gtk.Align.CENTER, width_request = 104, height_request = 104, - visible = package.uses_generic_icon + visible = package.uses_generic_icon && package.icon_available }; spinner.start (); spinner.add_css_class ("spinner"); diff --git a/src/Widgets/AppContainers/ListPackageRowGrid.vala b/src/Widgets/AppContainers/ListPackageRowGrid.vala index e85314a63..e36c32fc0 100644 --- a/src/Widgets/AppContainers/ListPackageRowGrid.vala +++ b/src/Widgets/AppContainers/ListPackageRowGrid.vala @@ -63,7 +63,7 @@ public class AppCenter.Widgets.ListPackageRowGrid : AbstractPackageRowGrid { valign = Gtk.Align.CENTER, width_request = 40, height_request = 40, - visible = package.uses_generic_icon + visible = package.uses_generic_icon && package.icon_available }; spinner.start (); spinner.add_css_class ("spinner-small"); diff --git a/src/Widgets/Banner.vala b/src/Widgets/Banner.vala index 686d876b8..414d9e371 100644 --- a/src/Widgets/Banner.vala +++ b/src/Widgets/Banner.vala @@ -66,7 +66,7 @@ public class AppCenter.Widgets.Banner : Gtk.Button { description: package.get_description (), icon: pkg_icon, brand_color: package.get_color_primary (), - uses_generic_icon: package.uses_generic_icon + uses_generic_icon: package.uses_generic_icon && package.icon_available ); }