diff --git a/src/Core/Client.vala b/src/Core/Client.vala index b99306c81..04ff7f90e 100644 --- a/src/Core/Client.vala +++ b/src/Core/Client.vala @@ -29,7 +29,6 @@ public class AppCenterCore.Client : Object { private GLib.DateTime last_cache_update = null; - public uint updates_number { get; private set; default = 0U; } private uint update_cache_timeout_id = 0; private bool refresh_in_progress = false; diff --git a/src/Core/UpdateManager.vala b/src/Core/UpdateManager.vala index 2d8993fe1..336b29925 100644 --- a/src/Core/UpdateManager.vala +++ b/src/Core/UpdateManager.vala @@ -20,6 +20,7 @@ public class AppCenterCore.UpdateManager : Object { public Package runtime_updates { public get; private set; } public int unpaid_apps_number { get; private set; default = 0; } + public uint updates_number { get; private set; default = 0U; } public uint64 updates_size { get; private set; default = 0ULL; } construct { @@ -38,7 +39,7 @@ public class AppCenterCore.UpdateManager : Object { public async uint get_updates (Cancellable? cancellable = null) { var apps_with_updates = new Gee.TreeSet (); - uint count = 0; + updates_number = 0; unpaid_apps_number = 0; updates_size = 0ULL; @@ -66,7 +67,7 @@ public class AppCenterCore.UpdateManager : Object { unpaid_apps_number++; } - count++; + updates_number++; updates_size += appcenter_package.change_information.size; appcenter_package.change_information.updatable_packages.@set (fp_client, flatpak_update); @@ -124,21 +125,21 @@ public class AppCenterCore.UpdateManager : Object { runtime_updates.description = "%s\n%s\n".printf (GLib.Markup.printf_escaped (_("%s:"), latest_version), runtime_desc); } - debug ("%u app updates found", count); + debug ("%u app updates found", updates_number); if (runtime_count > 0) { - count += 1; + updates_number += 1; } if (!AppCenter.App.settings.get_boolean ("automatic-updates")) { var application = Application.get_default (); - if (count > 0) { - var title = ngettext ("Update Available", "Updates Available", count); + if (updates_number > 0) { + var title = ngettext ("Update Available", "Updates Available", updates_number); var body = ngettext ( "%u app update is available", "%u app updates are available", - count - ).printf (count); + updates_number + ).printf (updates_number); var notification = new Notification (title); notification.set_body (body); @@ -151,15 +152,15 @@ public class AppCenterCore.UpdateManager : Object { } try { - yield Granite.Services.Application.set_badge (count); - yield Granite.Services.Application.set_badge_visible (count != 0); + yield Granite.Services.Application.set_badge (updates_number); + yield Granite.Services.Application.set_badge_visible (updates_number != 0); } catch (Error e) { warning ("Error setting updates badge: %s", e.message); } } runtime_updates.update_state (); - return count; + return updates_number; } private static GLib.Once instance; diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 9aa814cc2..05acc8582 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -268,8 +268,9 @@ public class AppCenter.MainWindow : Gtk.ApplicationWindow { } }); - client.notify["updates-number"].connect (() => { - show_update_badge (client.updates_number); + unowned var update_manager = AppCenterCore.UpdateManager.get_default (); + update_manager.notify["updates-number"].connect (() => { + show_update_badge (update_manager.updates_number); }); var network_monitor = NetworkMonitor.get_default (); diff --git a/src/Views/AppListUpdateView.vala b/src/Views/AppListUpdateView.vala index 4406b6379..159664b3d 100644 --- a/src/Views/AppListUpdateView.vala +++ b/src/Views/AppListUpdateView.vala @@ -197,12 +197,11 @@ namespace AppCenter.Views { yield refresh_mutex.lock (); // Wait for any previous operation to end // We know refresh_cancellable is now null as it was set so before mutex was unlocked. refresh_cancellable = new Cancellable (); - unowned var client = AppCenterCore.Client.get_default (); unowned var update_manager = AppCenterCore.UpdateManager.get_default (); - if (client.updates_number > 0) { + if (update_manager.updates_number > 0) { header_revealer.reveal_child = true; - if (client.updates_number == update_manager.unpaid_apps_number || updating_all_apps) { + if (update_manager.updates_number == update_manager.unpaid_apps_number || updating_all_apps) { update_all_button.sensitive = false; } else { update_all_button.sensitive = true; @@ -211,8 +210,8 @@ namespace AppCenter.Views { header_label.label = ngettext ( "%u Update Available", "%u Updates Available", - client.updates_number - ).printf (client.updates_number); + update_manager.updates_number + ).printf (update_manager.updates_number); size_label.update (update_manager.updates_size); } else { @@ -225,6 +224,7 @@ namespace AppCenter.Views { ); } + unowned var client = AppCenterCore.Client.get_default (); var installed_apps = yield client.get_installed_applications (refresh_cancellable); if (!refresh_cancellable.is_cancelled ()) {