On Nov 21, 2013 12:06 PM, "Luke Wagner" <
lu...@mozilla.com> wrote:
>
> I have a specific use case which Jonas thought motivated a general solution to a related set of problems:
>
> There are plans and a patch (in bug 839058) for an 'install-complete' message delivered to interested apps right after installation. Unfortunately, the handling of this message does not block the FFOS install UI which means that the app can be launched before it has finished handling 'install-complete'.
We should do two things here.
1. Improve system messages
We should add a way for applications to indicate that they have
handled a system message. Ehsan provided one such syntax. I would
prefer to reuse the syntax that Service Workers use:
setMessageHandler("install-complete", myHandler);
function myHandler(messageData, message) {
// messageData is what we're already sending with all system messages.
// It's contents depends on the specific system message
promise = doAsyncWork(messageData);
message.waitUntil(promise);
}
The new part here is the second argument to the message handler. This
object just has a single function, waitUntil. If called before the
message handler returns, it signals that the page needs to do more
work before it has fully handled the message.
To signal that you've handled the message, resolve the passed in promise.
This also enables the app to signal that it was unable to process the
message. To do this reject the promise passed to waitUntil.
This also means that we need to extend our internal APIs that we use
to send system messages. That API should return a promise. The promise
is rejected if the app crashes before it has time to finish running
the system message handler, or if the promise passed to waitUntil is
rejected.
The promise is resolved if the handler successfully returns from the
system message handler without calling waitUntil and without crashing.
The promise is also resolved if the promise passed to waitUntil is
successfully resolved.
2. Make install-complete delay the app being installed.
We should not consider an app fully installed until the
install-complete message handler has been fully run.
This is a little bit tricky since all parts of our platform needs to
consider the app fully installed so that it can run normally. However
the WebApp API should still indicate that the app isn't installed so
that the homescreen doesn't show it as installed, and so that the
marketplace doesn't show it as installed.
/ Jonas