1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-26 03:02:25 -05:00

Use new notifications lib

This commit is contained in:
Lance Stout 2013-10-11 15:40:42 -07:00
parent 943dff7b69
commit 5e0ffdb154
7 changed files with 22 additions and 80 deletions

View File

@ -12,7 +12,7 @@ var MainView = require('./views/main');
var Router = require('./router');
var Storage = require('./storage');
var xmppEventHandlers = require('./helpers/xmppEventHandlers');
var notifier = require('./helpers/notifications');
var Notify = require('notify.js');
module.exports = {
@ -20,7 +20,6 @@ module.exports = {
var self = window.app = this;
var config = localStorage.config;
self.notifier = notifier;
if (!config) {
console.log('missing config');
@ -33,6 +32,7 @@ module.exports = {
async.series([
function (cb) {
app.notifications = new Notify();
app.storage = new Storage();
app.storage.open(cb);
},

View File

@ -1,60 +0,0 @@
// simple module for showing notifications using growl if in fluid app,
// webkit notifications if present and permission granted and using UI Kit
// as an in-browser fallback. #winning
/*global ui */
/* Here's the api... pretty simple
{
title: <text>,
description: <text>
sticky: <bool>,
callback: <fn>,
icon: <url of image>
}
*/
var templates = require('../templates');
exports.show = function (opts) {
var hideTimeout = 5000,
note;
// set default icon
opts.icon || (opts.icon = '/images/applogo.png');
if (window.macgap) {
window.macgap.growl.notify(opts);
} else if (window.fluid) {
window.fluid.showGrowlNotification(opts);
} else if (window.webkitNotifications && window.webkitNotifications.checkPermission() === 0) {
note = window.webkitNotifications.createNotification(opts.icon, opts.title, opts.description);
note.show();
if (!opts.sticky) {
setTimeout(function () {
note.cancel();
}, hideTimeout);
}
if (opts.onclick) note.onclick = opts.onclick;
} else {
// build some HTML since we want to include an image
note = ui.notify(templates.misc.growlMessage(opts)).closable();
if (opts.sticky) {
note.sticky();
} else {
note.hide(hideTimeout);
}
if (opts.onclick) note.on('click', opts.onclick);
}
};
exports.shouldAskPermission = function () {
return (window.webkitNotifications && (window.webkitNotifications.checkPermission() !== 0) && (window.webkitNotifications.checkPermission() !== 2)) || false;
};
exports.askPermission = function (cb) {
if (!window.webkitNotifications) {
cb(false);
} else {
window.webkitNotifications.requestPermission(function () {
if (cb) cb(window.webkitNotifications.checkPermission() === 0);
});
}
};

View File

@ -174,10 +174,10 @@ module.exports = HumanModel.define({
if (notify && (!this.activeContact || (this.activeContact && !app.state.focused)) && message.from.bare === this.jid) {
this.unreadCount++;
app.notifier.show({
title: this.displayName,
description: message.body,
app.notifications.create(this.displayName, {
body: message.body,
icon: this.avatar,
tag: this.jid,
onclick: _.bind(app.navigate, app, '/chat/' + this.jid)
});
}

View File

@ -63,10 +63,10 @@ module.exports = HumanModel.define({
if (notify && (!this.activeContact || (this.activeContact && !app.hasFocus))) {
this.unreadCount++;
app.notifier.show({
title: this.displayName,
description: message.body,
app.notifications.create(this.displayName, {
body: message.body,
icon: this.avatar,
tag: this.id,
onclick: _.bind(app.navigate, app, '/chat/' + this.jid)
});
}

View File

@ -24,7 +24,7 @@ module.exports = HumanModel.define({
}, true);
}
if (navigator.mozApps) {
if (window.navigator.mozApps) {
this.installable = true;
var req = navigator.mozApps.checkInstalled(window.location.origin + '/manifest.webapp');
req.onsuccess = function (e) {
@ -34,6 +34,8 @@ module.exports = HumanModel.define({
};
}
//this.allowAlerts = app.notifications.allowed();
this.markActive();
},
session: {

View File

@ -26,19 +26,18 @@ module.exports = BasePage.extend({
'blur .status': 'handleStatusChange'
},
initialize: function (spec) {
me.shouldAskForAlertsPermission = app.notifier.shouldAskPermission();
this.renderAndBind();
},
enableAlerts: function () {
app.notifier.askPermission(function () {
var shouldAsk = app.notifier.shouldAskPermission();
if (!shouldAsk) {
app.notifier.show({
title: 'Ok, sweet!',
description: "You'll now be notified of stuff that happens."
if (app.notifications.permissionNeeded()) {
app.notifications.requestPermission(function (perm) {
if (perm === 'granted') {
app.notifications.create('Ok, sweet!', {
body: "You'll now be notified of stuff that happens."
});
}
});
}
},
installFirefox: function () {
navigator.mozApps.install(window.location.origin + '/manifest.webapp');

View File

@ -23,7 +23,8 @@
"templatizer": "0.1.2",
"underscore": "1.5.1",
"raf-component": "1.1.1",
"stanza.io": "2.3.1"
"stanza.io": "2.5.2",
"notify.js": "0.0.1"
},
"devDependencies": {
"precommit-hook": "0.3.6"