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
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.
in the .desktop, have a method called link (along with any other methods you support)
for each of the sharing method exceptlink, implement a ShareProvider as usual.
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)
}
}
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
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.