Skip to content

Commit

Permalink
UpdateManager: take over updates_number from client (#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Feb 22, 2024
1 parent 9870890 commit c26eead
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/Core/Client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
23 changes: 12 additions & 11 deletions src/Core/UpdateManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -38,7 +39,7 @@ public class AppCenterCore.UpdateManager : Object {

public async uint get_updates (Cancellable? cancellable = null) {
var apps_with_updates = new Gee.TreeSet<Package> ();
uint count = 0;
updates_number = 0;
unpaid_apps_number = 0;
updates_size = 0ULL;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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<UpdateManager> instance;
Expand Down
5 changes: 3 additions & 2 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,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 ();
Expand Down
10 changes: 5 additions & 5 deletions src/Views/AppListUpdateView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,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;
Expand All @@ -207,8 +206,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 {
Expand All @@ -221,6 +220,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 ()) {
Expand Down

0 comments on commit c26eead

Please sign in to comment.