App as endpoint in Share API chain

Hi. It is relatively easy. But not such easy as on standard Linux, when you can add just one line to desktop file. Because Sailfish executes application in single instance, you have to register D-Bus service to listen for “open” actions when your application is running already. You can get inspiration in Jolla’s Mediaplayer app, that is registered for opening audio files.

In /usr/share/applications/jolla-mediaplayer.desktop file are important these lines:

MimeType=audio/*;
X-Maemo-Service=com.jolla.mediaplayer
X-Maemo-Object-Path=/com/jolla/mediaplayer/ui
X-Maemo-Method=com.jolla.mediaplayer.ui.openUrl

To make open action working, there is important D-Bus registration in file /usr/share/dbus-1/services/com.jolla.mediaplayer.service:

[D-BUS Service]
Name=com.jolla.mediaplayer
Exec=/usr/bin/invoker -s --type=generic /usr/bin/sailjail -p jolla-mediaplayer.desktop /usr/bin/jolla-mediaplayer -prestart

Last missing piece is D-Bus service in app itself. In /usr/share/jolla-mediaplayer/mediaplayer.qml is:

    DBusAdaptor {
        service: "com.jolla.mediaplayer"
        path: "/com/jolla/mediaplayer/ui"
        iface: "com.jolla.mediaplayer.ui"

        function activateWindow(arg) {
            root.activate()
        }

        function openUrl(arg) {
            if (arg.length === 0) {
                root.activate()

                return true
            }

            AudioPlayer.playUrl(Qt.resolvedUrl(arg[0]))
            if (!pageStack.currentPage || pageStack.currentPage.objectName !== "PlayQueuePage") {
                pageStack.push(playQueuePage, {}, PageStackAction.Immediate)
            }
            dockedPanel().open = true
            activate()

            return true
        }
    }

You can test it from command line:

xdg-open path/to/some/song.mp3

This mechanism is not allowed in Harbour unfortunately. But you can distribute additional files in extra package on OpenRepos :slight_smile: I am doing that in OSM Scout, url support | OpenRepos.net — Community Repository System

4 Likes