Skip to content

Commit

Permalink
AppListUpdateView: move list population from InstalledView to here (#…
Browse files Browse the repository at this point in the history
…1860)

Co-authored-by: Jeremy Wootten <jeremy@elementaryos.org>
  • Loading branch information
danirabbit and Jeremy Wootten authored Jun 20, 2022
1 parent 29a2f54 commit 3676d66
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 39 deletions.
36 changes: 36 additions & 0 deletions src/Views/AppListUpdateView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace AppCenter.Views {
public class AppListUpdateView : AbstractAppList {
private Gtk.SizeGroup action_button_group;
private bool updating_all_apps = false;
private Cancellable refresh_cancellable;
private AsyncMutex refresh_mutex = new AsyncMutex ();

construct {
action_button_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.BOTH);
Expand Down Expand Up @@ -67,6 +69,40 @@ namespace AppCenter.Views {

add (infobar);
add (scrolled);

refresh_cancellable = new Cancellable ();

get_apps.begin ();

unowned var client = AppCenterCore.Client.get_default ();
client.installed_apps_changed.connect (() => {
Idle.add (() => {
get_apps.begin ();
return GLib.Source.REMOVE;
});
});
}

private async void get_apps () {
refresh_cancellable.cancel ();

yield refresh_mutex.lock ();

refresh_cancellable.reset ();

unowned var client = AppCenterCore.Client.get_default ();

var installed_apps = yield client.get_installed_applications (refresh_cancellable);

if (!refresh_cancellable.is_cancelled ()) {
clear ();

var os_updates = AppCenterCore.UpdateManager.get_default ().os_updates;
add_package (os_updates);
add_packages (installed_apps);
}

refresh_mutex.unlock ();
}

public override void add_packages (Gee.Collection<AppCenterCore.Package> packages) {
Expand Down
39 changes: 0 additions & 39 deletions src/Views/InstalledView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,16 @@
*/

public class AppCenter.Views.InstalledView : AbstractView {
private Cancellable refresh_cancellable;

private AppListUpdateView app_list_view;

private AsyncMutex refresh_mutex = new AsyncMutex ();

construct {
refresh_cancellable = new Cancellable ();

app_list_view = new AppListUpdateView ();
app_list_view.show_app.connect ((package) => {
show_package (package);
});

add (app_list_view);

unowned AppCenterCore.Client client = AppCenterCore.Client.get_default ();

get_apps.begin ();

client.installed_apps_changed.connect (() => {
Idle.add (() => {
get_apps.begin ();
return GLib.Source.REMOVE;
});
});

destroy.connect (() => {
app_list_view.clear ();
});
Expand All @@ -63,28 +46,6 @@ public class AppCenter.Views.InstalledView : AbstractView {
}
}

public async void get_apps () {
refresh_cancellable.cancel ();

yield refresh_mutex.lock ();

refresh_cancellable.reset ();

unowned AppCenterCore.Client client = AppCenterCore.Client.get_default ();

var installed_apps = yield client.get_installed_applications (refresh_cancellable);

if (!refresh_cancellable.is_cancelled ()) {
app_list_view.clear ();

var os_updates = AppCenterCore.UpdateManager.get_default ().os_updates;
app_list_view.add_package (os_updates);
app_list_view.add_packages (installed_apps);
}

refresh_mutex.unlock ();
}

public async void add_app (AppCenterCore.Package package) {
unowned AppCenterCore.Client client = AppCenterCore.Client.get_default ();
var installed_apps = yield client.get_installed_applications ();
Expand Down

0 comments on commit 3676d66

Please sign in to comment.