App as endpoint in Share API chain

Hi everyone!

The application works with .zip and .csv files, and in order to open them, I need to first launch the application, open a file dialog and find the file I need. I would like to transfer them directly from mail client or file browser or messenger etc. How can this be done? It smells like Share API) But there is not enough information.

Thanks!

2 Likes
  1. Your app should be able to do appname filepath and open/deal with a file given in filepath
  2. create a .desktop file which calls the app as ‘appname %U’, and register a mime handler for each file you can handle.

Best look for how other apps do that and copy them.

1 Like

For the share API afaik you have to register a dbus service, and launch your app with file path through that.

1 Like

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

Thanks to @karry and @nephros for help!