Display application icon
This commit is contained in:
26
matrixgw_frontend/src/widgets/messages/AppIconModifier.tsx
Normal file
26
matrixgw_frontend/src/widgets/messages/AppIconModifier.tsx
Normal 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} />;
|
||||
}
|
||||
Reference in New Issue
Block a user