raininglemons
raininglemons

Reputation: 460

Are you able to update a webkitNotifications?

Had a look around an can only really find resources on creating notifications, and not updating them. Heard it might be possible if I used chrome.notifications instead but again can't find anyway to do it.

This currently is my code, and it ends up just closing any previous notification then reissuing it.

        if (window.webkitNotifications){
            if(window.webkitNotifications.checkPermission() > 0){

            }
            else if (seconds == 0)
            {
                var thumb = 'images/icon.png';
                var title = 'Current Task';
                var body = "Active " + hours + " hours and " + minutes + " minutes";

                if (popup != "") {
                    popup.cancel();
                }
                popup = window.webkitNotifications.createNotification(thumb, title, body);
                popup.show();

            }
        }

Anyone know if it's possible to update a notification instead of just recreate it? Would make it much more user friendly, and for a live feed of information more of a float over any other job they might be doing?

Upvotes: 0

Views: 233

Answers (1)

Michael Johansen
Michael Johansen

Reputation: 5096

Once the notification has been created, the way to communicate with it is through message passing. Read up on it here: http://developer.chrome.com/extensions/messaging.html

Timeline:

  1. Background process creates notification with content. Notifiation is created and starts listening for messages, all well and good.
  2. Background process finds new information and checks whether the notification is still alive (via a variable in localStorage or usage of the Tabs API, or however you want to do this).
  3. If notification was found to be alive, background process passes a message about new information, which the notification picks up and displays.

Upvotes: 2

Related Questions