Cancel all outstanding notifications when disconnecting / navigating away

Fixes #296
This commit is contained in:
Lorenz Hübschle-Schneider 2014-10-16 17:12:48 +02:00
parent 8eda79e2f3
commit d709c8fd93
2 changed files with 26 additions and 0 deletions

View file

@ -221,6 +221,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
});
$rootScope.$on('relayDisconnect', function() {
// Reset title
$rootScope.pageTitle = '';
$rootScope.notificationStatus = '';
notifications.cancelAll();
models.reinitialize();
$rootScope.$emit('notificationChanged');
$scope.connectbutton = 'Connect';

View file

@ -1,6 +1,8 @@
var weechat = angular.module('weechat');
weechat.factory('notifications', ['$rootScope', '$log', 'models', function($rootScope, $log, models) {
var notifications = [];
// Ask for permission to display desktop notifications
var requestNotificationPermission = function() {
// Firefox
@ -109,6 +111,10 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', function($root
icon: 'assets/img/favicon.png'
});
// Save notification, so we can close all outstanding ones when disconnecting
notification.id = notifications.length;
notifications.push(notification);
// Cancel notification automatically
var timeout = 15*1000;
notification.onshow = function() {
@ -124,6 +130,11 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', function($root
notification.close();
};
// Remove from list of active notifications
notification.onclose = function() {
delete notifications[this.id];
};
if ($rootScope.soundnotification) {
// TODO fill in a sound file
var audioFile = "assets/audio/sonar";
@ -132,10 +143,20 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', function($root
}
};
var cancelAll = function() {
while (notifications.length > 0) {
var notification = notifications.pop();
if (notification !== undefined) {
notification.close();
}
}
};
return {
requestNotificationPermission: requestNotificationPermission,
updateTitle: updateTitle,
updateFavico: updateFavico,
createHighlight: createHighlight,
cancelAll: cancelAll,
};
}]);