Skip to content

Commit

Permalink
Fix logic if device is up to date (#205)
Browse files Browse the repository at this point in the history
* Fix logic if device is up to date

* Be more verbose for update version
  • Loading branch information
meisenzahl authored Mar 10, 2021
1 parent c2b5a06 commit 903ad63
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 42 deletions.
40 changes: 27 additions & 13 deletions src/Views/FirmwareView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,36 @@ public class About.FirmwareView : Gtk.Stack {

private void add_device (Fwupd.Client client, Fwupd.Device device) {
if (device.has_flag (Fwupd.DEVICE_FLAG_UPDATABLE)) {
var row = new Widgets.FirmwareUpdateRow (client, device);
FirmwareClient.get_upgrades.begin (client, device.get_id (), (obj, res) => {
Fwupd.Release? release = null;

if (row.is_updatable) {
num_updates++;
}
try {
var upgrades = FirmwareClient.get_upgrades.end (res);
if (upgrades != null) {
release = upgrades[0];
}
} catch (Error e) {
debug (e.message);
}

update_list.add (row);
update_list.invalidate_sort ();
var row = new Widgets.FirmwareUpdateRow (client, device, release);

row.on_update_start.connect (() => {
progress_alert_view.title = _("%s” is being updated").printf (device.get_name ());
visible_child = progress_view;
});
row.on_update_end.connect (() => {
visible_child = grid;
update_list_view.begin (client);
if (row.is_updatable) {
num_updates++;
}

update_list.add (row);
update_list.invalidate_sort ();
update_list.show_all ();

row.on_update_start.connect (() => {
progress_alert_view.title = _("%s” is being updated").printf (device.get_name ());
visible_child = progress_view;
});
row.on_update_end.connect (() => {
visible_child = grid;
update_list_view.begin (client);
});
});
}
}
Expand Down
53 changes: 24 additions & 29 deletions src/Widgets/FirmwareUpdateRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@
public class About.Widgets.FirmwareUpdateRow : Gtk.ListBoxRow {
public Fwupd.Client client { get; construct set; }
public Fwupd.Device device { get; construct set; }
public bool is_updatable { get; private set; default = false; }
public Fwupd.Release? release { get; construct set; }
public bool is_updatable {
get {
return release != null && device.get_version () != release.get_version ();
}
}

public signal void on_update_start ();
public signal void on_update_end ();

private Gtk.Image image;

public FirmwareUpdateRow (Fwupd.Client client, Fwupd.Device device) {
public FirmwareUpdateRow (Fwupd.Client client, Fwupd.Device device, Fwupd.Release? release) {
Object (
client: client,
device: device
device: device,
release: release
);
}

Expand Down Expand Up @@ -65,33 +71,22 @@ public class About.Widgets.FirmwareUpdateRow : Gtk.ListBoxRow {
image.gicon = new GLib.ThemedIcon.from_names (icons.data);
}

FirmwareClient.get_upgrades.begin (client, device.get_id (), (obj, res) => {
try {
var upgrades = FirmwareClient.get_upgrades.end (res);
if (upgrades != null) {
is_updatable = true;

var release = upgrades[0];
version_label.label = release.get_version ();

var update_button = new Gtk.Button.with_label (_("Update")) {
valign = Gtk.Align.CENTER
};
update_button.clicked.connect (() => {
on_update_start ();

update.begin (release, (obj, res) => {
update.end (res);
on_update_end ();
});
});
grid.attach (update_button, 2, 0, 1, 2);
}
} catch (Error e) {
debug (e.message);
}
});
if (is_updatable) {
version_label.label = "%s%s".printf (device.get_version (), release.get_version ());

var update_button = new Gtk.Button.with_label (_("Update")) {
valign = Gtk.Align.CENTER
};
update_button.clicked.connect (() => {
on_update_start ();

update.begin (release, (obj, res) => {
update.end (res);
on_update_end ();
});
});
grid.attach (update_button, 2, 0, 1, 2);
}

add (grid);
}
Expand Down

0 comments on commit 903ad63

Please sign in to comment.