Merge lp:~donadigo/appcenter/apt-link-support into lp:~elementary-apps/appcenter/appcenter

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Corentin Noël
Approved revision: 357
Merged at revision: 356
Proposed branch: lp:~donadigo/appcenter/apt-link-support
Merge into: lp:~elementary-apps/appcenter/appcenter
Diff against target: 121 lines (+54/-1)
4 files modified
data/org.pantheon.appcenter.desktop.in.in (+1/-0)
src/Application.vala (+37/-1)
src/Core/Client.vala (+11/-0)
src/MainWindow.vala (+5/-0)
To merge this branch: bzr merge lp:~donadigo/appcenter/apt-link-support
Reviewer Review Type Date Requested Status
Corentin Noël Approve
Review via email: mp+313889@code.launchpad.net

Commit message

* Add support for appstream links

Description of the change

This branch fixes bug #1628476: "Affiliate AppCenter with x-scheme-handler/apt mime type".

Most of the scheme handling code was taken from the recent switchboard change at revision 691.

This branch actually implements handling for appstream links as discussed on Slack instead of apt links.

To test run e.g:
appcenter appstream://org.pantheon.snap.desktop

To post a comment you must log in.
357. By Adam Bieńkowski

Instead of apt, support appstream

Revision history for this message
Corentin Noël (tintou) wrote :

Tested with xdg-open appstream://org.pantheon.appcenter.desktop
Working as expected

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/org.pantheon.appcenter.desktop.in.in'
--- data/org.pantheon.appcenter.desktop.in.in 2016-06-18 05:11:27 +0000
+++ data/org.pantheon.appcenter.desktop.in.in 2016-12-27 23:46:08 +0000
@@ -8,6 +8,7 @@
8Type=Application8Type=Application
9StartupNotify=true9StartupNotify=true
10Categories=GNOME;GTK;System;PackageManager;10Categories=GNOME;GTK;System;PackageManager;
11MimeType=x-scheme-handler/appstream;
11Actions=AboutDialog;12Actions=AboutDialog;
12X-GNOME-UsesNotifications=true13X-GNOME-UsesNotifications=true
1314
1415
=== modified file 'src/Application.vala'
--- src/Application.vala 2016-12-06 22:05:26 +0000
+++ src/Application.vala 2016-12-27 23:46:08 +0000
@@ -25,12 +25,14 @@
2525
26 private const int SECONDS_AFTER_NETWORK_UP = 60;26 private const int SECONDS_AFTER_NETWORK_UP = 60;
2727
28 private static string? link = null;
29
28 public static bool show_updates;30 public static bool show_updates;
29 public static bool silent;31 public static bool silent;
30 MainWindow main_window;32 MainWindow main_window;
31 construct {33 construct {
32 application_id = "org.pantheon.appcenter";34 application_id = "org.pantheon.appcenter";
33 flags = ApplicationFlags.FLAGS_NONE;35 flags |= ApplicationFlags.HANDLES_OPEN;
34 Intl.setlocale (LocaleCategory.ALL, "");36 Intl.setlocale (LocaleCategory.ALL, "");
35 Intl.textdomain (Build.GETTEXT_PACKAGE);37 Intl.textdomain (Build.GETTEXT_PACKAGE);
3638
@@ -63,10 +65,35 @@
63 }65 }
64 });66 });
6567
68 if (AppInfo.get_default_for_uri_scheme ("appstream") == null) {
69 var appinfo = new DesktopAppInfo (app_launcher);
70 try {
71 appinfo.set_as_default_for_type ("x-scheme-handler/appstream");
72 } catch (Error e) {
73 critical ("Unable to set default for the settings scheme: %s", e.message);
74 }
75 }
76
66 add_action (quit_action);77 add_action (quit_action);
67 add_accelerator ("<Control>q", "app.quit", null);78 add_accelerator ("<Control>q", "app.quit", null);
68 }79 }
6980
81 public override void open (File[] files, string hint) {
82 var file = files[0];
83 if (file == null) {
84 return;
85 }
86
87 if (file.has_uri_scheme ("appstream")) {
88 link = file.get_uri ().replace ("appstream://", "");
89 if (link.has_suffix ("/")) {
90 link = link.substring (0, link.last_index_of_char ('/'));
91 }
92 }
93
94 activate ();
95 }
96
70 public override void activate () {97 public override void activate () {
71 var client = AppCenterCore.Client.get_default ();98 var client = AppCenterCore.Client.get_default ();
72 if (silent) {99 if (silent) {
@@ -88,6 +115,15 @@
88 main_window = null;115 main_window = null;
89 });116 });
90117
118 if (link != null) {
119 var package = client.get_package_for_id (link);
120 if (package != null) {
121 main_window.show_package (package);
122 } else {
123 warning (_("Specified link '%s' could not be found, going back to the main panel").printf (link));
124 }
125 }
126
91 add_window (main_window);127 add_window (main_window);
92 main_window.show_all ();128 main_window.show_all ();
93 if (show_updates) {129 if (show_updates) {
94130
=== modified file 'src/Core/Client.vala'
--- src/Core/Client.vala 2016-12-02 09:24:22 +0000
+++ src/Core/Client.vala 2016-12-27 23:46:08 +0000
@@ -466,6 +466,17 @@
466 return installed;466 return installed;
467 }467 }
468468
469 public AppCenterCore.Package? get_package_for_id (string id) {
470 foreach (var entry in package_list.entries) {
471 var package = entry.value;
472 if (package.component.id == id) {
473 return package;
474 }
475 }
476
477 return null;
478 }
479
469 private static GLib.Once<Client> instance;480 private static GLib.Once<Client> instance;
470 public static unowned Client get_default () {481 public static unowned Client get_default () {
471 return instance.once (() => { return new Client (); });482 return instance.once (() => { return new Client (); });
472483
=== modified file 'src/MainWindow.vala'
--- src/MainWindow.vala 2016-11-06 15:33:30 +0000
+++ src/MainWindow.vala 2016-12-27 23:46:08 +0000
@@ -184,6 +184,11 @@
184 return false;184 return false;
185 }185 }
186186
187 public void show_package (AppCenterCore.Package package) {
188 category_view.show_package (package);
189 view_opened (_("Categories"), false, null);
190 }
191
187 public void go_to_installed () {192 public void go_to_installed () {
188 view_mode.selected = 1;193 view_mode.selected = 1;
189 }194 }

Subscribers

People subscribed via source and target branches