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:
commit
a28ee6033b
3 changed files with 81 additions and 22 deletions
|
@ -532,6 +532,56 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
$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.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
|
||||
$scope.fetchMoreLines($scope.lines);
|
||||
}
|
||||
$rootScope.pageTitle = ab.shortName + ' | ' + ab.title;
|
||||
$rootScope.updateTitle(ab);
|
||||
|
||||
// If user wants to sync hotlist with weechat
|
||||
// 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'});
|
||||
|
||||
$rootScope.$on('notificationChanged', function() {
|
||||
var notifications = _.reduce(models.model.buffers, function(memo, num) { return (parseInt(memo)||0) + num.notification;});
|
||||
if (typeof notifications !== 'number') {
|
||||
return;
|
||||
}
|
||||
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'
|
||||
});
|
||||
}
|
||||
$rootScope.updateTitle();
|
||||
|
||||
if ($scope.useFavico && $scope.favico) {
|
||||
$scope.updateFavico();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -621,6 +656,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
$store.bind($scope, "noembed", false);
|
||||
// Save setting for channel ordering
|
||||
$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
|
||||
$rootScope.visible = $scope.noembed === false;
|
||||
|
||||
|
@ -662,6 +699,18 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
$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';
|
||||
|
||||
$scope.setActiveBuffer = function(bufferId, key) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue