Skip to content

Commit 045259c

Browse files
committed
feat: show unread notification count in the browser tab's title
1 parent b1ffb8e commit 045259c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/gui/src/UI/UIDesktop.js

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ async function UIDesktop(options){
188188

189189
window.socket.on('notif.ack', ({ uid }) => {
190190
$(`.notification[data-uid="${uid}"]`).remove();
191+
update_tab_notif_count_badge();
191192
});
192193

193194
window.socket.on('app.opened', async (app) => {

src/gui/src/UI/UINotification.js

+28
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function UINotification(options){
3636
$('.notification-container').prepend(h);
3737

3838

39+
update_tab_notif_count_badge();
40+
3941
const el_notification = document.getElementById(`ui-notification__${window.global_element_id}`);
4042

4143
// now wrap it in a div
@@ -106,6 +108,8 @@ function UINotification(options){
106108
}else{
107109
$('.notification-container').addClass('has-multiple');
108110
}
111+
112+
update_tab_notif_count_badge();
109113
}, 500);
110114
}
111115
// Show Notification
@@ -131,10 +135,34 @@ $(document).on('click', '.notifications-close-all', function(e){
131135
}, 300);
132136
// remove the 'has-multiple' class
133137
$('.notification-container').removeClass('has-multiple');
138+
139+
// update tab notification count badge
140+
update_tab_notif_count_badge();
141+
134142
// prevent default
135143
e.stopPropagation();
136144
e.preventDefault();
137145
return false;
138146
})
139147

148+
window.update_tab_notif_count_badge = function(){
149+
// count open notifications
150+
let count = $('.notification').length;
151+
152+
// see if title is in the format "(n) Title"
153+
let title = document.title;
154+
let titleMatch = title.match(/^\((\d+)\) (.*)/);
155+
if(titleMatch){
156+
// remove the count
157+
title = titleMatch[2];
158+
}
159+
160+
// if there are notifications, add the count to the title
161+
if(count > 0){
162+
document.title = `(${count}) ${title}`;
163+
}else{
164+
document.title = title;
165+
}
166+
}
167+
140168
export default UINotification;

0 commit comments

Comments
 (0)