Merge lp:~donadigo/appcenter/fix-get-can-launch into lp:~elementary-apps/appcenter/appcenter

Proposed by Adam Bieńkowski
Status: Merged
Approved by: David Hewitt
Approved revision: 405
Merged at revision: 405
Proposed branch: lp:~donadigo/appcenter/fix-get-can-launch
Merge into: lp:~elementary-apps/appcenter/appcenter
Diff against target: 49 lines (+15/-8)
1 file modified
src/Core/Package.vala (+15/-8)
To merge this branch: bzr merge lp:~donadigo/appcenter/fix-get-can-launch
Reviewer Review Type Date Requested Status
David Hewitt code, function Approve
Review via email: mp+317789@code.launchpad.net

Commit message

* Fix open button appearing on apps which cannot be launched

Description of the change

This branch fixes how get_can_launch () method works in Package class.

get_can_launch used to use Component.get_desktop_id which apparently returns a desktop id *even if it's not valid*, this had to be reworked in order to not show "Open" button in a driver page.

It now creates a DesktopAppInfo which will be verified and if the AppInfo doesn't exist, it will return null so the method will return false.

To post a comment you must log in.
Revision history for this message
David Hewitt (davidmhewitt) wrote :

Stops the open button appearing on OS Updates and things you wouldn't expect to have an open button. Everything else still works.

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/Core/Package.vala'
2--- src/Core/Package.vala 2017-02-04 17:18:30 +0000
3+++ src/Core/Package.vala 2017-02-20 16:56:15 +0000
4@@ -87,7 +87,10 @@
5 private get { return _latest_version; }
6 internal set { _latest_version = convert_version (value); }
7 }
8+
9 private Pk.Package? pk_package = null;
10+ private AppInfo? app_info;
11+ private bool app_info_retrieved = false;
12
13 construct {
14 installed_packages = new Gee.TreeSet<Pk.Package> ();
15@@ -154,14 +157,8 @@
16 }
17
18 public void launch () throws Error {
19- string desktop_id = component.get_desktop_id ();
20- if (desktop_id == null) {
21- throw new PackageLaunchError.DESKTOP_ID_NOT_FOUND ("desktop ID not found");
22- }
23-
24- var app_info = new DesktopAppInfo (desktop_id);
25 if (app_info == null) {
26- throw new PackageLaunchError.APP_INFO_NOT_FOUND ("AppInfo not found for %s ID".printf (desktop_id));
27+ throw new PackageLaunchError.APP_INFO_NOT_FOUND ("AppInfo not found for package: %s".printf (get_name ()));
28 }
29
30 try {
31@@ -332,7 +329,17 @@
32 }
33
34 public bool get_can_launch () {
35- return component.get_desktop_id () != null;
36+ if (app_info_retrieved) {
37+ return app_info != null;
38+ }
39+
40+ string? desktop_id = component.get_desktop_id ();
41+ if (desktop_id != null) {
42+ app_info = new DesktopAppInfo (desktop_id);
43+ }
44+
45+ app_info_retrieved = true;
46+ return app_info != null;
47 }
48
49 private Pk.Package? find_package () {

Subscribers

People subscribed via source and target branches