diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx index d83f8e4..9bfb02c 100644 --- a/app/[locale]/layout.tsx +++ b/app/[locale]/layout.tsx @@ -1,6 +1,8 @@ // @auto-i18n-check. Please do not delete the line. import "@/styles/globals.css"; +import "/node_modules/flag-icons/css/flag-icons.min.css"; + import React from "react"; import { NextIntlClientProvider, useMessages } from "next-intl"; import { PublicEnvScript } from "next-runtime-env"; diff --git a/bun.lockb b/bun.lockb index 0667cb3..6139404 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/components/ServerCard.tsx b/components/ServerCard.tsx index 666e158..7eb800f 100644 --- a/components/ServerCard.tsx +++ b/components/ServerCard.tsx @@ -11,18 +11,40 @@ import { cn, formatNezhaInfo } from "@/lib/utils"; import ServerCardPopover from "./ServerCardPopover"; import getUnicodeFlagIcon from "country-flag-icons/unicode"; import { env } from "next-runtime-env"; +import { useEffect, useState } from "react"; export default function ServerCard({ serverInfo, }: { serverInfo: NezhaAPISafe; }) { + const [supportsEmojiFlags, setSupportsEmojiFlags] = useState(false); + + useEffect(() => { + const checkEmojiSupport = () => { + const canvas = document.createElement('canvas'); + const ctx = canvas.getContext('2d'); + const emojiFlag = "🇺🇸"; // 使用美国国旗作为测试 + if (!ctx) return; + ctx.fillStyle = "#000"; + ctx.textBaseline = 'top'; + ctx.font = '32px Arial'; + ctx.fillText(emojiFlag, 0, 0); + + const support = ctx.getImageData(16, 16, 1, 1).data[3] !== 0; + setSupportsEmojiFlags(support); + }; + + checkEmojiSupport(); + }, []); + const t = useTranslations("ServerCard"); const { name, country_code, online, cpu, up, down, mem, stg, ...props } = formatNezhaInfo(serverInfo); const showFlag = env("NEXT_PUBLIC_ShowFlag") === "true"; + return online ? (
{showFlag ? ( - country_code ? ( - - {getUnicodeFlagIcon(country_code)} - - ) : ( - 🏁 - ) + + {!supportsEmojiFlags ? ( + + ) : ( + getUnicodeFlagIcon(country_code) + )} + ) : null}

{showFlag ? ( - country_code ? ( - - {getUnicodeFlagIcon(country_code)} - - ) : ( - 🏁 - ) + + {!supportsEmojiFlags ? ( + + ) : ( + getUnicodeFlagIcon(country_code) + )} + ) : null}