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

Improve SearchView #1965

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions src/Core/FlatpakBackend.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlatpakBackend> instance;
public static unowned FlatpakBackend get_default () {
return instance.once (() => { return new FlatpakBackend (); });
Expand Down
12 changes: 11 additions & 1 deletion src/Views/SearchView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,11 +33,16 @@ public class AppCenter.SearchView : Gtk.Box {
var flathub_link = "<a href='https://flathub.org'>%s</a>".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 () {
Expand All @@ -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 = "<a href='https://flathub.org/apps/search/%s'>%s</a>".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);
});
Expand Down