Skip to content

Commit

Permalink
Add Update Progress Indicator (#356)
Browse files Browse the repository at this point in the history
Co-authored-by: Stanisław <[email protected]>
Co-authored-by: Ryo Nakano <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent d68e2e5 commit b0752f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/DBus/SystemUpdate.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface SystemUpdate : Object {
public struct CurrentState {
State state;
string message;
uint percentage;
uint64 download_size_remaining;
}

public struct UpdateDetails {
Expand Down
49 changes: 46 additions & 3 deletions src/Views/OperatingSystemView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public class About.OperatingSystemView : Gtk.Box {
}
}

private uint64 download_size_remaining = 0;
private uint64 download_size_max = 0;

private File? logo_file;
private Adw.Avatar? logo;
private Gtk.StringList packages;
Expand All @@ -88,6 +91,8 @@ public class About.OperatingSystemView : Gtk.Box {
private Gtk.Grid software_grid;
private Gtk.Image updates_image;
private Gtk.Label updates_title;
private Gtk.ProgressBar update_progress_bar;
private Gtk.Revealer update_progress_revealer;
private Gtk.Label updates_description;
private Gtk.Revealer details_button_revealer;
private Gtk.Stack button_stack;
Expand Down Expand Up @@ -181,12 +186,26 @@ public class About.OperatingSystemView : Gtk.Box {
xalign = 0
};

update_progress_bar = new Gtk.ProgressBar () {
margin_top = 3
};

update_progress_revealer = new Gtk.Revealer () {
child = update_progress_bar
};

updates_description = new Gtk.Label (null) {
xalign = 0
xalign = 0,
use_markup = true,
wrap = true
};
updates_description.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL);
updates_description.add_css_class (Granite.STYLE_CLASS_DIM_LABEL);

var progress_description_box = new Gtk.Box (VERTICAL, 3);
progress_description_box.append (update_progress_revealer);
progress_description_box.append (updates_description);

var update_button = new Gtk.Button.with_label (_("Download"));
update_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);

Expand Down Expand Up @@ -229,7 +248,7 @@ public class About.OperatingSystemView : Gtk.Box {
};
updates_grid.attach (updates_image, 0, 0, 1, 2);
updates_grid.attach (updates_title, 1, 0);
updates_grid.attach (updates_description, 1, 1);
updates_grid.attach (progress_description_box, 1, 1);
updates_grid.attach (button_stack, 2, 0, 1, 2);
updates_grid.attach (details_button_revealer, 1, 2, 2);

Expand Down Expand Up @@ -502,6 +521,7 @@ public class About.OperatingSystemView : Gtk.Box {
return;
}

update_progress_revealer.reveal_child = false;
details_button_revealer.reveal_child = current_state.state == AVAILABLE || current_state.state == ERROR;

switch (current_state.state) {
Expand Down Expand Up @@ -554,9 +574,20 @@ public class About.OperatingSystemView : Gtk.Box {
}
break;
case DOWNLOADING:
update_progress_revealer.reveal_child = current_state.percentage > 0;
update_progress_bar.fraction = current_state.percentage / 100.0;

download_size_remaining = current_state.download_size_remaining;
if (download_size_remaining > download_size_max) {
download_size_max = download_size_remaining;
}

updates_image.icon_name = "browser-download";
updates_title.label = _("Downloading Updates");
updates_description.label = current_state.message;
updates_description.label = "%s <span font-features='tnum'>%s</span>".printf (
current_state.message,
to_progress_text (download_size_remaining, download_size_max)
);
button_stack.visible_child_name = "cancel";
break;
case RESTART_REQUIRED:
Expand All @@ -574,6 +605,18 @@ public class About.OperatingSystemView : Gtk.Box {
}
}

private string to_progress_text (uint64 remain_size, uint64 total_size) {
if (total_size == 0) {
return "";
}

uint64 current_size = total_size - remain_size;
string current_size_str = GLib.format_size (current_size);
string total_size_str = GLib.format_size (total_size);

return "%s / %s".printf (current_size_str, total_size_str);
}

private void details_clicked () {
if (current_state == null) {
return;
Expand Down

0 comments on commit b0752f7

Please sign in to comment.