Merge pull request #476 from glowing-bear/close-notifications-on-disconnect
Cancel all outstanding notifications when disconnecting / navigating away
This commit is contained in:
commit
6658dd1265
2 changed files with 26 additions and 0 deletions
|
@ -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';
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}]);
|
||||
|
|
Loading…
Reference in a new issue