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:
parent
943dff7b69
commit
5e0ffdb154
@ -12,7 +12,7 @@ var MainView = require('./views/main');
|
|||||||
var Router = require('./router');
|
var Router = require('./router');
|
||||||
var Storage = require('./storage');
|
var Storage = require('./storage');
|
||||||
var xmppEventHandlers = require('./helpers/xmppEventHandlers');
|
var xmppEventHandlers = require('./helpers/xmppEventHandlers');
|
||||||
var notifier = require('./helpers/notifications');
|
var Notify = require('notify.js');
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -20,7 +20,6 @@ module.exports = {
|
|||||||
var self = window.app = this;
|
var self = window.app = this;
|
||||||
var config = localStorage.config;
|
var config = localStorage.config;
|
||||||
|
|
||||||
self.notifier = notifier;
|
|
||||||
|
|
||||||
if (!config) {
|
if (!config) {
|
||||||
console.log('missing config');
|
console.log('missing config');
|
||||||
@ -33,6 +32,7 @@ module.exports = {
|
|||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
function (cb) {
|
function (cb) {
|
||||||
|
app.notifications = new Notify();
|
||||||
app.storage = new Storage();
|
app.storage = new Storage();
|
||||||
app.storage.open(cb);
|
app.storage.open(cb);
|
||||||
},
|
},
|
||||||
|
@ -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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
@ -174,10 +174,10 @@ module.exports = HumanModel.define({
|
|||||||
|
|
||||||
if (notify && (!this.activeContact || (this.activeContact && !app.state.focused)) && message.from.bare === this.jid) {
|
if (notify && (!this.activeContact || (this.activeContact && !app.state.focused)) && message.from.bare === this.jid) {
|
||||||
this.unreadCount++;
|
this.unreadCount++;
|
||||||
app.notifier.show({
|
app.notifications.create(this.displayName, {
|
||||||
title: this.displayName,
|
body: message.body,
|
||||||
description: message.body,
|
|
||||||
icon: this.avatar,
|
icon: this.avatar,
|
||||||
|
tag: this.jid,
|
||||||
onclick: _.bind(app.navigate, app, '/chat/' + this.jid)
|
onclick: _.bind(app.navigate, app, '/chat/' + this.jid)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -63,10 +63,10 @@ module.exports = HumanModel.define({
|
|||||||
|
|
||||||
if (notify && (!this.activeContact || (this.activeContact && !app.hasFocus))) {
|
if (notify && (!this.activeContact || (this.activeContact && !app.hasFocus))) {
|
||||||
this.unreadCount++;
|
this.unreadCount++;
|
||||||
app.notifier.show({
|
app.notifications.create(this.displayName, {
|
||||||
title: this.displayName,
|
body: message.body,
|
||||||
description: message.body,
|
|
||||||
icon: this.avatar,
|
icon: this.avatar,
|
||||||
|
tag: this.id,
|
||||||
onclick: _.bind(app.navigate, app, '/chat/' + this.jid)
|
onclick: _.bind(app.navigate, app, '/chat/' + this.jid)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ module.exports = HumanModel.define({
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (navigator.mozApps) {
|
if (window.navigator.mozApps) {
|
||||||
this.installable = true;
|
this.installable = true;
|
||||||
var req = navigator.mozApps.checkInstalled(window.location.origin + '/manifest.webapp');
|
var req = navigator.mozApps.checkInstalled(window.location.origin + '/manifest.webapp');
|
||||||
req.onsuccess = function (e) {
|
req.onsuccess = function (e) {
|
||||||
@ -34,6 +34,8 @@ module.exports = HumanModel.define({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//this.allowAlerts = app.notifications.allowed();
|
||||||
|
|
||||||
this.markActive();
|
this.markActive();
|
||||||
},
|
},
|
||||||
session: {
|
session: {
|
||||||
|
@ -26,19 +26,18 @@ module.exports = BasePage.extend({
|
|||||||
'blur .status': 'handleStatusChange'
|
'blur .status': 'handleStatusChange'
|
||||||
},
|
},
|
||||||
initialize: function (spec) {
|
initialize: function (spec) {
|
||||||
me.shouldAskForAlertsPermission = app.notifier.shouldAskPermission();
|
|
||||||
this.renderAndBind();
|
this.renderAndBind();
|
||||||
},
|
},
|
||||||
enableAlerts: function () {
|
enableAlerts: function () {
|
||||||
app.notifier.askPermission(function () {
|
if (app.notifications.permissionNeeded()) {
|
||||||
var shouldAsk = app.notifier.shouldAskPermission();
|
app.notifications.requestPermission(function (perm) {
|
||||||
if (!shouldAsk) {
|
if (perm === 'granted') {
|
||||||
app.notifier.show({
|
app.notifications.create('Ok, sweet!', {
|
||||||
title: 'Ok, sweet!',
|
body: "You'll now be notified of stuff that happens."
|
||||||
description: "You'll now be notified of stuff that happens."
|
});
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
},
|
},
|
||||||
installFirefox: function () {
|
installFirefox: function () {
|
||||||
navigator.mozApps.install(window.location.origin + '/manifest.webapp');
|
navigator.mozApps.install(window.location.origin + '/manifest.webapp');
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
"templatizer": "0.1.2",
|
"templatizer": "0.1.2",
|
||||||
"underscore": "1.5.1",
|
"underscore": "1.5.1",
|
||||||
"raf-component": "1.1.1",
|
"raf-component": "1.1.1",
|
||||||
"stanza.io": "2.3.1"
|
"stanza.io": "2.5.2",
|
||||||
|
"notify.js": "0.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"precommit-hook": "0.3.6"
|
"precommit-hook": "0.3.6"
|
||||||
|
Loading…
Reference in New Issue
Block a user