From 6cb384c73254a5d1481dd56d63fe5451b0063a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 09:38:43 -0700 Subject: [PATCH 01/11] Core: only support Flatpaks for category --- src/Core/BackendAggregator.vala | 20 -------------------- src/Core/BackendInterface.vala | 1 - src/Core/Client.vala | 4 ---- src/Core/FlatpakBackend.vala | 18 +++++++++++++++--- src/Core/PackageKitBackend.vala | 2 +- src/Core/UbuntuDriversBackend.vala | 4 ---- src/Views/CategoryView.vala | 5 +++-- src/Views/Homepage.vala | 4 ++-- 8 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/Core/BackendAggregator.vala b/src/Core/BackendAggregator.vala index 539dba984..58ea64097 100644 --- a/src/Core/BackendAggregator.vala +++ b/src/Core/BackendAggregator.vala @@ -98,26 +98,6 @@ public class AppCenterCore.BackendAggregator : Backend, Object { return apps; } - public Gee.Collection get_applications_for_category (AppStream.Category category) { - var apps = new Gee.HashMap (); - foreach (var backend in backends) { - var results = backend.get_applications_for_category (category); - - foreach (var result in results) { - var result_component_id = result.normalized_component_id; - if (apps.has_key (result_component_id)) { - if (result.origin_score > apps[result_component_id].origin_score) { - apps[result_component_id] = result; - } - } else { - apps[result_component_id] = result; - } - } - } - - return apps.values; - } - public Gee.Collection search_applications (string query, AppStream.Category? category) { var apps = new Gee.HashMap (); foreach (var backend in backends) { diff --git a/src/Core/BackendInterface.vala b/src/Core/BackendInterface.vala index 4f75c47d7..38f9835e3 100644 --- a/src/Core/BackendInterface.vala +++ b/src/Core/BackendInterface.vala @@ -26,7 +26,6 @@ public interface AppCenterCore.Backend : Object { public abstract bool working { public get; protected set; } public abstract async Gee.Collection get_installed_applications (Cancellable? cancellable = null); - public abstract Gee.Collection get_applications_for_category (AppStream.Category category); public abstract Gee.Collection search_applications (string query, AppStream.Category? category); public abstract Gee.Collection search_applications_mime (string query); public abstract Package? get_package_for_component_id (string id); diff --git a/src/Core/Client.vala b/src/Core/Client.vala index 9c274c50b..bfeb4abdc 100644 --- a/src/Core/Client.vala +++ b/src/Core/Client.vala @@ -49,10 +49,6 @@ public class AppCenterCore.Client : Object { return yield BackendAggregator.get_default ().get_installed_applications (cancellable); } - public Gee.Collection get_applications_for_category (AppStream.Category category) { - return BackendAggregator.get_default ().get_applications_for_category (category); - } - public Gee.Collection search_applications (string query, AppStream.Category? category) { return BackendAggregator.get_default ().search_applications (query, category); } diff --git a/src/Core/FlatpakBackend.vala b/src/Core/FlatpakBackend.vala index a22d275d1..08a819255 100644 --- a/src/Core/FlatpakBackend.vala +++ b/src/Core/FlatpakBackend.vala @@ -331,13 +331,25 @@ public class AppCenterCore.FlatpakBackend : Backend, Object { AppStream.utils_sort_components_into_categories (system_appstream_pool.get_components (), category_array, false); components = category.get_components (); - var apps = new Gee.TreeSet (); + var results = new Gee.TreeSet (); components.foreach ((comp) => { var packages = get_packages_for_component_id (comp.get_id ()); - apps.add_all (packages); + results.add_all (packages); }); - return apps; + var apps = new Gee.HashMap (); + foreach (var result in results) { + var result_component_id = result.normalized_component_id; + if (apps.has_key (result_component_id)) { + if (result.origin_score > apps[result_component_id].origin_score) { + apps[result_component_id] = result; + } + } else { + apps[result_component_id] = result; + } + } + + return apps.values; } public Gee.Collection search_applications (string query, AppStream.Category? category) { diff --git a/src/Core/PackageKitBackend.vala b/src/Core/PackageKitBackend.vala index 117d6fb22..889308c95 100644 --- a/src/Core/PackageKitBackend.vala +++ b/src/Core/PackageKitBackend.vala @@ -399,7 +399,7 @@ public class AppCenterCore.PackageKitBackend : Backend, Object { return packages; } - public Gee.Collection get_applications_for_category (AppStream.Category category) { + private Gee.Collection get_applications_for_category (AppStream.Category category) { unowned GLib.GenericArray components = category.get_components (); // Clear out any cached components that could be from other backends if (components.length != 0) { diff --git a/src/Core/UbuntuDriversBackend.vala b/src/Core/UbuntuDriversBackend.vala index 7867f0328..a490026ea 100644 --- a/src/Core/UbuntuDriversBackend.vala +++ b/src/Core/UbuntuDriversBackend.vala @@ -147,10 +147,6 @@ public class AppCenterCore.UbuntuDriversBackend : Backend, Object { } } - public Gee.Collection get_applications_for_category (AppStream.Category category) { - return new Gee.ArrayList (); - } - public Gee.Collection search_applications (string query, AppStream.Category? category) { return new Gee.ArrayList (); } diff --git a/src/Views/CategoryView.vala b/src/Views/CategoryView.vala index b30f5ad56..a1cab9745 100644 --- a/src/Views/CategoryView.vala +++ b/src/Views/CategoryView.vala @@ -60,8 +60,9 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { uncurated_grid.attach (uncurated_flowbox, 0, 1); #endif - unowned var client = AppCenterCore.Client.get_default (); - foreach (var package in client.get_applications_for_category (category)) { + + unowned var flatpak_backend = AppCenterCore.FlatpakBackend.get_default (); + foreach (var package in flatpak_backend.get_applications_for_category (category)) { // Don't show plugins or fonts in search and category views if (!package.is_plugin && !package.is_font) { var package_row = new AppCenter.Widgets.ListPackageRowGrid (package); diff --git a/src/Views/Homepage.vala b/src/Views/Homepage.vala index 482f6e367..ab7f38760 100644 --- a/src/Views/Homepage.vala +++ b/src/Views/Homepage.vala @@ -163,8 +163,8 @@ public class AppCenter.Homepage : AbstractView { var list_view = child as Views.AppListView; list_view.clear (); - unowned var client = AppCenterCore.Client.get_default (); - var apps = client.get_applications_for_category (currently_viewed_category); + unowned var flatpak_backend = AppCenterCore.FlatpakBackend.get_default (); + var apps = flatpak_backend.get_applications_for_category (currently_viewed_category); list_view.add_packages (apps); } } From e2fda556d79daf0df21bce97ca8c8ffa574f61c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 09:48:24 -0700 Subject: [PATCH 02/11] remove extra blank line --- src/Views/CategoryView.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Views/CategoryView.vala b/src/Views/CategoryView.vala index a1cab9745..a6dc7a5df 100644 --- a/src/Views/CategoryView.vala +++ b/src/Views/CategoryView.vala @@ -60,7 +60,6 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { uncurated_grid.attach (uncurated_flowbox, 0, 1); #endif - unowned var flatpak_backend = AppCenterCore.FlatpakBackend.get_default (); foreach (var package in flatpak_backend.get_applications_for_category (category)) { // Don't show plugins or fonts in search and category views From 07dadb4c2e2a663f0eed7d49a6345216bafe5119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 09:52:35 -0700 Subject: [PATCH 03/11] Remove dead code --- src/Views/Homepage.vala | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Views/Homepage.vala b/src/Views/Homepage.vala index ab7f38760..66f7f1511 100644 --- a/src/Views/Homepage.vala +++ b/src/Views/Homepage.vala @@ -155,18 +155,12 @@ public class AppCenter.Homepage : AbstractView { // Remove any old cached category list views foreach (weak Gtk.Widget child in get_children ()) { - if (child is Views.AppListView) { + if (child is CategoryView) { if (child != visible_child) { child.destroy (); - } else { - // If the category list view is visible, don't delete it, just make the package list right - var list_view = child as Views.AppListView; - list_view.clear (); - - unowned var flatpak_backend = AppCenterCore.FlatpakBackend.get_default (); - var apps = flatpak_backend.get_applications_for_category (currently_viewed_category); - list_view.add_packages (apps); } + + // FIXME: Add a refresh method to CategoryView for visible child } } From 8ad47f1ad5af44252f7b01c5e9cf320890f8b295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 10:28:23 -0700 Subject: [PATCH 04/11] Refresh on backend update --- src/Views/CategoryView.vala | 90 ++++++++++++++++++++++++------------- src/Views/Homepage.vala | 4 +- 2 files changed, 61 insertions(+), 33 deletions(-) diff --git a/src/Views/CategoryView.vala b/src/Views/CategoryView.vala index a6dc7a5df..da14bbaee 100644 --- a/src/Views/CategoryView.vala +++ b/src/Views/CategoryView.vala @@ -20,6 +20,14 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { public AppStream.Category category { get; construct; } + private Gtk.Grid free_grid; + private Gtk.Grid grid; + private Gtk.Grid paid_grid; + private Gtk.Grid uncurated_grid; + private SubcategoryFlowbox free_flowbox; + private SubcategoryFlowbox paid_flowbox; + private SubcategoryFlowbox uncurated_flowbox; + public CategoryView (AppStream.Category category) { Object (category: category); } @@ -30,9 +38,9 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { }; paid_header.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL); - var paid_flowbox = new SubcategoryFlowbox (); + paid_flowbox = new SubcategoryFlowbox (); - var paid_grid = new Gtk.Grid (); + paid_grid = new Gtk.Grid (); paid_grid.attach (paid_header, 0, 0); paid_grid.attach (paid_flowbox, 0, 1); @@ -41,9 +49,9 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { }; free_header.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL); - var free_flowbox = new SubcategoryFlowbox (); + free_flowbox = new SubcategoryFlowbox (); - var free_grid = new Gtk.Grid (); + free_grid = new Gtk.Grid (); free_grid.attach (free_header, 0, 0); free_grid.attach (free_flowbox, 0, 1); @@ -52,17 +60,61 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { }; uncurated_header.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL); - var uncurated_flowbox = new SubcategoryFlowbox (); + uncurated_flowbox = new SubcategoryFlowbox (); #if CURATED - var uncurated_grid = new Gtk.Grid (); + uncurated_grid = new Gtk.Grid (); uncurated_grid.attach (uncurated_header, 0, 0); uncurated_grid.attach (uncurated_flowbox, 0, 1); #endif + grid = new Gtk.Grid () { + margin = 12, + margin_bottom = 24, + orientation = Gtk.Orientation.VERTICAL, + row_spacing = 48 + }; + + hscrollbar_policy = Gtk.PolicyType.NEVER; + add (grid); + + populate (); + + paid_flowbox.child_activated.connect ((child) => { + var row = (Widgets.ListPackageRowGrid) child.get_child (); + show_app (row.package); + }); + + free_flowbox.child_activated.connect ((child) => { + var row = (Widgets.ListPackageRowGrid) child.get_child (); + show_app (row.package); + }); + + uncurated_flowbox.child_activated.connect ((child) => { + var row = (Widgets.ListPackageRowGrid) child.get_child (); + show_app (row.package); + }); + } + + public void populate () { + foreach (unowned var child in grid.get_children ()) { + grid.remove (child); + } + + foreach (unowned var child in free_flowbox.get_children ()) { + child.destroy (); + } + + foreach (unowned var child in paid_flowbox.get_children ()) { + child.destroy (); + } + + foreach (unowned var child in uncurated_flowbox.get_children ()) { + child.destroy (); + } + unowned var flatpak_backend = AppCenterCore.FlatpakBackend.get_default (); foreach (var package in flatpak_backend.get_applications_for_category (category)) { - // Don't show plugins or fonts in search and category views if (!package.is_plugin && !package.is_font) { var package_row = new AppCenter.Widgets.ListPackageRowGrid (package); @@ -83,13 +135,6 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { } } - var grid = new Gtk.Grid () { - margin = 12, - margin_bottom = 24, - orientation = Gtk.Orientation.VERTICAL, - row_spacing = 48 - }; - #if CURATED if (paid_flowbox.get_child_at_index (0) != null) { grid.add (paid_grid); @@ -105,25 +150,8 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { #else grid.add (uncurated_flowbox); #endif - hscrollbar_policy = Gtk.PolicyType.NEVER; - add (grid); show_all (); - - paid_flowbox.child_activated.connect ((child) => { - var row = (Widgets.ListPackageRowGrid) child.get_child (); - show_app (row.package); - }); - - free_flowbox.child_activated.connect ((child) => { - var row = (Widgets.ListPackageRowGrid) child.get_child (); - show_app (row.package); - }); - - uncurated_flowbox.child_activated.connect ((child) => { - var row = (Widgets.ListPackageRowGrid) child.get_child (); - show_app (row.package); - }); } private class SubcategoryFlowbox : Gtk.FlowBox { diff --git a/src/Views/Homepage.vala b/src/Views/Homepage.vala index 66f7f1511..59780249c 100644 --- a/src/Views/Homepage.vala +++ b/src/Views/Homepage.vala @@ -158,9 +158,9 @@ public class AppCenter.Homepage : AbstractView { if (child is CategoryView) { if (child != visible_child) { child.destroy (); + } else { + ((CategoryView) child).populate (); } - - // FIXME: Add a refresh method to CategoryView for visible child } } From f3927daf8a7c59243abb4df364ea7f1a67ec7e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 10:30:49 -0700 Subject: [PATCH 05/11] Views update themselves --- src/Views/CategoryView.vala | 9 ++++++++- src/Views/Homepage.vala | 11 ----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Views/CategoryView.vala b/src/Views/CategoryView.vala index da14bbaee..7e2f23a85 100644 --- a/src/Views/CategoryView.vala +++ b/src/Views/CategoryView.vala @@ -94,9 +94,16 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { var row = (Widgets.ListPackageRowGrid) child.get_child (); show_app (row.package); }); + + AppCenterCore.Client.get_default ().installed_apps_changed.connect (() => { + Idle.add (() => { + populate (); + return GLib.Source.REMOVE; + }); + }); } - public void populate () { + private void populate () { foreach (unowned var child in grid.get_children ()) { grid.remove (child); } diff --git a/src/Views/Homepage.vala b/src/Views/Homepage.vala index 59780249c..457cad709 100644 --- a/src/Views/Homepage.vala +++ b/src/Views/Homepage.vala @@ -153,17 +153,6 @@ public class AppCenter.Homepage : AbstractView { } } - // Remove any old cached category list views - foreach (weak Gtk.Widget child in get_children ()) { - if (child is CategoryView) { - if (child != visible_child) { - child.destroy (); - } else { - ((CategoryView) child).populate (); - } - } - } - return GLib.Source.REMOVE; }); }); From 3502f4295be8bb4fb8b91432047c35f8de7f9ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 10:37:49 -0700 Subject: [PATCH 06/11] Move de-duplication to categoryview --- src/Core/FlatpakBackend.vala | 18 +++--------------- src/Views/CategoryView.vala | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Core/FlatpakBackend.vala b/src/Core/FlatpakBackend.vala index 08a819255..a22d275d1 100644 --- a/src/Core/FlatpakBackend.vala +++ b/src/Core/FlatpakBackend.vala @@ -331,25 +331,13 @@ public class AppCenterCore.FlatpakBackend : Backend, Object { AppStream.utils_sort_components_into_categories (system_appstream_pool.get_components (), category_array, false); components = category.get_components (); - var results = new Gee.TreeSet (); + var apps = new Gee.TreeSet (); components.foreach ((comp) => { var packages = get_packages_for_component_id (comp.get_id ()); - results.add_all (packages); + apps.add_all (packages); }); - var apps = new Gee.HashMap (); - foreach (var result in results) { - var result_component_id = result.normalized_component_id; - if (apps.has_key (result_component_id)) { - if (result.origin_score > apps[result_component_id].origin_score) { - apps[result_component_id] = result; - } - } else { - apps[result_component_id] = result; - } - } - - return apps.values; + return apps; } public Gee.Collection search_applications (string query, AppStream.Category? category) { diff --git a/src/Views/CategoryView.vala b/src/Views/CategoryView.vala index 7e2f23a85..0a3fcd676 100644 --- a/src/Views/CategoryView.vala +++ b/src/Views/CategoryView.vala @@ -120,11 +120,22 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { child.destroy (); } - unowned var flatpak_backend = AppCenterCore.FlatpakBackend.get_default (); - foreach (var package in flatpak_backend.get_applications_for_category (category)) { + var packages = new Gee.HashMap (); + var results = AppCenterCore.FlatpakBackend.get_default ().get_applications_for_category (category); + foreach (var result in results) { + var result_component_id = result.normalized_component_id; + if (packages.has_key (result_component_id)) { + if (result.origin_score > packages[result_component_id].origin_score) { + packages[result_component_id] = result; + } + } else { + packages[result_component_id] = result; + } + } + + foreach (var package in packages.values) { if (!package.is_plugin && !package.is_font) { var package_row = new AppCenter.Widgets.ListPackageRowGrid (package); - #if CURATED if (package.is_native) { if (package.get_payments_key () != null && package.get_suggested_amount () != "0") { From 57c61f14e3594e5d13a1364e558bd846bdbe0f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 15:53:14 -0700 Subject: [PATCH 07/11] Populate view async --- src/Views/CategoryView.vala | 117 ++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 51 deletions(-) diff --git a/src/Views/CategoryView.vala b/src/Views/CategoryView.vala index 0a3fcd676..86266fa28 100644 --- a/src/Views/CategoryView.vala +++ b/src/Views/CategoryView.vala @@ -78,6 +78,8 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { hscrollbar_policy = Gtk.PolicyType.NEVER; add (grid); + show_all (); + populate (); paid_flowbox.child_activated.connect ((child) => { @@ -96,80 +98,93 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { }); AppCenterCore.Client.get_default ().installed_apps_changed.connect (() => { - Idle.add (() => { - populate (); - return GLib.Source.REMOVE; - }); + populate (); }); } private void populate () { - foreach (unowned var child in grid.get_children ()) { - grid.remove (child); - } + get_packages.begin ((obj, res) => { + var packages = get_packages.end (res); - foreach (unowned var child in free_flowbox.get_children ()) { - child.destroy (); - } + foreach (unowned var child in grid.get_children ()) { + grid.remove (child); + } - foreach (unowned var child in paid_flowbox.get_children ()) { - child.destroy (); - } + foreach (unowned var child in free_flowbox.get_children ()) { + child.destroy (); + } - foreach (unowned var child in uncurated_flowbox.get_children ()) { - child.destroy (); - } + foreach (unowned var child in paid_flowbox.get_children ()) { + child.destroy (); + } - var packages = new Gee.HashMap (); - var results = AppCenterCore.FlatpakBackend.get_default ().get_applications_for_category (category); - foreach (var result in results) { - var result_component_id = result.normalized_component_id; - if (packages.has_key (result_component_id)) { - if (result.origin_score > packages[result_component_id].origin_score) { - packages[result_component_id] = result; - } - } else { - packages[result_component_id] = result; + foreach (unowned var child in uncurated_flowbox.get_children ()) { + child.destroy (); } - } - foreach (var package in packages.values) { - if (!package.is_plugin && !package.is_font) { - var package_row = new AppCenter.Widgets.ListPackageRowGrid (package); + foreach (var package in packages.values) { + if (!package.is_plugin && !package.is_font) { + var package_row = new AppCenter.Widgets.ListPackageRowGrid (package); #if CURATED - if (package.is_native) { - if (package.get_payments_key () != null && package.get_suggested_amount () != "0") { - paid_flowbox.add (package_row); + if (package.is_native) { + if (package.get_payments_key () != null && package.get_suggested_amount () != "0") { + paid_flowbox.add (package_row); + } else { + free_flowbox.add (package_row); + } } else { - free_flowbox.add (package_row); + uncurated_flowbox.add (package_row); } - } else { - uncurated_flowbox.add (package_row); - } #else - uncurated_flowbox.add (package_row); + uncurated_flowbox.add (package_row); #endif - + } } - } #if CURATED - if (paid_flowbox.get_child_at_index (0) != null) { - grid.add (paid_grid); - } + if (paid_flowbox.get_child_at_index (0) != null) { + grid.add (paid_grid); + } - if (free_flowbox.get_child_at_index (0) != null) { - grid.add (free_grid); - } + if (free_flowbox.get_child_at_index (0) != null) { + grid.add (free_grid); + } - if (uncurated_flowbox.get_child_at_index (0) != null) { - grid.add (uncurated_grid); - } + if (uncurated_flowbox.get_child_at_index (0) != null) { + grid.add (uncurated_grid); + } #else - grid.add (uncurated_flowbox); + grid.add (uncurated_flowbox); #endif - show_all (); + show_all (); + }); + } + + private async Gee.HashMap get_packages () { + SourceFunc callback = get_packages.callback; + + var packages = new Gee.HashMap (); + + new Thread ("get_packages", () => { + var results = AppCenterCore.FlatpakBackend.get_default ().get_applications_for_category (category); + foreach (var result in results) { + var result_component_id = result.normalized_component_id; + if (packages.has_key (result_component_id)) { + if (result.origin_score > packages[result_component_id].origin_score) { + packages[result_component_id] = result; + } + } else { + packages[result_component_id] = result; + } + } + + Idle.add ((owned) callback); + }); + + yield; + + return packages; } private class SubcategoryFlowbox : Gtk.FlowBox { From 56b09c5226f9527ebe02793361e2605e70a4f53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 16:01:34 -0700 Subject: [PATCH 08/11] Add a spinner --- src/Views/CategoryView.vala | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Views/CategoryView.vala b/src/Views/CategoryView.vala index 86266fa28..d852bb77b 100644 --- a/src/Views/CategoryView.vala +++ b/src/Views/CategoryView.vala @@ -15,11 +15,12 @@ * along with this program. If not, see . */ -public class AppCenter.CategoryView : Gtk.ScrolledWindow { +public class AppCenter.CategoryView : Gtk.Stack { public signal void show_app (AppCenterCore.Package package); public AppStream.Category category { get; construct; } + private Gtk.ScrolledWindow scrolled; private Gtk.Grid free_grid; private Gtk.Grid grid; private Gtk.Grid paid_grid; @@ -75,9 +76,18 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { row_spacing = 48 }; - hscrollbar_policy = Gtk.PolicyType.NEVER; - add (grid); + scrolled = new Gtk.ScrolledWindow (null, null) { + hscrollbar_policy = Gtk.PolicyType.NEVER + }; + scrolled.add (grid); + + var spinner = new Gtk.Spinner () { + halign = Gtk.Align.CENTER + }; + spinner.start (); + add (spinner); + add (scrolled); show_all (); populate (); @@ -158,6 +168,7 @@ public class AppCenter.CategoryView : Gtk.ScrolledWindow { #endif show_all (); + visible_child = scrolled; }); } From 609c5946f12060067f8542bd92eb9476945ee9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 16:07:09 -0700 Subject: [PATCH 09/11] organize --- src/Views/CategoryView.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Views/CategoryView.vala b/src/Views/CategoryView.vala index d852bb77b..896a3bd5f 100644 --- a/src/Views/CategoryView.vala +++ b/src/Views/CategoryView.vala @@ -114,8 +114,6 @@ public class AppCenter.CategoryView : Gtk.Stack { private void populate () { get_packages.begin ((obj, res) => { - var packages = get_packages.end (res); - foreach (unowned var child in grid.get_children ()) { grid.remove (child); } @@ -132,6 +130,7 @@ public class AppCenter.CategoryView : Gtk.Stack { child.destroy (); } + var packages = get_packages.end (res); foreach (var package in packages.values) { if (!package.is_plugin && !package.is_font) { var package_row = new AppCenter.Widgets.ListPackageRowGrid (package); From 91fce1fffd6d2c7e89b6b25f83ce0ae0aa59257c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 20:18:05 -0700 Subject: [PATCH 10/11] Just do async stuff --- src/Core/BackendAggregator.vala | 20 ++++++++++++++++++++ src/Core/BackendInterface.vala | 1 + src/Core/Client.vala | 4 ++++ src/Core/PackageKitBackend.vala | 2 +- src/Core/UbuntuDriversBackend.vala | 4 ++++ src/Views/CategoryView.vala | 18 ++++-------------- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/Core/BackendAggregator.vala b/src/Core/BackendAggregator.vala index 58ea64097..539dba984 100644 --- a/src/Core/BackendAggregator.vala +++ b/src/Core/BackendAggregator.vala @@ -98,6 +98,26 @@ public class AppCenterCore.BackendAggregator : Backend, Object { return apps; } + public Gee.Collection get_applications_for_category (AppStream.Category category) { + var apps = new Gee.HashMap (); + foreach (var backend in backends) { + var results = backend.get_applications_for_category (category); + + foreach (var result in results) { + var result_component_id = result.normalized_component_id; + if (apps.has_key (result_component_id)) { + if (result.origin_score > apps[result_component_id].origin_score) { + apps[result_component_id] = result; + } + } else { + apps[result_component_id] = result; + } + } + } + + return apps.values; + } + public Gee.Collection search_applications (string query, AppStream.Category? category) { var apps = new Gee.HashMap (); foreach (var backend in backends) { diff --git a/src/Core/BackendInterface.vala b/src/Core/BackendInterface.vala index 38f9835e3..4f75c47d7 100644 --- a/src/Core/BackendInterface.vala +++ b/src/Core/BackendInterface.vala @@ -26,6 +26,7 @@ public interface AppCenterCore.Backend : Object { public abstract bool working { public get; protected set; } public abstract async Gee.Collection get_installed_applications (Cancellable? cancellable = null); + public abstract Gee.Collection get_applications_for_category (AppStream.Category category); public abstract Gee.Collection search_applications (string query, AppStream.Category? category); public abstract Gee.Collection search_applications_mime (string query); public abstract Package? get_package_for_component_id (string id); diff --git a/src/Core/Client.vala b/src/Core/Client.vala index bfeb4abdc..9c274c50b 100644 --- a/src/Core/Client.vala +++ b/src/Core/Client.vala @@ -49,6 +49,10 @@ public class AppCenterCore.Client : Object { return yield BackendAggregator.get_default ().get_installed_applications (cancellable); } + public Gee.Collection get_applications_for_category (AppStream.Category category) { + return BackendAggregator.get_default ().get_applications_for_category (category); + } + public Gee.Collection search_applications (string query, AppStream.Category? category) { return BackendAggregator.get_default ().search_applications (query, category); } diff --git a/src/Core/PackageKitBackend.vala b/src/Core/PackageKitBackend.vala index 889308c95..117d6fb22 100644 --- a/src/Core/PackageKitBackend.vala +++ b/src/Core/PackageKitBackend.vala @@ -399,7 +399,7 @@ public class AppCenterCore.PackageKitBackend : Backend, Object { return packages; } - private Gee.Collection get_applications_for_category (AppStream.Category category) { + public Gee.Collection get_applications_for_category (AppStream.Category category) { unowned GLib.GenericArray components = category.get_components (); // Clear out any cached components that could be from other backends if (components.length != 0) { diff --git a/src/Core/UbuntuDriversBackend.vala b/src/Core/UbuntuDriversBackend.vala index a490026ea..7867f0328 100644 --- a/src/Core/UbuntuDriversBackend.vala +++ b/src/Core/UbuntuDriversBackend.vala @@ -147,6 +147,10 @@ public class AppCenterCore.UbuntuDriversBackend : Backend, Object { } } + public Gee.Collection get_applications_for_category (AppStream.Category category) { + return new Gee.ArrayList (); + } + public Gee.Collection search_applications (string query, AppStream.Category? category) { return new Gee.ArrayList (); } diff --git a/src/Views/CategoryView.vala b/src/Views/CategoryView.vala index 896a3bd5f..8ea2027a3 100644 --- a/src/Views/CategoryView.vala +++ b/src/Views/CategoryView.vala @@ -131,7 +131,7 @@ public class AppCenter.CategoryView : Gtk.Stack { } var packages = get_packages.end (res); - foreach (var package in packages.values) { + foreach (var package in packages) { if (!package.is_plugin && !package.is_font) { var package_row = new AppCenter.Widgets.ListPackageRowGrid (package); #if CURATED @@ -171,23 +171,13 @@ public class AppCenter.CategoryView : Gtk.Stack { }); } - private async Gee.HashMap get_packages () { + private async Gee.Collection get_packages () { SourceFunc callback = get_packages.callback; - var packages = new Gee.HashMap (); + var packages = new Gee.TreeSet (); new Thread ("get_packages", () => { - var results = AppCenterCore.FlatpakBackend.get_default ().get_applications_for_category (category); - foreach (var result in results) { - var result_component_id = result.normalized_component_id; - if (packages.has_key (result_component_id)) { - if (result.origin_score > packages[result_component_id].origin_score) { - packages[result_component_id] = result; - } - } else { - packages[result_component_id] = result; - } - } + packages.add_all (AppCenterCore.Client.get_default ().get_applications_for_category (category)); Idle.add ((owned) callback); }); From 1e1fef3d27c84c24e7fb1ad4c368cbc414b4bec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 21 May 2022 20:19:10 -0700 Subject: [PATCH 11/11] remove blank lines --- src/Views/CategoryView.vala | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Views/CategoryView.vala b/src/Views/CategoryView.vala index 8ea2027a3..500ad8391 100644 --- a/src/Views/CategoryView.vala +++ b/src/Views/CategoryView.vala @@ -175,15 +175,12 @@ public class AppCenter.CategoryView : Gtk.Stack { SourceFunc callback = get_packages.callback; var packages = new Gee.TreeSet (); - new Thread ("get_packages", () => { packages.add_all (AppCenterCore.Client.get_default ().get_applications_for_category (category)); - Idle.add ((owned) callback); }); yield; - return packages; }