Skip to content

Commit

Permalink
Add Update Progress Indicator (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 authored Dec 17, 2024
1 parent a3329de commit 049dd1f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/Backends/SystemUpdate.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public class SettingsDaemon.Backends.SystemUpdate : Object {
construct {
current_state = {
UP_TO_DATE,
""
"",
0,
0
};

update_details = {
Expand Down Expand Up @@ -189,7 +191,12 @@ public class SettingsDaemon.Backends.SystemUpdate : Object {
}

private void progress_callback (Pk.Progress progress, Pk.ProgressType progress_type) {
update_state (current_state.state, PkUtils.status_to_title (progress.status));
update_state (
current_state.state,
PkUtils.status_to_title (progress.status),
progress.percentage,
progress.download_size_remaining
);
}

private void send_error (string message) {
Expand All @@ -203,10 +210,17 @@ public class SettingsDaemon.Backends.SystemUpdate : Object {
update_state (ERROR, message);
}

private void update_state (PkUtils.State state, string message = "") {
private void update_state (
PkUtils.State state,
string message = "",
uint percentage = 0,
uint64 download_size_remaining = 0
) {
current_state = {
state,
message
message,
percentage,
download_size_remaining
};

state_changed ();
Expand Down
22 changes: 18 additions & 4 deletions src/Backends/UbuntuDrivers.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public class SettingsDaemon.Backends.UbuntuDrivers : Object {
construct {
current_state = {
UP_TO_DATE,
""
"",
0,
0
};

available_drivers = new HashTable<string, GenericArray<string>> (str_hash, str_equal);
Expand Down Expand Up @@ -260,7 +262,12 @@ public class SettingsDaemon.Backends.UbuntuDrivers : Object {
}

private void progress_callback (Pk.Progress progress, Pk.ProgressType progress_type) {
update_state (current_state.state, PkUtils.status_to_title (progress.status));
update_state (
current_state.state,
PkUtils.status_to_title (progress.status),
progress.percentage,
progress.download_size_remaining
);
}

private void send_error (string message) {
Expand All @@ -274,10 +281,17 @@ public class SettingsDaemon.Backends.UbuntuDrivers : Object {
update_state (ERROR, message);
}

private void update_state (PkUtils.State state, string message = "") {
private void update_state (
PkUtils.State state,
string message = "",
uint percentage = 0,
uint64 download_size_remaining = 0
) {
current_state = {
state,
message
message,
percentage,
download_size_remaining
};

state_changed ();
Expand Down
2 changes: 2 additions & 0 deletions src/Utils/PkUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace SettingsDaemon.PkUtils {
public struct CurrentState {
State state;
string status;
uint percentage;
uint64 download_size_remaining;
}

public static unowned string status_to_title (Pk.Status status) {
Expand Down

0 comments on commit 049dd1f

Please sign in to comment.