diff --git a/src/Core/Client.vala b/src/Core/Client.vala index 3708ce193..b99306c81 100644 --- a/src/Core/Client.vala +++ b/src/Core/Client.vala @@ -35,8 +35,6 @@ public class AppCenterCore.Client : Object { private const int SECONDS_BETWEEN_REFRESHES = 60 * 60 * 24; - private AsyncMutex update_notification_mutex = new AsyncMutex (); - private Client () { } construct { @@ -66,35 +64,7 @@ public class AppCenterCore.Client : Object { } public async void refresh_updates () { - yield update_notification_mutex.lock (); - - bool was_empty = updates_number == 0U; - updates_number = yield UpdateManager.get_default ().get_updates (null); - - var application = Application.get_default (); - if (was_empty && updates_number != 0U) { - string title = ngettext ("Update Available", "Updates Available", updates_number); - string body = ngettext ("%u app update is available", "%u app updates are available", updates_number).printf (updates_number); - - var notification = new Notification (title); - notification.set_body (body); - notification.set_icon (new ThemedIcon ("software-update-available")); - notification.set_default_action ("app.show-updates"); - - application.send_notification ("io.elementary.appcenter.updates", notification); - } else { - application.withdraw_notification ("io.elementary.appcenter.updates"); - } - - try { - 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); - } - - update_notification_mutex.unlock (); - + yield UpdateManager.get_default ().get_updates (null); installed_apps_changed (); } diff --git a/src/Core/UpdateManager.vala b/src/Core/UpdateManager.vala index 853913800..2d8993fe1 100644 --- a/src/Core/UpdateManager.vala +++ b/src/Core/UpdateManager.vala @@ -130,6 +130,34 @@ public class AppCenterCore.UpdateManager : Object { count += 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); + var body = ngettext ( + "%u app update is available", + "%u app updates are available", + count + ).printf (count); + + var notification = new Notification (title); + notification.set_body (body); + notification.set_icon (new ThemedIcon ("software-update-available")); + notification.set_default_action ("app.show-updates"); + + application.send_notification ("io.elementary.appcenter.updates", notification); + } else { + application.withdraw_notification ("io.elementary.appcenter.updates"); + } + + try { + yield Granite.Services.Application.set_badge (count); + yield Granite.Services.Application.set_badge_visible (count != 0); + } catch (Error e) { + warning ("Error setting updates badge: %s", e.message); + } + } + runtime_updates.update_state (); return count; }