Friday, October 9, 2009

Additional stuff from Developing with Mozilla Prism

Yesterday in my presentation on Developing with Mozilla Prism, I had some difficulties getting an app to work because of an intermittent bug in prism right now.

I did want to post the webapp.js code for the Google Reader prism app that I was showing during the presentation:

/**
* Google Reader web app script
*/

function n(app, msg) {
window.platform.showNotification(app, msg, null);
}

/**
* standard webrunner plugin api
*/
function startup() {
}

function preload() {
}

function load() {
Reader.load();
}

function shutdown() {
Reader.shutdown();
}

function error() {
}

var Reader = {
_timer : null,
_unreadCount : 0,
_window : null,

receiveMessage : function() {
//window.platform.sound().beep();
window.platform.getAttention();

n("Google Reader", "You have " + Reader._unreadCount + " unread item(s).");
},

_init : function() {
Reader._unreadCount = 0;
Reader._window = window;
},

run : function() {
if (Reader._unreadCount == undefined)
Reader._unreadCount = 0;

var title = Reader._window.top.document.title;

var matches = title.match(/Google Reader \((\d+)\)/);
if (matches) {
if (matches[1] > Reader._unreadCount) {
Reader._unreadCount = matches[1];
Reader.receiveMessage();
}

Reader._unreadCount = matches[1];
}
},

load : function() {
Reader._init();
// kick off a polling timer to check for new articles
Reader._timer = Reader._window.setInterval(Reader.run, 5000);
},

shutdown : function() {
if (Reader._timer)
Reader._window.clearInterval(Reader._timer);
}
};


Also, the MIME type to add to your httpd.conf to allow prism webapp bundles to load properly by linking to them is:

AddType application/x-webapp .webapp


Talking with Matt Gertner a little about adding javascript to your own web page... He said that you could use the window.platform stuff in your webapp and that would, in many cases, simply replace the need for webapp.js since your web page would then essentially become prism aware. That's another option for trying to distribute a prism app.

For more information on prism - check out https://developer.mozilla.org/en/Prism

No comments: