diff --git a/src/Core/FlatpakBackend.vala b/src/Core/FlatpakBackend.vala index bed0c6574..217bebf37 100644 --- a/src/Core/FlatpakBackend.vala +++ b/src/Core/FlatpakBackend.vala @@ -1564,6 +1564,38 @@ public class AppCenterCore.FlatpakBackend : Backend, Object { return package_list[id]; } + public bool is_flathub_enabled () { + if (user_installation != null) { + try { + var remotes = user_installation.list_remotes (null); + for (int i = 0; i < remotes.length; i++) { + if (remotes[i].get_title () == "Flathub") { + return true; + } + } + } catch (Error e) { + critical ("Unable to check if Flathub is enabled: %s", e.message); + return false; + } + } + + if (system_installation != null) { + try { + var remotes = system_installation.list_remotes (null); + for (int i = 0; i < remotes.length; i++) { + if (remotes[i].get_title () == "Flathub") { + return true; + } + } + } catch (Error e) { + critical ("Unable to check if Flathub is enabled: %s", e.message); + return false; + } + } + + return false; + } + private static GLib.Once instance; public static unowned FlatpakBackend get_default () { return instance.once (() => { return new FlatpakBackend (); }); diff --git a/src/Views/SearchView.vala b/src/Views/SearchView.vala index 9bada53b6..a88f41be3 100644 --- a/src/Views/SearchView.vala +++ b/src/Views/SearchView.vala @@ -23,6 +23,7 @@ public class AppCenter.SearchView : Gtk.Box { public signal void show_app (AppCenterCore.Package package); public string? current_search_term { get; set; default = null; } + public bool is_flathub_enabled { get; set; default = false; } private Gtk.ListBox list_box; private uint current_visible_index = 0U; @@ -32,11 +33,16 @@ public class AppCenter.SearchView : Gtk.Box { var flathub_link = "%s".printf (_("Flathub")); var alert_view = new Granite.Widgets.AlertView ( _("No Apps Found"), - _("Try changing search terms. You can also sideload Flatpak apps e.g. from %s").printf (flathub_link), + _("Try changing search terms. You can also sideload Flatpak apps."), "edit-find-symbolic" ); alert_view.show_all (); + is_flathub_enabled = AppCenterCore.FlatpakBackend.get_default ().is_flathub_enabled (); + if (!is_flathub_enabled) { + alert_view.description = _("Try changing search terms. You can also sideload Flatpak apps e.g. from %s").printf (flathub_link); + } + list_store = new GLib.ListStore (typeof (AppCenterCore.Package)); list_box = new Gtk.ListBox () { @@ -55,6 +61,10 @@ public class AppCenter.SearchView : Gtk.Box { add (scrolled); notify["current-search-term"].connect (() => { + if (is_flathub_enabled) { + return; + } + var dyn_flathub_link = "%s".printf (current_search_term, _("Flathub")); alert_view.description = _("Try changing search terms. You can also sideload Flatpak apps e.g. from %s").printf (dyn_flathub_link); });