did thread fixes

This commit is contained in:
KevinWh0 2024-05-03 11:27:41 +02:00
parent 42c2969707
commit 47d1477ac4
2 changed files with 8 additions and 10 deletions

View file

@ -21,15 +21,14 @@ class FavIconDot {
this.faviconImage = document.createElement('img'); this.faviconImage = document.createElement('img');
this.hasLoaded = new Promise((resolve, reject) => { this.hasLoaded = new Promise((resolve, reject) => {
(this.faviconImage as HTMLImageElement).onload = () => { (this.faviconImage as HTMLImageElement).addEventListener('load', () => {
this.canvas.width = (this.faviconImage as HTMLImageElement).width; this.canvas.width = (this.faviconImage as HTMLImageElement).width;
this.canvas.height = (this.faviconImage as HTMLImageElement).height; this.canvas.height = (this.faviconImage as HTMLImageElement).height;
resolve(); resolve();
}; });
(this.faviconImage as HTMLImageElement).addEventListener('error', () => {
(this.faviconImage as HTMLImageElement).onerror = () => {
reject('Failed to create favicon img element'); reject('Failed to create favicon img element');
}; });
}); });
this.faviconImage.src = this.faviconEL.href; this.faviconImage.src = this.faviconEL.href;
@ -38,9 +37,9 @@ class FavIconDot {
private async getOrMakeFaviconElement() : Promise<HTMLLinkElement> { private async getOrMakeFaviconElement() : Promise<HTMLLinkElement> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const favicon = document.querySelector<HTMLLinkElement>('link[rel$=icon]') ?? this._createFaviconElem(); const favicon = document.querySelector<HTMLLinkElement>('link[rel$=icon]') ?? this._createFaviconElem();
favicon.onload = () => { favicon.addEventListener('load', () => {
resolve(favicon); resolve(favicon);
}; });
favicon.onerror = () => { favicon.onerror = () => {
reject('Failed to load favicon'); reject('Failed to load favicon');
@ -80,7 +79,6 @@ class FavIconDot {
async setVisible(isVisible : boolean) { async setVisible(isVisible : boolean) {
//Wait for it to have loaded the icon //Wait for it to have loaded the icon
await this.hasLoaded; await this.hasLoaded;
console.log(this.hasLoaded);
this._drawIcon(); this._drawIcon();
if (isVisible) this._drawDot(); if (isVisible) this._drawDot();
this._setFavicon(); this._setFavicon();
@ -104,6 +102,6 @@ export function setFavIconDot(visible: boolean) {
setIconVisibility(); setIconVisibility();
} else { } else {
// Otherwise, set visibility when window loads // Otherwise, set visibility when window loads
window.onload = setIconVisibility; window.addEventListener('load', setIconVisibility);
} }
} }

View file

@ -96,7 +96,7 @@ if ($i) {
connection.on('notification', onNotification); connection.on('notification', onNotification);
//For the favicon notification dot //For the favicon notification dot
watch(() => $i?.hasUnreadNotification, (hasAny) => setFavIconDot((defaultStore.state.enableFaviconNotificationDot ? hasAny : false) ?? false)); watch(() => $i?.hasUnreadNotification && defaultStore.state.enableFaviconNotificationDot, (hasAny) => setFavIconDot(hasAny as boolean));
if ($i.hasUnreadNotification && defaultStore.state.enableFaviconNotificationDot) setFavIconDot(true); if ($i.hasUnreadNotification && defaultStore.state.enableFaviconNotificationDot) setFavIconDot(true);