Desktop notifications for orangereds!

This commit is contained in:
Kerrick Long
2011-07-18 19:38:18 -05:00
parent acfcdc4374
commit 24eae6e666
6 changed files with 101 additions and 4 deletions
+11
View File
@@ -388,5 +388,16 @@
"content": "</a>"
}
}
},
"orangered_received": {
"message": "You have an $ORANGERED$!",
"placeholders": {
"ORANGERED": {
"content": "orangered"
}
}
},
"orangered_action": {
"message": "Click here to be taken to your inbox."
}
}
+33
View File
@@ -67,6 +67,39 @@ this.manifest = {
"type": "description",
"text": "<p>When checked, this will add the following to each commment you post from within Mostly Harmless:</p><p><em>Posted from <a href='http://kerrick.github.com/Mostly-Harmless'>Mostly Harmless</a>, a Google Chrome extension for awesome redditors.<em></p>"
},
{
"tab": "Preferences",
"group": "Orangered Notifications",
"name": "checkMail",
"type": "checkbox",
"label": "Check for orangereds"
},
{
"tab": "Preferences",
"group": "Orangered Notifications",
"name": "mailInterval",
"type": "slider",
"label": "",
"max": 5,
"min": 0,
"step": 1,
"display": true,
"displayModifier": function (value) {
if (value === 0)
return "every 30 seconds";
else if (value === 1)
return "every minute";
return "every " + value.toString() + " minutes";
}
},
{
"tab": "Preferences",
"group": "Orangered Notifications",
"name": "mailDescription",
"type": "description",
"text": "<p>When checked, Mostly Harmless will check for new orangereds at the interval you set. If you get an orangered, it will display a desktop notification for five seconds.</p>"
},
{
"tab": "Performance",
"group": "Cache Time",
+1
View File
@@ -15,6 +15,7 @@
cache.removeAll();
button.setBadgeDefaults();
chrome.tabs.onUpdated.addListener(background.prepareBrowserAction);
background.watchMail();
}
window.onload = initBackground;
+54 -3
View File
@@ -6,7 +6,9 @@ settings = new Store('settings', {
'freshCutoff': 7,
'popupWidth': 640,
'shamelessPlug': false,
'waitForClick': false
'waitForClick': false,
'checkMail': true,
'mailInterval': 1
});
cache = new Store('cache');
@@ -205,7 +207,7 @@ BrowserAction.prototype.setBadgeDefaults = function (tabId) {
chrome.browserAction.setTitle({'title': 'Click to load data.', 'tabId': tabId});
chrome.browserAction.setBadgeBackgroundColor({'color': [192, 192, 192, 255], 'tabId': tabId});
chrome.browserAction.setPopup({popup: '', tabId: tabId});
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.browserAction.onClicked.addListener(function (tab) {
reddit.getInfo(tab.url, tab.id);
});
return true;
@@ -258,7 +260,7 @@ BrowserAction.prototype.setBadgeError = function (tabId, text) {
chrome.browserAction.setTitle({'title': text, 'tabId': tabId});
chrome.browserAction.setBadgeBackgroundColor({'color': [200, 0, 0, 255], 'tabId': tabId});
chrome.browserAction.setPopup({popup: '', tabId: tabId});
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.browserAction.onClicked.addListener(function (tab) {
reddit.getInfo(tab.url, tab.id);
});
return true;
@@ -770,6 +772,55 @@ Background.prototype.prepareBrowserAction = function (tabId, info, tab) {
return true;
};
/**
* Sets a timeout for the next time to run checkMail.
* @alias Background.watchMail()
* @return {Boolean} Returns true.
* @method
*/
Background.prototype.watchMail = function () {
var mailProcess;
function showNotification (hasMail) {
var notification, notificationTimeout, mailInterval;
mailInterval = (settings.get('mailInterval') === 0) ? 1000 * 30 : settings.get('mailInterval') * 1000 * 60;
if (hasMail === true) {
console.log('Orangered! I need to show a notification...');
notification = webkitNotifications.createNotification(
'/pix/mail.png', // icon url - can be relative
chrome.i18n.getMessage('orangered_received'), // notification title
chrome.i18n.getMessage('orangered_action') // notification body text
);
notificationTimeout = window.setTimeout(function () {
notification.cancel();
}, 1000 * 5);
notification.onclick = function () {
chrome.tabs.create({'url': 'http://' + reddit.domain + '/message/unread/', 'selected': true});
notification.cancel();
window.clearTimeout(notificationTimeout);
};
notification.show();
window.setTimeout(checkPrefs, mailInterval);
}
}
function getMail () {
reddit.apiTransmit('GET', 'http://' + reddit.domain + '/api/me.json', null, function (response) {
showNotification(response.data.has_mail);
});
}
function checkPrefs () {
if (settings.get('checkMail') === true) {
getMail();
}
}
checkPrefs();
};
/**
* Creates a new framework of popup processes
* @classDescription Creates a new framework of background processes.
+2 -1
View File
@@ -8,7 +8,8 @@
},
"permissions": [
"http://*.reddit.com/",
"tabs"
"tabs",
"notifications"
],
"background_page": "html/background.html",
"options_page": "fancy-settings/index.html",
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB