Merge lp:~donadigo/appcenter/open-button into lp:~elementary-apps/appcenter/appcenter

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Danielle Foré
Approved revision: 366
Merged at revision: 379
Proposed branch: lp:~donadigo/appcenter/open-button
Merge into: lp:~elementary-apps/appcenter/appcenter
Diff against target: 247 lines (+78/-11)
5 files modified
src/AbstractAppContainer.vala (+41/-3)
src/Core/Package.vala (+27/-0)
src/Views/AppInfoView.vala (+2/-1)
src/Views/AppListView.vala (+2/-2)
src/Widgets/PackageRow.vala (+6/-5)
To merge this branch: bzr merge lp:~donadigo/appcenter/open-button
Reviewer Review Type Date Requested Status
Jeremy Wootten code, function Approve
Review via email: mp+313934@code.launchpad.net

Commit message

* Add open button to open apps from appcenter

Description of the change

This branch fixes bug #1628748: "Add "Open" button to installed listings".

If the app has a desktop ID and is installed or has an update available, the open button will be shown to open the app directly from the appcenter.

To post a comment you must log in.
lp:~donadigo/appcenter/open-button updated
366. By Adam Bieńkowski

Do not show open button in installed view

Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

LGTM :)

review: Approve (code, function)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/AbstractAppContainer.vala'
2--- src/AbstractAppContainer.vala 2016-09-17 18:18:04 +0000
3+++ src/AbstractAppContainer.vala 2017-01-01 16:06:44 +0000
4@@ -9,11 +9,13 @@
5 // The action button covers Install and Update
6 protected Widgets.AppActionButton action_button;
7 protected Widgets.AppActionButton uninstall_button;
8+ protected Widgets.AppActionButton open_button;
9 protected Gtk.ProgressBar progress_bar;
10 protected Gtk.Button cancel_button;
11 protected Gtk.SizeGroup action_button_group;
12 protected Gtk.Stack action_stack;
13- protected bool show_uninstall;
14+ protected bool show_uninstall = true;
15+ protected bool show_open = true;
16
17 public bool is_os_updates {
18 get {
19@@ -68,12 +70,17 @@
20 uninstall_button = new Widgets.AppActionButton (_("Uninstall"));
21 uninstall_button.clicked.connect (() => uninstall_clicked.begin ());
22
23+ open_button = new Widgets.AppActionButton (_("Open"));
24+ open_button.clicked.connect (launch_package_app);
25+
26 var button_grid = new Gtk.Grid ();
27+ button_grid.column_spacing = 6;
28 button_grid.halign = Gtk.Align.END;
29 button_grid.valign = Gtk.Align.CENTER;
30 button_grid.orientation = Gtk.Orientation.HORIZONTAL;
31 button_grid.add (uninstall_button);
32 button_grid.add (action_button);
33+ button_grid.add (open_button);
34
35 var progress_grid = new Gtk.Grid ();
36 progress_grid.valign = Gtk.Align.CENTER;
37@@ -89,6 +96,7 @@
38 action_button_group.add_widget (action_button);
39 action_button_group.add_widget (uninstall_button);
40 action_button_group.add_widget (cancel_button);
41+ action_button_group.add_widget (open_button);
42
43 action_stack.add_named (button_grid, "buttons");
44 action_stack.add_named (progress_grid, "progress");
45@@ -115,7 +123,7 @@
46 update_action ();
47 }
48
49- protected void update_action (bool show_uninstall = true) {
50+ protected void update_action () {
51 uninstall_button.no_show_all = true;
52 uninstall_button.hide ();
53 progress_bar.no_show_all = true;
54@@ -129,8 +137,10 @@
55 action_button.label = _("Install");
56 action_button.no_show_all = false;
57 action_button.show ();
58+
59+ open_button.no_show_all = true;
60+ open_button.hide ();
61 break;
62-
63 case AppCenterCore.Package.State.INSTALLED:
64 if (show_uninstall) {
65 /* Uninstall button will show */
66@@ -148,10 +158,27 @@
67 action_stack.hide ();
68 }
69
70+ if (show_open && package.get_can_launch ()) {
71+ open_button.no_show_all = false;
72+ open_button.show ();
73+ } else {
74+ open_button.no_show_all = true;
75+ open_button.hide ();
76+ }
77+
78 break;
79
80 case AppCenterCore.Package.State.UPDATE_AVAILABLE:
81 action_button.label = _("Update");
82+
83+ if (show_open && package.get_can_launch ()) {
84+ open_button.no_show_all = false;
85+ open_button.show ();
86+ } else {
87+ open_button.no_show_all = true;
88+ open_button.hide ();
89+ }
90+
91 break;
92
93 case AppCenterCore.Package.State.INSTALLING:
94@@ -160,6 +187,9 @@
95 progress_bar.no_show_all = false;
96 progress_bar.show ();
97 action_stack.set_visible_child_name ("progress");
98+
99+ open_button.no_show_all = true;
100+ open_button.hide ();
101 break;
102
103 default:
104@@ -184,6 +214,14 @@
105 package.action_cancellable.cancel ();
106 }
107
108+ private void launch_package_app () {
109+ try {
110+ package.launch ();
111+ } catch (Error e) {
112+ warning ("Failed to launch %s: %s".printf (package.get_name (), e.message));
113+ }
114+ }
115+
116 private async void action_clicked () {
117 if (package.update_available) {
118 yield package.update ();
119
120=== modified file 'src/Core/Package.vala'
121--- src/Core/Package.vala 2016-12-26 21:35:06 +0000
122+++ src/Core/Package.vala 2017-01-01 16:06:44 +0000
123@@ -18,6 +18,11 @@
124 * Authored by: Corentin Noël <corentin@elementary.io>
125 */
126
127+public errordomain PackageLaunchError {
128+ DESKTOP_ID_NOT_FOUND,
129+ APP_INFO_NOT_FOUND
130+}
131+
132 public class AppCenterCore.Package : Object {
133 public signal void changing (bool is_changing);
134 public signal void info_changed (Pk.Status status);
135@@ -144,6 +149,24 @@
136 return yield perform_operation (State.REMOVING, State.NOT_INSTALLED, State.INSTALLED);
137 }
138
139+ public void launch () throws Error {
140+ string desktop_id = component.get_desktop_id ();
141+ if (desktop_id == null) {
142+ throw new PackageLaunchError.DESKTOP_ID_NOT_FOUND ("desktop ID not found");
143+ }
144+
145+ var app_info = new DesktopAppInfo (desktop_id);
146+ if (app_info == null) {
147+ throw new PackageLaunchError.APP_INFO_NOT_FOUND ("AppInfo not found for %s ID".printf (desktop_id));
148+ }
149+
150+ try {
151+ app_info.launch (null, null);
152+ } catch (Error e) {
153+ throw e;
154+ }
155+ }
156+
157 private async bool perform_operation (State performing, State after_success, State after_fail) {
158 var exit_status = Pk.Exit.UNKNOWN;
159 prepare_package_operation (performing);
160@@ -300,6 +323,10 @@
161 return version;
162 }
163
164+ public bool get_can_launch () {
165+ return component.get_desktop_id () != null;
166+ }
167+
168 private Pk.Package? find_package () {
169 if (component.id == OS_UPDATES_ID) {
170 return null;
171
172=== modified file 'src/Views/AppInfoView.vala'
173--- src/Views/AppInfoView.vala 2016-09-29 07:09:59 +0000
174+++ src/Views/AppInfoView.vala 2017-01-01 16:06:44 +0000
175@@ -138,11 +138,12 @@
176
177 action_button.set_suggested_action_header ();
178 uninstall_button.set_destructive_action_header ();
179+ open_button.get_style_context ().add_class ("h3");
180 }
181
182 private async void load_extensions () {
183 package.component.get_addons ().@foreach ((extension) => {
184- var row = new Widgets.PackageRow (new AppCenterCore.Package (extension), null, false);
185+ var row = new Widgets.PackageRow (new AppCenterCore.Package (extension), null);
186 if (extension_box != null) {
187 extension_box.add (row);
188 }
189
190=== modified file 'src/Views/AppListView.vala'
191--- src/Views/AppListView.vala 2016-10-05 13:50:55 +0000
192+++ src/Views/AppListView.vala 2017-01-01 16:06:44 +0000
193@@ -26,7 +26,7 @@
194 public AppListView () {}
195
196 protected override Widgets.AppListRow make_row (AppCenterCore.Package package) {
197- return (Widgets.AppListRow)(new Widgets.PackageRow (package, action_button_group, false));
198+ return (Widgets.AppListRow)(new Widgets.PackageRow (package, action_button_group));
199 }
200 }
201
202@@ -88,7 +88,7 @@
203 protected override void after_add_remove_change_row () {update_headers ();}
204
205 protected override Widgets.AppListRow make_row (AppCenterCore.Package package) {
206- return (Widgets.AppListRow)(new Widgets.PackageRow (package, action_button_group, false));
207+ return (Widgets.AppListRow)(new Widgets.PackageRow (package, action_button_group));
208 }
209
210 protected override void on_package_changing (AppCenterCore.Package package, bool is_changing) {
211
212=== modified file 'src/Widgets/PackageRow.vala'
213--- src/Widgets/PackageRow.vala 2016-09-17 19:28:03 +0000
214+++ src/Widgets/PackageRow.vala 2017-01-01 16:06:44 +0000
215@@ -22,8 +22,8 @@
216 public class PackageRow : Gtk.ListBoxRow, AppListRow {
217 PackageRowGrid grid;
218
219- public PackageRow (AppCenterCore.Package package, Gtk.SizeGroup? size_group, bool show_uninstall = true) {
220- grid = new PackageRowGrid (package, size_group, show_uninstall);
221+ public PackageRow (AppCenterCore.Package package, Gtk.SizeGroup? size_group) {
222+ grid = new PackageRowGrid (package, size_group);
223 add (grid);
224 grid.changed.connect (() => {
225 changed ();
226@@ -92,9 +92,10 @@
227 attach (action_stack, 2, 0, 1, 2);
228 }
229
230- public PackageRowGrid (AppCenterCore.Package package, Gtk.SizeGroup? size_group, bool show_uninstall = true) {
231+ public PackageRowGrid (AppCenterCore.Package package, Gtk.SizeGroup? size_group) {
232 this.package = package;
233- this.show_uninstall = show_uninstall;
234+ this.show_uninstall = false;
235+ this.show_open = false;
236 set_up_package ();
237
238 if (size_group != null) {
239@@ -105,7 +106,7 @@
240 }
241
242 protected override void update_state () {
243- update_action (show_uninstall);
244+ update_action ();
245 changed ();
246 }
247 }

Subscribers

People subscribed via source and target branches