constructor(roomList) {
super();
+ this.initialized = false;
+ this.favicon = LogoSVG;
this.matrixClient = roomList.matrixClient;
this.roomList = roomList;
}
async _initNoti() {
+ this.initialized = false;
this.roomIdToNoti = new Map();
const addNoti = (roomId) => {
};
[...this.roomList.rooms].forEach(addNoti);
[...this.roomList.directs].forEach(addNoti);
+
+ this.initialized = true;
this._updateFavicon();
}
}
async _updateFavicon() {
+ if (!this.initialized) return;
let unread = false;
let highlight = false;
[...this.roomIdToNoti.values()].find((noti) => {
if (unread && highlight) return true;
return false;
});
- if (!unread) {
- setFavicon(LogoSVG);
- return;
+ let newFavicon = LogoSVG;
+ if (unread && !highlight) {
+ newFavicon = LogoUnreadSVG;
+ }
+ if (unread && highlight) {
+ newFavicon = LogoHighlightSVG;
}
- setFavicon(highlight ? LogoHighlightSVG : LogoUnreadSVG);
+ if (newFavicon === this.favicon) return;
+ this.favicon = newFavicon;
+ setFavicon(this.favicon);
}
_setNoti(roomId, total, highlight) {
}
export function setFavicon(url) {
- const oldFav = document.querySelector('[rel=icon]');
- oldFav.parentElement.removeChild(oldFav);
- const fav = document.createElement('link');
- fav.rel = 'icon';
- fav.href = url;
- document.head.appendChild(fav);
+ document.querySelector('[rel=icon]').href = url;
}
export function copyToClipboard(text) {