1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-01-11 18:13:52 +02:00

Fixing favicon changes on other browsers (#1017)

This commit is contained in:
Jesús Espino 2021-08-17 22:50:49 +02:00 committed by GitHub
parent 7bc168ad84
commit 83a45ae706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -49,13 +49,19 @@ const MainApp = () => {
}, []) }, [])
useEffect(() => { useEffect(() => {
const link = (document.querySelector("link[rel*='icon']") || document.createElement('link')) as HTMLLinkElement const oldLink = document.querySelector("link[rel*='icon']") as HTMLLinkElement
if (!oldLink) {
return () => null
}
const restoreData = { const restoreData = {
type: link.type, type: oldLink.type,
rel: link.rel, rel: oldLink.rel,
href: link.href, href: oldLink.href,
} }
return () => { return () => {
document.querySelectorAll("link[rel*='icon']").forEach((n) => n.remove())
const link = document.createElement('link') as HTMLLinkElement
link.type = restoreData.type link.type = restoreData.type
link.rel = restoreData.rel link.rel = restoreData.rel
link.href = restoreData.href link.href = restoreData.href

View File

@ -241,11 +241,15 @@ class Utils {
// favicon // favicon
static setFavicon(icon?: string): void { static setFavicon(icon?: string): void {
const href = icon ? `data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">${icon}</text></svg>` : '' if (!icon) {
const link = (document.querySelector("link[rel*='icon']") || document.createElement('link')) as HTMLLinkElement document.querySelector("link[rel*='icon']")?.remove()
return
}
const link = document.createElement('link') as HTMLLinkElement
link.type = 'image/x-icon' link.type = 'image/x-icon'
link.rel = 'shortcut icon' link.rel = 'shortcut icon'
link.href = href link.href = `data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">${icon}</text></svg>`
document.querySelectorAll("link[rel*='icon']").forEach((n) => n.remove())
document.getElementsByTagName('head')[0].appendChild(link) document.getElementsByTagName('head')[0].appendChild(link)
} }