Favicon badges

This commit is contained in:
David Baker 2015-12-21 12:55:13 +00:00
parent 5f6fe74ca8
commit 6ea3f21a8e
2 changed files with 18 additions and 0 deletions

View file

@ -21,6 +21,7 @@
}, },
"dependencies": { "dependencies": {
"classnames": "^2.1.2", "classnames": "^2.1.2",
"favico.js": "^0.3.10",
"filesize": "^3.1.2", "filesize": "^3.1.2",
"flux": "^2.0.3", "flux": "^2.0.3",
"glob": "^5.0.14", "glob": "^5.0.14",

View file

@ -16,6 +16,7 @@ limitations under the License.
var React = require('react'); var React = require('react');
var Matrix = require("matrix-js-sdk"); var Matrix = require("matrix-js-sdk");
var url = require('url'); var url = require('url');
var Favico = require('favico.js');
var MatrixClientPeg = require("../../MatrixClientPeg"); var MatrixClientPeg = require("../../MatrixClientPeg");
var Notifier = require("../../Notifier"); var Notifier = require("../../Notifier");
@ -82,6 +83,10 @@ module.exports = React.createClass({
}; };
}, },
componentWillMount: function() {
this.favicon = new Favico({animation: 'none'});
},
componentDidMount: function() { componentDidMount: function() {
this.dispatcherRef = dis.register(this.onAction); this.dispatcherRef = dis.register(this.onAction);
if (this.state.logged_in) { if (this.state.logged_in) {
@ -399,6 +404,7 @@ module.exports = React.createClass({
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
var self = this; var self = this;
cli.on('sync', function(state, prevState) { cli.on('sync', function(state, prevState) {
self.updateFavicon();
if (state === "SYNCING" && prevState === "SYNCING") { if (state === "SYNCING" && prevState === "SYNCING") {
return; return;
} }
@ -628,6 +634,17 @@ module.exports = React.createClass({
this.showScreen("settings"); this.showScreen("settings");
}, },
updateFavicon: function() {
var notifCount = 0;
var rooms = MatrixClientPeg.get().getRooms();
for (var i = 0; i < rooms.length; ++i) {
notifCount += rooms[i].unread_notification_count;
}
this.favicon.badge(notifCount);
document.title = (notifCount > 0 ? "["+notifCount+"] " : "")+"Vector";
},
render: function() { render: function() {
var LeftPanel = sdk.getComponent('structures.LeftPanel'); var LeftPanel = sdk.getComponent('structures.LeftPanel');
var RoomView = sdk.getComponent('structures.RoomView'); var RoomView = sdk.getComponent('structures.RoomView');