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() {
|
$rootScope.$on('relayDisconnect', function() {
|
||||||
|
// Reset title
|
||||||
|
$rootScope.pageTitle = '';
|
||||||
|
$rootScope.notificationStatus = '';
|
||||||
|
notifications.cancelAll();
|
||||||
|
|
||||||
models.reinitialize();
|
models.reinitialize();
|
||||||
$rootScope.$emit('notificationChanged');
|
$rootScope.$emit('notificationChanged');
|
||||||
$scope.connectbutton = 'Connect';
|
$scope.connectbutton = 'Connect';
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
var weechat = angular.module('weechat');
|
var weechat = angular.module('weechat');
|
||||||
|
|
||||||
weechat.factory('notifications', ['$rootScope', '$log', 'models', function($rootScope, $log, models) {
|
weechat.factory('notifications', ['$rootScope', '$log', 'models', function($rootScope, $log, models) {
|
||||||
|
var notifications = [];
|
||||||
|
|
||||||
// Ask for permission to display desktop notifications
|
// Ask for permission to display desktop notifications
|
||||||
var requestNotificationPermission = function() {
|
var requestNotificationPermission = function() {
|
||||||
// Firefox
|
// Firefox
|
||||||
|
@ -109,6 +111,10 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', function($root
|
||||||
icon: 'assets/img/favicon.png'
|
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
|
// Cancel notification automatically
|
||||||
var timeout = 15*1000;
|
var timeout = 15*1000;
|
||||||
notification.onshow = function() {
|
notification.onshow = function() {
|
||||||
|
@ -124,6 +130,11 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', function($root
|
||||||
notification.close();
|
notification.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Remove from list of active notifications
|
||||||
|
notification.onclose = function() {
|
||||||
|
delete notifications[this.id];
|
||||||
|
};
|
||||||
|
|
||||||
if ($rootScope.soundnotification) {
|
if ($rootScope.soundnotification) {
|
||||||
// TODO fill in a sound file
|
// TODO fill in a sound file
|
||||||
var audioFile = "assets/audio/sonar";
|
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 {
|
return {
|
||||||
requestNotificationPermission: requestNotificationPermission,
|
requestNotificationPermission: requestNotificationPermission,
|
||||||
updateTitle: updateTitle,
|
updateTitle: updateTitle,
|
||||||
updateFavico: updateFavico,
|
updateFavico: updateFavico,
|
||||||
createHighlight: createHighlight,
|
createHighlight: createHighlight,
|
||||||
|
cancelAll: cancelAll,
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
Loading…
Reference in a new issue