mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
8c51d06222
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { useAsyncEffect } from 'ahooks'
|
|
import { appDefaultIconBackground } from '@/config'
|
|
import { searchEmoji } from '@/utils/emoji'
|
|
import type { AppIconType } from '@/types/app'
|
|
|
|
type UseAppFaviconOptions = {
|
|
enable?: boolean
|
|
icon_type?: AppIconType | null
|
|
icon?: string
|
|
icon_background?: string | null
|
|
icon_url?: string | null
|
|
}
|
|
|
|
export function useAppFavicon(options: UseAppFaviconOptions) {
|
|
const {
|
|
enable = true,
|
|
icon_type = 'emoji',
|
|
icon,
|
|
icon_background,
|
|
icon_url,
|
|
} = options
|
|
|
|
useAsyncEffect(async () => {
|
|
if (!enable)
|
|
return
|
|
|
|
const isValidImageIcon = icon_type === 'image' && icon_url
|
|
|
|
const link: HTMLLinkElement = document.querySelector('link[rel*="icon"]') || document.createElement('link')
|
|
|
|
link.href = isValidImageIcon
|
|
? icon_url
|
|
: 'data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22>'
|
|
+ `<rect width=%22100%25%22 height=%22100%25%22 fill=%22${encodeURIComponent(icon_background || appDefaultIconBackground)}%22 rx=%2230%22 ry=%2230%22 />`
|
|
+ `<text x=%2212.5%22 y=%221em%22 font-size=%2275%22>${
|
|
icon ? await searchEmoji(icon) : '🤖'
|
|
}</text>`
|
|
+ '</svg>'
|
|
|
|
link.rel = 'shortcut icon'
|
|
link.type = 'image/svg'
|
|
document.getElementsByTagName('head')[0].appendChild(link)
|
|
}, [enable, icon, icon_background])
|
|
}
|