I couldn’t resist taking RSS Bling, and adding modern offline support to it (instead of HTA/Mozilla specific support from 2+ years ago).
I tackled a very narrow problem. Instead of grabbing feed and post data directly from an online store, I changed the code to:
- Display the feeds and posts, pulling them from the local database (Using the embedded SQLLite DB)
- Try to get updated feeds and posts, and if they are available (e.g. you are online), place them right into the offline store
- Repaint.
This simplified model takes out the complicated syncing piece (and since this is a simple read-only reader, that is quite OK!). There is no checking to see if you are online or offline. There is no visual queue for telling you that (which is a good thing IMO). It should just work.
There are times where you do need to change the UI though of course. It would be nice to say “hey, don’t close the laptop quite yet, I am still downloading all of these feeds so you can read them on the plane”.
For a real offline feed reader, you can use the new Google Reader that runs on Google Gears.
The work is all done in offline.js, and it has a couple of different sections.
The fun piece is the Google Gears work to setup and play with the database.
E.g.
JAVASCRIPT:
-
-
function initDb() {
-
if (!window.google || !google.gears) {
-
return;
-
}
-
-
db = getDb();
-
run(‘create table if not exists feeds (’ +
-
‘id integer not null primary key autoincrement,’ +
-
‘title varchar(255),’ +
-
‘url varchar(255),’ +
-
‘description text)’);
-
-
run(‘create table if not exists posts (’ +
-
‘id integer not null primary key autoincrement,’ +
-
‘feed_id integer,’ +
-
‘title varchar(255),’ +
-
‘url varchar(255),’ +
-
‘content text)’);
-
}
-
-
function getDb() {
-
try {
-
var theDb = google.gears.factory.create(‘beta.database’, ‘1.0′);
-
theDb.open(‘rssbling’);
-
return theDb;
-
} catch (e) {
-
alert(‘Could not create the rssbling database: ‘ + e.message);
-
}
-
}
-
-
/*
-
* Check to see if the feed is already there before adding it
-
*/
-
function addFeed(title, url, description) {
-
var rslt = executeToObjects(’select id from feeds where title = ? and url = ?’, [title, url])[0];
-
if (rslt) { return; }
-
run(‘insert into feeds (title, url, description) values (?, ?, ?)’, [title, url, description]);
-
}
-
-
function selectPosts(feed_id) {
-
return executeToObjects(“select * from posts where feed_id = ?”, [feed_id]);
-
}
-
This has only scratched the surface. I need to integrate the Resource pieces, come up with a problem that would benefit from the WorkerPool, and play.
I can’t wait to see what you all come up with. There is a lot of room to do interesting offline apps, and build libraries on top of Google Gears.
Their approach hasn’t been to boil the ocean of offline, but rather to give us developers a little bit to work with and then we can go to town. The recent model for this is XHR itself. It isn’t the best interface, but it is a nice low-level piece of functionality that we can then riff on top of.