From 364d43c33b855bf582e7e9c36d53e816f90983b3 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 13 Oct 2015 23:23:52 +0200 Subject: [PATCH] Added desktop notification timeout Closes #897 --- app/js/services.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/app/js/services.js b/app/js/services.js index edee1f16..db7bec99 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -2897,6 +2897,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var titleBackup = document.title, titleChanged = false, + titleCnt = 0, titlePromise; var prevFavicon; @@ -2916,8 +2917,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) titleBackup = document.title; titlePromise = $interval(function () { - var time = tsNow(); - if (!notificationsCount || time % 2000 > 1000) { + if (!notificationsCount || ((titleCnt++) % 2)) { if (titleChanged) { titleChanged = false; document.title = titleBackup; @@ -3148,14 +3148,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) }; notification.onclose = function () { - delete notificationsShown[key]; - notificationsClear(); + if (!notification.hidden) { + delete notificationsShown[key]; + notificationsClear(); + } }; if (notification.show) { notification.show(); } notificationsShown[key] = notification; + + if (!Config.Navigator.mobile) { + setTimeout(function () { + notificationHide(key) + }, 8000); + } }; function playSound (volume) { @@ -3192,6 +3200,19 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } } + function notificationHide (key) { + var notification = notificationsShown[key]; + if (notification) { + try { + if (notification.close) { + notification.hidden = true; + notification.close(); + } + } catch (e) {} + delete notificationsCount[key]; + } + } + function notificationSoundReset (tag) { delete soundsPlayed[tag]; }