Intents

From WebOS-Ports
Revision as of 14:10, 10 November 2014 by DougReeder (talk | contribs) (tweaks)
Jump to: navigation, search

Proposed "Lune OS Intents"

Rationale

There are a number of common actions that apps should delegate to other apps: sending an email, selecting a picture to insert, sharing a link, picking a contact, etc. webOS provided a few custom mechanisms for critical actions and a general mechanism for an app to call another, known app. These don't generalize nor extend well. Custom mechanisms depend on OS updates. To share a link, an app had to know the correct launchParam for every app for every service.

Overview

The proposal is provide an extensible mechanism similar to Android Intents/Web Intents/Web Activities.

There is a short list of well-known "verbs", such as "share", "edit", "view", "pick", "save", "dial". New verbs should be developed by consensus. Verbs should harmonize with Just Type so far as reasonable. Apps may freely experiment with namespaced verbs, for example "NinjaGroup:slice".

Any app may register to handle any verb, and usually a list of MIME types of data it handles. (We do not expect the same app to "edit" "text/plain" and "image/jpeg".) Mime types may be generic, such as text/*, image/* or */*.

Each verb defines a "data" object to be passed, with required and optional properties, with required semantics. Optional means the *user* need not specify the property, but handlers MUST implement it. (For example, if the verb "share" defines an optional "attachment" property, a handler MUST support attachments.) Apps MAY pass additional data properties, but SHOULD first seek consensus, as nonstandard properties are only hints, at best.

Each verb defines the parameters it returns.

Any app may request any Intent. As *any* Intent may require user input to complete, the client app SHOULD NOT block on the request. Intents always return at least success or failure. The simplest failure is that there was no registered handler.

When a client app requests a new Intent, the system

  • searches its database to find handlers which can handle the MIME type
  • if there is no match, immediately returns failure to the client and displays system UI to the user, informing her that she must install a handler app, and offering to launch Preware.
  • if the user has previously designated a preferred handler for that verb and MIME type, sends a request to the handler without presenting system UI.
  • otherwise, the system presents a list of handler apps to the user, plus the option Cancel.
  • if the user cancels, the system returns failure to the client
  • if the user selects an app, the system closes its UI, requests the handler app to do its thing, and waits for a response
  • when the handler responds to the request (which might be hours later), passes the response to the client (without further system UI).

User Experience

The weak point of Intents is that handler apps must be installed before client apps, and the user does not, in general, know she might need a handler app before using a client app. In general, a verb SHOULD NOT be on the "well-known" list until there is a system default handler, such as a generic file picker that can fulfill a "pick" request of any MIME type.

So, handler apps provide either new implementations of actions (for example, an image editor with new features beyond cropping) or new destinations (sharing to Twitter, rather than just via email or messaging).

A possible future extension would, when there is no registered handler, for the system to search Preware feeds. That would require extending Preware to search for app by handled Intents.

Registering Handlers

An app registers in its appinfo.json.

Sample Schema

{
...
    "intents": [
       {"name": "edit", "types": ["image/jpeg", "image/png"]},
       {"name": "view", "types": ["image/*"]}
    ] 
...
}

The data object is defined by the verb, not by the app, so it is not documented in appinfo.json.

When the system calls a handler, it passes name, type and data in an intent appParam:

"intent": {
    "name": "edit",
    "type": "image/jpeg",
    "data": {
        "original": "/media/internal/DCIM/100PALM/CIMG0711.jpg",
        "target": "/media/internal/myArt/autmun.jpg"
    }
}

Client Requests

Requests are made on the PalmBus, to org.webosports.intents with the method new, with the parameters name, type (optional) and data (optional). (or maybe palm://com.palm.applicationManager and method newIntent.)

Sample:

luna-send -n 1 luna://org.webosports.intents/new '{"name": "edit", "type": "image/jpeg", "data": {"original": "/media/internal/DCIM/100PALM/CIMG0711.jpg", "target": "/media/internal/myArt/autmun.jpg"} }'

returning

{ "returnValue": true, "modified": "/media/internal/myArt/autmun.jpg" }

Proposed Initial Verbs & Data

Long term, we'd like to supersede everything listed at https://developer.palm.com/content/api/reference/application-apis.html , but we must get data for each verb right, or we'll regret it forever. Every handler for a verb must be able to meaningfully deal with the verb's standard data parameters.


View

Similar to luna://com.palm.applicationManager/open, but allows the user to select a handler.

One data parameter: "target", a URL, which may be a file: URL.

Returns only success / failure.


Pick

Request the user to select a single chunk of data, with an optional type. No data parameters.

[Does it return data inline, a file path, a URL? Is that up to the handler? We should accommodate URLs - the client may not need the whole file. We probably want file paths to be distinct from URLs, since an image path can be used opaquely to set a background or avatar.]

For example, "pick" with type "image/*" should have at least three system handlers: a thumbnail selector that uses the Media Indexer, the standard Camera app and the standard file dialog.

Presumably, the Memos app will support type "text/plain" and/or "text/*"

The standard file dialog should register for type "*/*". A Dropbox app would presumably also contain a handler for type "*/*".

"pick" with some weird type will always match (at least) the standard file dialog.


Save

[should this pass data inline? Alternatively, it could pass a path to a temporary file]

[What are the return parameters?]

The system will provide a handler (the standard file dialog) for type "*/*".

A Dropbox, Box, etc. app should have a handler for type "*/*".

A photo site should provide a handler for type "image/*" or maybe just "image/jpeg".


Share

[Is there common data that IM, SMS, Twitter, Bluetooth sharing, etc. would accept? Do we pass a single chunk of info (for example, text or the path of an image file) and let the user add additional chunks in the handler? Do they all accept text and an image attachment? Do we need one verb ("share"?) for sharing short text, and another ("shareWithAttachment"?) for short text plus attachment? Are there MIME types relevant to this?]

[It may not make sense to allow recipients here - those should probably be filled in by the handler. And why should client apps know anything about recipients?]

(In addition to standard "messaging" apps, presumably email would also register as a handler.)


Mapping

[Mapping a location, and mapping a route are probably separate verbs. It's not clear what role MIME types will play here.]


Verbs Believed To Be Unnecessary

  • take a picture (handled by "Pick" "image/*")
  • Messaging (handled by "share" verb/verbs)