有效付费授权时侧栏展示金色Logo

This commit is contained in:
monster committed 2026-10-16 17:33:26 +08:00
1 parent 2a40f5ff64
commit d1600cc9ef
5 files changed
+90 -22

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

+23 -10
View File
@@ -4,6 +4,7 @@ import * as React from "react"
import { useTranslation } from "react-i18next"
import { NavLink } from "react-router-dom"
import paidLicenseLogo from "@/assets/paid-license-logo.webp"
import { NavMain } from "@/components/nav-main"
import { NavUser } from "@/components/nav-user"
import {
@@ -25,6 +26,7 @@ import {
} from "@hugeicons/core-free-icons"
import { CONSOLE_ROUTES, DEFAULT_CONSOLE_PATH } from "@/lib/routes"
import { useAuth } from "@/hooks/use-auth"
import { useLicenseStatus } from "@/hooks/use-license-status"
export function AppSidebar({
onLogout,
@@ -36,6 +38,7 @@ export function AppSidebar({
}) {
const { i18n, t } = useTranslation()
const { user } = useAuth()
const license = useLicenseStatus()
const navMain = [
{
title: t("sections.statistics"),
@@ -162,16 +165,26 @@ export function AppSidebar({
render={<NavLink to={DEFAULT_CONSOLE_PATH} />}
>
<div className="size-8 shrink-0 overflow-hidden rounded-lg">
<img
src="/logo-light.png"
alt=""
className="size-full object-contain dark:hidden"
/>
<img
src="/logo-dark.png"
alt=""
className="hidden size-full object-contain dark:block"
/>
{license?.state === "valid" ? (
<img
src={paidLicenseLogo}
alt=""
className="size-full object-contain"
/>
) : (
<>
<img
src="/logo-light.png"
alt=""
className="size-full object-contain dark:hidden"
/>
<img
src="/logo-dark.png"
alt=""
className="hidden size-full object-contain dark:block"
/>
</>
)}
</div>
<div className="grid flex-1 text-start text-sm leading-tight">
<span className="truncate font-medium">{productName}</span>
@@ -31,20 +31,9 @@ import {
ItemTitle,
} from "@/components/ui/item"
import { api } from "@/lib/api"
import { publishLicenseStatus, type LicenseInfo } from "@/lib/license"
import { cn } from "@/lib/utils"
type LicenseInfo = {
state: "missing" | "valid" | "expired" | "invalid"
product_type?: string
client_name?: string
client_id?: string
custom_product_name?: string
machine_ids?: string[]
max_members?: number
not_valid_before?: number
not_valid_after?: number
}
type MachineCodeResponse = {
machine_code: string
}
@@ -104,6 +93,7 @@ export function PaidLicenseCard({ className }: { className?: string }) {
body: form,
})
setInfo(next)
publishLicenseStatus(next)
setFile(null)
formElement.reset()
setImportOpen(false)
@@ -0,0 +1,46 @@
import { useEffect, useState } from "react"
import { api } from "@/lib/api"
import { LICENSE_STATUS_CHANGED, type LicenseInfo } from "@/lib/license"
export function useLicenseStatus() {
const [info, setInfo] = useState<LicenseInfo | null>(null)
useEffect(() => {
let controller: AbortController | undefined
const load = () => {
controller?.abort()
const request = new AbortController()
controller = request
void api<LicenseInfo>("/api/admin/v1/license/status", {
signal: request.signal,
})
.then((status) => {
if (!request.signal.aborted) setInfo(status)
})
.catch(() => {
if (!request.signal.aborted) setInfo(null)
})
}
const refresh = () => {
if (document.visibilityState === "visible") load()
}
const onImported = (event: Event) => {
controller?.abort()
setInfo((event as CustomEvent<LicenseInfo>).detail)
}
load()
const timer = window.setInterval(refresh, 60_000)
document.addEventListener("visibilitychange", refresh)
window.addEventListener(LICENSE_STATUS_CHANGED, onImported)
return () => {
controller?.abort()
window.clearInterval(timer)
document.removeEventListener("visibilitychange", refresh)
window.removeEventListener(LICENSE_STATUS_CHANGED, onImported)
}
}, [])
return info
}
+19
View File
@@ -0,0 +1,19 @@
export type LicenseInfo = {
state: "missing" | "valid" | "expired" | "invalid"
product_type?: string
client_name?: string
client_id?: string
custom_product_name?: string
machine_ids?: string[]
max_members?: number
not_valid_before?: number
not_valid_after?: number
}
export const LICENSE_STATUS_CHANGED = "monkeyai:license-status-changed"
export function publishLicenseStatus(info: LicenseInfo) {
window.dispatchEvent(
new CustomEvent<LicenseInfo>(LICENSE_STATUS_CHANGED, { detail: info })
)
}