ShareProvider receiver for url sharing from browser is failing

I’m trying to register a share provider for my app. The expectation: I would be able to share url from the browser to my app as text or url (you can share url with sms for example).

I managed to successfully register the app and the share option appears on the browser. Unfortunately when I tap it I got this error from silica.Share 1.0:

``bash
[W] unknown:17 - file:///usr/share/harbour-app/qml/harbour-app.qml:17:5: QML ShareProvider: Shared resource map did not contain valid ‘name’ or ‘data’ values
[W] unknown:17 - file:///usr/share/harbour-app/qml/harbour-app.qml:17:5: QML ShareProvider: No usable resources
``

On the phone I got two different messages based on some random feature:
File cannot be shared, or share with app failed

I have seen this problem also.

It appears link sharing from Browser/Webview does not follow the specification form Sailfish.Share:

As you can see, the object that is generated does not have the “name” and “data” keys required by ShareResource.

Now, you can see that the Messages application handles this in a special DBusAdaptor handler, /usr/share/jolla-messages/messages.qml line 142ff. (I would quote it here, but that file has a notice that the source is proprietary.)

This seems to me a bug and/or unresovled technical debt in the WebView component.


In case the error is “Could not share to AppName”, there should be a journal entry asying something like

 Failed to share: org.freedesktop.DBus.Error.ServiceUnknown with message: The name foo.Bar was not provided by any .service files

So the dbus interface was not registered properly. I guess this is the race condition mentioned in the docs.

1 Like

I have created this bug report:

6 Likes

Okay, it seems this workaround is working:

  1. in the .desktop, have a method called link (along with any other methods you support)
  2. for each of the sharing method except link, implement a ShareProvider as usual.
  3. Have something like the following:

import QtQuick 2.6
import Sailfish.Share 1.0
import Nemo.DBus 2.0

[...]

    ShareProvider { id: filesProvider
        method: "files"
        //capabilities: ["image/png", "image/jpeg"]
        // registerName: true

        onTriggered: {
           [ ... do things ...]
        }
    }

    // used by the Adapter below to load the resource object
    ShareAction { id: shareAction }

    // workaround for https://github.com/sailfishos/sailfish-components-webview/issues/180
    DBusAdaptor {
        service: "my.app.organame.appname"
        path: "/share/link" // <-- must correspond to method from .desktop
        iface: "org.sailfishos.share"

        function share(shareConfiguration) { // must be called "share"
            shareAction.loadConfiguration(shareConfiguration)
            var resources = shareAction.resources
            var handledHere = false
            console.debug("Special Sharing handler for:", JSON.stringify(resources, null, 2))
            /* URLs are shared by Browser in this format:
            {
                "type": "text/x-url",
                "linkTitle": linkTitle,
                "status": linkHref,
            }
            */
            if (resources[0].type === "text/x-url") {
                handledHere = true
                const sharedlink = resources[0].status
                [ ... do more things ...]
            }
            // in case it was something else, handle it there:
            if (!handledHere) someOtherProvider.trigger(resources)
        }
    }

2 Likes

Thanks a lot it seems we get one step further. I’ve added proposed solution and now I have infinitely spin screen:
”Share Link <image.gif>” in browser, the app never become active, no logs or anything from inside the app (app is running as well)
I’m using the c++ DBus registration for the service

QDBusConnection dbus = QDBusConnection::sessionBus();
if (!dbus.registerService("my.app.organame.appname")) {
  qWarning() << "Error:" << dbus.lastError().message();
}

before the start qml part, otherwise the is log message that register with DBusAdaptor is failing

That string is just an example. You will need to use your app’s ID as specified in the Sailjail part of the .desktop file.

So if your app has

[X-Sailjail]
ApplicationName=MyApp
OrganizationName=my.app.orga

… the correct DBus name is my.app.orga.MyApp

And while I don’t know if there’s a better way, what seems t work for me in registering DBus names for Sharing is:

Yes, I’m using the one I have in .desktop file.

What I seen:

  • install app
  • logs that dbus is registered
  • open browser
  • tap on share
  • two items: share with sms, share with my app
  • tap on my app
  • new popup opens: Share Link running progress circle

the focus comes never to my app

Nevermind, as I’ve started build RPM I’ve realised that Shared is not allowed permission on harbour, so it make no sense to support this feature: Allowed Permissions | Sailfish OS Documentation

Sharing permission is included by default, so you don’t need to add it in the desktop file.
And it is possible to have the feature in and permitted in Harbour.