Merge pull request #163 from lorenzhs/flashtitle

Flash title when receiving lines in the background & make use of favico configurable
This commit is contained in:
David Cormier 2014-02-21 09:58:28 -05:00
commit a28ee6033b
3 changed files with 81 additions and 22 deletions

View file

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<title ng-bind-template="WeeChat {{ pageTitle}}"></title> <title ng-bind-template="{{ notificationStatus }}WeeChat {{ pageTitle}}"></title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" media="screen"> <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link rel="shortcut icon" sizes="128x128" href="img/weechat_logo_128x128.png"> <link rel="shortcut icon" sizes="128x128" href="img/weechat_logo_128x128.png">
<link rel="apple-touch-icon" sizes="128x128" href="img/weechat_logo_128x128.png"> <link rel="apple-touch-icon" sizes="128x128" href="img/weechat_logo_128x128.png">
@ -256,6 +256,16 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
</div> </div>
</form> </form>
</li> </li>
<li>
<form class="form-inline" role="form">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="useFavico">
Display unread count in favicon
</label>
</div>
</form>
</li>
<li> <li>
<form class="form-inline" role="form"> <form class="form-inline" role="form">
<div class="checkbox"> <div class="checkbox">

View file

@ -532,6 +532,56 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.isinstalled = false; $scope.isinstalled = false;
} }
// Reduce buffers with "+" operation over a key. Mostly useful for unread/notification counts.
$rootScope.unreadCount = function(type) {
if (!type) {
type = "unread";
}
// Do this the old-fashioned way with iterating over the keys, as underscore proved to be error-prone
var keys = Object.keys(models.model.buffers);
var count = 0;
for (var key in keys) {
count += models.model.buffers[keys[key]][type];
}
return count;
};
$rootScope.updateTitle = function() {
var unreadFragment = '';
var notifications = $rootScope.unreadCount('notification');
if (notifications > 0) {
// New notifications deserve an exclamation mark
$rootScope.notificationStatus = '(' + notifications + ') ';
} else {
$rootScope.notificationStatus = '';
}
var activeBuffer = models.getActiveBuffer();
$rootScope.pageTitle = activeBuffer.shortName + ' | ' + activeBuffer.title;
};
$scope.updateFavico = function() {
var notifications = $rootScope.unreadCount('notification');
if (notifications > 0) {
$scope.favico.badge(notifications, {
bgColor: '#d00',
textColor: '#fff'
});
} else {
var unread = $rootScope.unreadCount('unread');
if (unread === 0) {
$scope.favico.reset();
} else {
$scope.favico.badge(unread, {
bgColor: '#5CB85C',
textColor: '#ff0'
});
}
}
};
$rootScope.$on('activeBufferChanged', function() { $rootScope.$on('activeBufferChanged', function() {
$rootScope.scrollWithBuffer(true); $rootScope.scrollWithBuffer(true);
@ -540,7 +590,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// buffer has not been loaded, but some lines may already be present if they arrived after we connected // buffer has not been loaded, but some lines may already be present if they arrived after we connected
$scope.fetchMoreLines($scope.lines); $scope.fetchMoreLines($scope.lines);
} }
$rootScope.pageTitle = ab.shortName + ' | ' + ab.title; $rootScope.updateTitle(ab);
// If user wants to sync hotlist with weechat // If user wants to sync hotlist with weechat
// we will send a /buffer bufferName command every time // we will send a /buffer bufferName command every time
@ -560,25 +610,10 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.favico = new Favico({animation: 'none'}); $scope.favico = new Favico({animation: 'none'});
$rootScope.$on('notificationChanged', function() { $rootScope.$on('notificationChanged', function() {
var notifications = _.reduce(models.model.buffers, function(memo, num) { return (parseInt(memo)||0) + num.notification;}); $rootScope.updateTitle();
if (typeof notifications !== 'number') {
return; if ($scope.useFavico && $scope.favico) {
} $scope.updateFavico();
if (notifications > 0) {
$scope.favico.badge(notifications, {
bgColor: '#d00',
textColor: '#fff'
});
} else {
var unread = _.reduce(models.model.buffers, function(memo, num) { return (parseInt(memo)||0) + num.unread;});
if (unread === 0) {
$scope.favico.reset();
} else {
$scope.favico.badge(unread, {
bgColor: '#5CB85C',
textColor: '#ff0'
});
}
} }
}); });
@ -621,6 +656,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$store.bind($scope, "noembed", false); $store.bind($scope, "noembed", false);
// Save setting for channel ordering // Save setting for channel ordering
$store.bind($scope, "orderbyserver", false); $store.bind($scope, "orderbyserver", false);
// Save setting for updating favicon
$store.bind($scope, "useFavico", true);
// Save setting for displaying embeds in rootScope so it can be used from service // Save setting for displaying embeds in rootScope so it can be used from service
$rootScope.visible = $scope.noembed === false; $rootScope.visible = $scope.noembed === false;
@ -662,6 +699,18 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$rootScope.predicate = $scope.orderbyserver ? 'serverSortKey' : 'number'; $rootScope.predicate = $scope.orderbyserver ? 'serverSortKey' : 'number';
}); });
$scope.$watch('useFavico', function() {
// this check is necessary as this is called on page load, too
if (!$rootScope.connected) {
return;
}
if ($scope.useFavico) {
$scope.updateFavico();
} else {
$scope.favico.reset();
}
});
$rootScope.predicate = $scope.orderbyserver ? 'serverSortKey' : 'number'; $rootScope.predicate = $scope.orderbyserver ? 'serverSortKey' : 'number';
$scope.setActiveBuffer = function(bufferId, key) { $scope.setActiveBuffer = function(bufferId, key) {

View file

@ -98,7 +98,7 @@ ls.factory("$store",function($parse){
*/ */
bind: function ($scope, key, def) { bind: function ($scope, key, def) {
def = def || ''; def = def || '';
if (!publicMethods.get(key)) { if (publicMethods.get(key) === undefined) {
publicMethods.set(key, def); publicMethods.set(key, def);
} }
$parse(key).assign($scope, publicMethods.get(key)); $parse(key).assign($scope, publicMethods.get(key));