appstream:/id URL handler #11

Closed
aleixpol opened this Issue Oct 16, 2015 · 4 comments

Projects

None yet

2 participants

@aleixpol
Collaborator

It would be really useful to have such a URL handler so that if the user clicks a URL with "appstream:" scheme, he launches Discover/Gnome-Software/Whatever.

This could help a lot minimize the access barrier to the projects we offer since we'd be leveraging a cross-distro naming scheme, therefore not compromising when giving a package name (like it used to be done with apt:/).

@ximion ximion self-assigned this Oct 16, 2015
@aleixpol
Collaborator

This simple patch does the trick in Discover.

diff --git a/discover/main.cpp b/discover/main.cpp
index 66ba5a7..21bf164 100644
--- a/discover/main.cpp
+++ b/discover/main.cpp
@@ -50,6 +50,7 @@ int main(int argc, char** argv)
         parser.addOption(QCommandLineOption("category", i18n("Display a list of entries with a category."), "name"));
         parser.addOption(QCommandLineOption("mode", i18n("Open Muon Discover in a said mode. Modes correspond to the toolbar buttons."), "name"));
         parser.addOption(QCommandLineOption("listmodes", i18n("List all the available modes.")));
+        parser.addPositionalArgument("urls", i18n("Supports appstream: url scheme"));
         MuonBackendsFactory::setupCommandLine(&parser);
         about.setupCommandLine(&parser);parser.addHelpOption();
         parser.addVersionOption();
@@ -74,6 +75,13 @@ int main(int argc, char** argv)
                 fprintf(stdout, " * %s\n", qPrintable(mode));
             return 0;
         }
+
+        foreach(const QString &arg, parser.positionalArguments()) {
+            QUrl url(arg);
+            if (url.scheme() == QLatin1String("appstream")) {
+                mainWindow->openApplication(url.path());
+            }
+        }
     }

     mainWindow->show();
diff --git a/discover/org.kde.discover.desktop b/discover/org.kde.discover.desktop
index d540f1b..be9128d 100644
--- a/discover/org.kde.discover.desktop
+++ b/discover/org.kde.discover.desktop
@@ -44,7 +44,8 @@ Name[uk]=Шукач Muon
 Name[x-test]=xxMuon Discoverxx
 Name[zh_CN]=Muon 发现者
 Name[zh_TW]=Muon 探詢器
-Exec=muon-discover
+MimeType=x-scheme-handler/appstream
+Exec=muon-discover %U
 Icon=muondiscover
 Type=Application
 X-DocPath=muon/index.html
@ximion
Owner
ximion commented Oct 23, 2015

Will be in the next release, as discussed on IRC :-)
Thanks for reporting this!

@ximion ximion added a commit that closed this issue Nov 3, 2015
@ximion spec: Specify the appstream:// URL handler
The URL handler will be an optional feature (but we recommend it to be
implemented in software-centers).
This resolves #11
40ec324
@ximion ximion closed this in 40ec324 Nov 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment