Skip to content

Commit

Permalink
Allow cancelling
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Jan 22, 2024
1 parent 39e90c3 commit f545fed
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Backends/SystemUpdate.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class SettingsDaemon.Backends.SystemUpdate : Object {

private Pk.Task task;
private Pk.PackageSack? available_updates = null;
private GLib.Cancellable cancellable;
private Error? last_error = null;

construct {
Expand All @@ -55,6 +56,8 @@ public class SettingsDaemon.Backends.SystemUpdate : Object {
only_download = true
};

cancellable = new GLib.Cancellable ();

check_for_updates.begin ();

Timeout.add_seconds ((uint) settings.get_int64 ("refresh-interval"), () => {
Expand All @@ -71,7 +74,7 @@ public class SettingsDaemon.Backends.SystemUpdate : Object {
update_state (CHECKING);

try {
yield task.refresh_cache_async (false, null, progress_callback);
yield task.refresh_cache_async (force, null, progress_callback);
} catch (Error e) {
warning ("Failed to refresh cache: %s", e.message);
}
Expand Down Expand Up @@ -114,10 +117,12 @@ public class SettingsDaemon.Backends.SystemUpdate : Object {
return;
}

cancellable.reset ();

update_state (DOWNLOADING);

try {
yield task.update_packages_async (available_updates.get_ids (), null, progress_callback);
yield task.update_packages_async (available_updates.get_ids (), cancellable, progress_callback);

Pk.offline_trigger (REBOOT);

Expand All @@ -129,6 +134,9 @@ public class SettingsDaemon.Backends.SystemUpdate : Object {
GLib.Application.get_default ().send_notification (null, notification);

update_state (RESTART_REQUIRED);
} catch (IOError.CANCELLED e) {
debug ("Updates were cancelled");
check_for_updates.begin (true);
} catch (Error e) {
critical ("Failed to download available updates: %s", e.message);

Expand All @@ -146,6 +154,10 @@ public class SettingsDaemon.Backends.SystemUpdate : Object {
}
}

public void cancel () throws DBusError, IOError {
cancellable.cancel ();
}

[DBus (visible=false)]
public void show_error_details () {
if (last_error == null) {
Expand Down

0 comments on commit f545fed

Please sign in to comment.