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

UpdateManager: handle notifications #2112

Merged
merged 6 commits into from
Feb 15, 2024
Merged
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: 1 addition & 31 deletions src/Core/Client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ();
}

Expand Down
28 changes: 28 additions & 0 deletions src/Core/UpdateManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down