Permalink
Browse files

create a Notification module that transparently handles Fluid or Pris…

…m API
  • Loading branch information...
1 parent 88e70d8 commit 3c991758bff246ff0c89a42477ca0124ba3e37c7 @mislav committed Jun 18, 2009
Showing with 47 additions and 19 deletions.
  1. +1 −0 endless_tweets/endless_tweets.js
  2. +5 −19 endless_tweets/polling.js
  3. +41 −0 toolkit/notification.js
@@ -356,6 +356,7 @@ if (wrapper) checkUserscriptUpdate(scriptURL, $et.scriptSize, function() {
})
//= toolkit/toolkit.js
+//= toolkit/notification.js
function twitterLinkify(text) {
return linkify(text, true).
View
@@ -1,5 +1,4 @@
-var polling = getValue('polling', false),
- growls = window.fluid ? [] : null
+var polling = getValue('polling', false)
function updateTimestamps() {
var now = new Date()
@@ -25,10 +24,10 @@ function deliverUpdate(data) {
removeChild(find($et.timeline, '> li[last()]'))
// never send Growl notifications for own tweets
- if (growls && data.user.screen_name != $et.currentUser) {
+ if (Notification.supported && data.user.screen_name != $et.currentUser) {
var title = data.user.screen_name + ' updated ' + strip(find(update, '.published').textContent),
description = data.text.replace(/&lt;/g, '<').replace(/&gt;/g, '>')
- growls.push({
+ Notification.enqueue({
title: title, description: description, icon: find(update, '.author img'),
identifier: 'tw' + data.id, onclick: function() { window.fluid.activate() }
})
@@ -53,21 +52,8 @@ function checkUpdates() {
count++
}
}
- if (growls) {
- var limit = growls.length - 4
- for (var i = growls.length - 1; i >= 0; i--) {
- if (i < limit) {
- window.fluid.showGrowlNotification({
- title: '(' + limit + ' more update' + (limit > 1 ? 's' : '') + ')',
- description: '',
- onclick: function() { window.fluid.activate() }
- })
- break
- }
- window.fluid.showGrowlNotification(growls[i])
- }
- growls = []
- }
+ Notification.release()
+
if (count) {
$et.setLastRead(data.id)
livequeryRun()
View
@@ -0,0 +1,41 @@
+var Notification = (function() {
+ var fluid = window.fluid && typeof window.fluid.showGrowlNotification == "function",
+ prism = window.platform && typeof window.platform.showNotification == "function",
+ supported = fluid || prism,
+ queue = []
+
+ if (!supported) {
+ var show = function() {}
+ } else if (fluid) {
+ var show = window.fluid.showGrowlNotification
+ } else {
+ var show = function(params) {
+ window.platform.showNotification(params.title, params.description, params.icon)
+ }
+ }
+
+ return {
+ supported: supported,
+ show: show,
+ enqueue: function(params) {
+ if (!supported) return
+ queue.push(params)
+ },
+ release: function() {
+ if (!supported) return
+ var limit = queue.length - 4
+ for (var i = queue.length - 1; i >= 0; i--) {
+ if (i < limit) {
+ Notification.show({
+ title: '(' + limit + ' more update' + (limit > 1 ? 's' : '') + ')',
+ description: '',
+ onclick: function() { if (fluid) window.fluid.activate() }
+ })
+ break
+ }
+ Notification.show(queue[i])
+ }
+ queue = []
+ }
+ }
+})()

0 comments on commit 3c99175

Please sign in to comment.