Display application icon

This commit is contained in:
2025-12-01 08:36:29 +01:00
parent 1f22d5c41b
commit 64985bb39e
5 changed files with 53 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
import Favicon from "react-favicon";
// Taken from https://github.com/element-hq/element-web/blob/0577e245dac944bd85eea07b93a9762a93062f62/src/favicon.ts
function getInitialFavicon(): HTMLLinkElement[] {
const icons: HTMLLinkElement[] = [];
const links = window.document
.getElementsByTagName("head")[0]
.getElementsByTagName("link");
for (const link of links) {
if (
link.hasAttribute("rel") &&
/(^|\s)icon(\s|$)/i.test(link.getAttribute("rel")!)
) {
icons.push(link);
}
}
return icons;
}
let iconPath = getInitialFavicon()[0].getAttribute("href")!;
export function AppIconModifier(p: {
numberUnread: number;
}): React.ReactElement {
return <Favicon url={iconPath} alertCount={p.numberUnread} />;
}