Thanks Etienne, that sounded like a good idea. I was just testing it and the 
"notification" handler gets hardly called. 

This is what I have in the manifest:
        "messages": [
                { "alarm": "/index.html" },
                { "notification": "/index.html" }
        ],
        "permissions": {
                "desktop-notification": { "description": "..." },
                "alarms": { "description": "..." }
        },


And this is the code in index.html:

function setAlarm() {
        // delete existing alarms before creating new one
        var request = navigator.mozAlarms.getAll();
        request.onsuccess = function () {
                this.result.forEach(function (alarm) {
                        navigator.mozAlarms.remove(alarm.id);
                });
        };
        request.onerror = function () { 
                console.log("error querying alarms");
        };

        
        request = navigator.mozAlarms.add(new Date(new Date().getTime() + 
60000), "honorTimezone");
        request.onsuccess = function () {
                console.log("alarm request success");
        };
        request.onerror = function () { 
                console.log("alarm request fail");
        };
}

        window.navigator.mozSetMessageHandler("notification", function (data) {
                console.log("noti fired");
        });
        window.navigator.mozSetMessageHandler("alarm", function (data) {
                console.log("alarm fired"); 
                  
                var wakeLock = window.navigator.requestWakeLock("cpu");
                
                var notification = navigator.mozNotification.createNotification(
                                "title", "message", null
                );
                notification.onclick = function() {
                        console.log("onclick");
                };
                notification.onclose = function() {
                        console.log("onclose");
                };
                notification.show();
                        
                wakeLock.unlock();
                
                setAlarm();
        });

To reproduce, you'll have to start index.html once. Afterwards flush it from 
the loaded pages by long pressing the home button and cancelling it.

I'll create an issue report later in any case, this is just to check my 
"notification" system message handler.


On Monday, August 5, 2013 11:14:46 AM UTC+2, Etienne Segonzac wrote:
> On Mon, Aug 5, 2013 at 10:18 AM, Michael Diener <
> 
> [email protected]> wrote:
> 
> 
> 
> > Thanks Antonio, but the system messages are delivered successfully in my
> 
> > case.
> 
> >
> 
> 
> 
> Yep, gecko queues the messages waiting for the message handler to be set.
> 
> 
> 
> 
> 
> >
> 
> > When they are delivered, the endpoint page is not yet in memory and gets
> 
> > loaded successfully so the message handlers are triggered. Then my code in
> 
> > that handler acquires a wakelock and displays a notification. This
> 
> > notification is successfully displayed, but onclick is not called when
> 
> > clicking the notification.
> 
> >
> 
> 
> 
> You should be able to register for the "notification" system message in
> 
> order to be notified of the notification click even if your app got killed
> 
> (and the notification.onlick handler gced).
> 
> --
> 
> Etienne
_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g

Reply via email to