comparison 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
comparison
equal deleted inserted replaced
833:4db064a70fc7 834:2491898b3041
18 background, send desktop notifications on messages. 18 background, send desktop notifications on messages.
19 19
20 Requires both Web Notifications and Page Visibility API. 20 Requires both Web Notifications and Page Visibility API.
21 """ 21 """
22 22
23 def __init__(self): 23 def __init__(self, alerts_counter):
24 """
25
26 @param alerts_counter (FaviconCounter): counter instance
27 """
28 self.alerts_counter = alerts_counter
24 self.enabled = False 29 self.enabled = False
25 user_agent = None 30 user_agent = None
26 notif_permission = None 31 notif_permission = None
27 JS(""" 32 JS("""
28 if (!('hidden' in document)) 33 if (!('hidden' in document))
52 self.user_agent = user_agent 57 self.user_agent = user_agent
53 self._installChromiumWorkaround() 58 self._installChromiumWorkaround()
54 59
55 wnd().onfocus = self.onFocus 60 wnd().onfocus = self.onFocus
56 # wnd().onblur = self.onBlur 61 # wnd().onblur = self.onBlur
57 self._notif_count = 0
58 self._orig_title = Window.getTitle()
59 62
60 def _installChromiumWorkaround(self): 63 def _installChromiumWorkaround(self):
61 # XXX: Workaround for Chromium behaviour, it's doens't manage requestPermission on onLoad event 64 # XXX: Workaround for Chromium behaviour, it's doens't manage requestPermission on onLoad event
62 # see https://code.google.com/p/chromium/issues/detail?id=274284 65 # see https://code.google.com/p/chromium/issues/detail?id=274284
63 # FIXME: need to be removed if Chromium behaviour changes 66 # FIXME: need to be removed if Chromium behaviour changes
89 }); 92 });
90 """) 93 """)
91 wnd().onclick = self._old_click 94 wnd().onclick = self._old_click
92 95
93 def onFocus(self, event=None): 96 def onFocus(self, event=None):
94 Window.setTitle(self._orig_title) 97 self.alerts_counter.update(extra=0)
95 self._notif_count = 0
96 98
97 # def onBlur(self, event=None): 99 # def onBlur(self, event=None):
98 # pass 100 # pass
99 101
100 def isHidden(self): 102 def isHidden(self):
111 window.focus(); 113 window.focus();
112 }); 114 });
113 """) 115 """)
114 notification.onshow = lambda: Timer(TIMER_DELAY, lambda timer: notification.close()) 116 notification.onshow = lambda: Timer(TIMER_DELAY, lambda timer: notification.close())
115 117
116 def highlightTab(self):
117 self._notif_count += 1
118 Window.setTitle("%s (%d)" % (self._orig_title, self._notif_count))
119
120 def notify(self, title, body, icon='/media/icons/apps/48/sat.png'): 118 def notify(self, title, body, icon='/media/icons/apps/48/sat.png'):
121 if self.isHidden(): 119 if self.isHidden():
122 self._notify(title, body, icon) 120 self._notify(title, body, icon)
123 self.highlightTab()
124 121
125 122
126 class FaviconCounter(object): 123 class FaviconCounter(object):
127 """Display numbers over the favicon to signal e.g. waiting messages""" 124 """Display numbers over the favicon to signal e.g. waiting messages"""
128 125
134 animation : 'slide', 131 animation : 'slide',
135 bgColor: '#5CB85C', 132 bgColor: '#5CB85C',
136 }); 133 });
137 """) 134 """)
138 135
139 def update(self, count): 136 self.count = 0 # messages that are not displayed
140 self.counter.badge(count) 137 self.extra = 0 # messages that are displayed but the window is hidden
138
139 def update(self, count=None, extra=None):
140 """Update the favicon counter.
141
142 @param count (int): primary counter
143 @param extra (int): extra counter
144 """
145 if count is not None:
146 self.count = count
147 if extra is not None:
148 self.extra = extra
149 self.counter.badge(self.count + self.extra)