Mercurial > libervia-web
diff src/browser/sat_browser/notification.py @ 834:2491898b3041
browser (chat, notification): remove the textual alerts counter, merge it with the favicon counter
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 12 Jan 2016 17:59:07 +0100 |
parents | 03e9fe91081c |
children | 620306b3d5be |
line wrap: on
line diff
--- a/src/browser/sat_browser/notification.py Tue Jan 12 16:55:43 2016 +0100 +++ b/src/browser/sat_browser/notification.py Tue Jan 12 17:59:07 2016 +0100 @@ -20,7 +20,12 @@ Requires both Web Notifications and Page Visibility API. """ - def __init__(self): + def __init__(self, alerts_counter): + """ + + @param alerts_counter (FaviconCounter): counter instance + """ + self.alerts_counter = alerts_counter self.enabled = False user_agent = None notif_permission = None @@ -54,8 +59,6 @@ wnd().onfocus = self.onFocus # wnd().onblur = self.onBlur - self._notif_count = 0 - self._orig_title = Window.getTitle() def _installChromiumWorkaround(self): # XXX: Workaround for Chromium behaviour, it's doens't manage requestPermission on onLoad event @@ -91,8 +94,7 @@ wnd().onclick = self._old_click def onFocus(self, event=None): - Window.setTitle(self._orig_title) - self._notif_count = 0 + self.alerts_counter.update(extra=0) # def onBlur(self, event=None): # pass @@ -113,14 +115,9 @@ """) notification.onshow = lambda: Timer(TIMER_DELAY, lambda timer: notification.close()) - def highlightTab(self): - self._notif_count += 1 - Window.setTitle("%s (%d)" % (self._orig_title, self._notif_count)) - def notify(self, title, body, icon='/media/icons/apps/48/sat.png'): if self.isHidden(): self._notify(title, body, icon) - self.highlightTab() class FaviconCounter(object): @@ -136,5 +133,17 @@ }); """) - def update(self, count): - self.counter.badge(count) + self.count = 0 # messages that are not displayed + self.extra = 0 # messages that are displayed but the window is hidden + + def update(self, count=None, extra=None): + """Update the favicon counter. + + @param count (int): primary counter + @param extra (int): extra counter + """ + if count is not None: + self.count = count + if extra is not None: + self.extra = extra + self.counter.badge(self.count + self.extra)