diff options
| author | dakkar <dakkar@thenautilus.net> | 2024-06-18 15:25:39 +0000 |
|---|---|---|
| committer | dakkar <dakkar@thenautilus.net> | 2024-06-18 15:25:39 +0000 |
| commit | 717696c4728d2e507ddfbd0e4890189758ab1087 (patch) | |
| tree | 7114d1726b71a9be7eb1594c9b1d809c96a1e366 /packages/frontend/src/scripts | |
| parent | merge: Revert "fix: start only one instance of ChartManagementService schedul... (diff) | |
| parent | add .js to import in general.vue (diff) | |
| download | sharkey-717696c4728d2e507ddfbd0e4890189758ab1087.tar.gz sharkey-717696c4728d2e507ddfbd0e4890189758ab1087.tar.bz2 sharkey-717696c4728d2e507ddfbd0e4890189758ab1087.zip | |
merge: Misskey fixes & add button to see if notification dot works (!553)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/553
Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <marie@kaifa.ch>
Approved-by: Amelia Yukii <amelia.yukii@shourai.de>
Diffstat (limited to 'packages/frontend/src/scripts')
| -rw-r--r-- | packages/frontend/src/scripts/favicon-dot.ts | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/packages/frontend/src/scripts/favicon-dot.ts b/packages/frontend/src/scripts/favicon-dot.ts index ba6dcb5d30..a5972276e2 100644 --- a/packages/frontend/src/scripts/favicon-dot.ts +++ b/packages/frontend/src/scripts/favicon-dot.ts @@ -6,12 +6,12 @@ import tinycolor from 'tinycolor2'; class FavIconDot { - canvas: HTMLCanvasElement; - src: string | null = null; - ctx: CanvasRenderingContext2D | null = null; - faviconImage: HTMLImageElement | null = null; - faviconEL: HTMLLinkElement | undefined; - hasLoaded: Promise<void> | undefined; + private readonly canvas: HTMLCanvasElement; + private src: string | null = null; + private ctx: CanvasRenderingContext2D | null = null; + private faviconImage: HTMLImageElement | null = null; + private faviconEL: HTMLLinkElement | undefined; + private hasLoaded: Promise<void> | undefined; constructor() { this.canvas = document.createElement('canvas'); @@ -88,32 +88,58 @@ class FavIconDot { if (this.faviconEL) this.faviconEL.href = this.canvas.toDataURL('image/png'); } - async setVisible(isVisible: boolean) { + public async setVisible(isVisible: boolean) { // Wait for it to have loaded the icon await this.hasLoaded; this.drawIcon(); if (isVisible) this.drawDot(); this.setFavicon(); } + + public async worksOnInstance() { + try { + // Wait for it to have loaded the icon + await this.hasLoaded; + this.drawIcon(); + this.drawDot(); + this.canvas.toDataURL('image/png'); + } catch (error) { + return false; + } + return true; + } } let icon: FavIconDot | undefined = undefined; -export function setFavIconDot(visible: boolean) { +export async function setFavIconDot(visible: boolean) { const setIconVisibility = async () => { if (!icon) { icon = new FavIconDot(); await icon.setup(); } - (icon as FavIconDot).setVisible(visible); + try { + (icon as FavIconDot).setVisible(visible); + } catch (error) { + //Probably failed due to CORS and a dirty canvas + } }; // If document is already loaded, set visibility immediately if (document.readyState === 'complete') { - setIconVisibility(); + await setIconVisibility(); } else { // Otherwise, set visibility when window loads window.addEventListener('load', setIconVisibility); } } + +export async function worksOnInstance() { + if (!icon) { + icon = new FavIconDot(); + await icon.setup(); + } + + return await icon.worksOnInstance(); +} |