Skip to content

Commit 87ae37b

Browse files
leolost2605danirabbitjeremypw
authored
ChangeInfo: Update properties on the main thread, use property bindings (#2405)
Co-authored-by: Danielle Foré <danielle@elementary.io> Co-authored-by: Jeremy Wootten <jeremywootten@gmail.com>
1 parent 35c2bd6 commit 87ae37b

3 files changed

Lines changed: 17 additions & 60 deletions

File tree

src/Core/ChangeInformation.vala

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ public class AppCenterCore.ChangeInformation : Object {
2929
FINISHED
3030
}
3131

32-
/**
33-
* This signal is likely to be fired from a non-main thread. Ensure any UI
34-
* logic driven from this runs on the GTK thread
35-
*/
36-
public signal void status_changed ();
37-
38-
/**
39-
* This signal is likely to be fired from a non-main thread. Ensure any UI
40-
* logic driven from this runs on the GTK thread
41-
*/
42-
public signal void progress_changed ();
43-
4432
public Gee.ArrayList<string> updatable_packages { get; private set; }
4533

4634
public ActionGroup action_group { get; private set; }
@@ -75,15 +63,12 @@ public class AppCenterCore.ChangeInformation : Object {
7563
progress = 0.0f;
7664
status = Status.WAITING;
7765
status_description = _("Waiting");
78-
status_changed ();
79-
progress_changed ();
8066
}
8167

8268
public void complete () {
8369
cancel_action.set_enabled (false);
8470
status = Status.FINISHED;
8571
status_description = _("Finished");
86-
status_changed ();
8772
reset_progress ();
8873
}
8974

@@ -92,7 +77,6 @@ public class AppCenterCore.ChangeInformation : Object {
9277
cancel_action.set_enabled (false);
9378
status = Status.CANCELLED;
9479
status_description = _("Cancelling");
95-
status_changed ();
9680
}
9781

9882
public void clear_update_info () {
@@ -106,16 +90,21 @@ public class AppCenterCore.ChangeInformation : Object {
10690
progress = 0.0f;
10791
}
10892

93+
/**
94+
* This method is thread safe. It will queue any updates on the main thread.
95+
*/
10996
public void callback (string status_description, double progress, Status status) {
110-
if (this.status_description != status_description || this.status != status) {
111-
this.status_description = status_description;
112-
this.status = status;
113-
status_changed ();
114-
}
115-
116-
if (this.progress != progress) {
117-
this.progress = progress;
118-
progress_changed ();
119-
}
97+
Idle.add (() => {
98+
if (this.status_description != status_description || this.status != status) {
99+
this.status_description = status_description;
100+
this.status = status;
101+
}
102+
103+
if (this.progress != progress) {
104+
this.progress = progress;
105+
}
106+
107+
return Source.REMOVE;
108+
});
120109
}
121110
}

src/Core/Package.vala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,6 @@ public class AppCenterCore.Package : Object {
186186
}
187187
}
188188

189-
public bool changes_finished {
190-
get {
191-
return change_information.status == ChangeInformation.Status.FINISHED;
192-
}
193-
}
194-
195189
public bool is_runtime_updates {
196190
get {
197191
return component.id == RUNTIME_UPDATES_ID;
@@ -601,10 +595,6 @@ public class AppCenterCore.Package : Object {
601595
return summary;
602596
}
603597

604-
public string get_progress_description () {
605-
return change_information.status_description;
606-
}
607-
608598
public GLib.Icon get_icon (uint size, uint scale_factor) {
609599
GLib.Icon? icon = null;
610600
uint current_size = 0;

src/Widgets/ProgressButton.vala

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ public class AppCenter.ProgressButton : Gtk.Button {
1919
add_css_class ("progress");
2020
add_css_class ("text-button");
2121

22-
package.change_information.progress_changed.connect (update_progress);
23-
package.change_information.status_changed.connect (update_progress_status);
24-
25-
update_progress_status ();
26-
update_progress ();
22+
package.change_information.bind_property ("status-description", this, "tooltip-text", SYNC_CREATE);
2723

2824
var cancel_label = new Gtk.Label (_("Cancel")) {
2925
mnemonic_widget = this
3026
};
3127

3228
progressbar = new Gtk.ProgressBar ();
29+
package.change_information.bind_property ("progress", progressbar, "fraction", SYNC_CREATE);
3330

3431
var box = new Gtk.Box (VERTICAL, 0);
3532
box.append (cancel_label);
@@ -39,23 +36,4 @@ public class AppCenter.ProgressButton : Gtk.Button {
3936
action_name = ACTION_PREFIX + AppCenterCore.ChangeInformation.CANCEL_ACTION_NAME;
4037
insert_action_group (ACTION_GROUP_PREFIX, package.change_information.action_group);
4138
}
42-
43-
private void update_progress () {
44-
Idle.add (() => {
45-
progressbar.fraction = package.progress;
46-
return GLib.Source.REMOVE;
47-
});
48-
}
49-
50-
private void update_progress_status () {
51-
Idle.add (() => {
52-
tooltip_text = package.get_progress_description ();
53-
/* Ensure progress bar shows complete to match status (lp:1606902) */
54-
if (package.changes_finished) {
55-
progressbar.fraction = 1.0f;
56-
}
57-
58-
return GLib.Source.REMOVE;
59-
});
60-
}
6139
}

0 commit comments

Comments
 (0)