2026-07-11 19:20:17 +08:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
} from "@/components/ui/dialog";
|
|
|
|
|
import {
|
|
|
|
|
Monitor,
|
|
|
|
|
Apple,
|
|
|
|
|
Terminal,
|
|
|
|
|
Loader2,
|
|
|
|
|
AlertCircle,
|
|
|
|
|
Package,
|
|
|
|
|
Hash,
|
2026-08-31 12:01:41 +08:00
|
|
|
Calendar,
|
|
|
|
|
GitBranch,
|
|
|
|
|
PackageOpen,
|
2026-07-11 19:20:17 +08:00
|
|
|
ArrowUpRight,
|
|
|
|
|
FileText,
|
|
|
|
|
Download,
|
|
|
|
|
} from "lucide-react";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
2026-08-31 12:01:41 +08:00
|
|
|
import { MarkdownLite } from "@/components/markdown-lite";
|
|
|
|
|
import {
|
|
|
|
|
DOWNLOAD_SOURCES,
|
|
|
|
|
resolveDownloadUrl,
|
|
|
|
|
type DownloadSourceKey,
|
|
|
|
|
} from "@/lib/download-sources";
|
2026-07-11 19:20:17 +08:00
|
|
|
|
|
|
|
|
interface License {
|
|
|
|
|
isNeedAgreat: string;
|
|
|
|
|
title: string;
|
|
|
|
|
text: string;
|
|
|
|
|
liceURL: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface PlatformInfo {
|
|
|
|
|
isNoVersion: string;
|
|
|
|
|
licence: License;
|
|
|
|
|
DownlodeURL: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface AboutVersion {
|
|
|
|
|
about: string;
|
|
|
|
|
"about-list": Record<string, string>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface BetaData {
|
|
|
|
|
version: string;
|
|
|
|
|
builddate: string;
|
2026-08-31 12:01:41 +08:00
|
|
|
/** 数据来源:github = GitHub Releases 自动识别;legacy = 旧静态源兜底 */
|
|
|
|
|
source?: "github" | "legacy";
|
|
|
|
|
tag?: string;
|
|
|
|
|
htmlUrl?: string;
|
|
|
|
|
releaseNotes?: string;
|
|
|
|
|
/** GitHub 可达但没有预览版时的标记 */
|
|
|
|
|
noRelease?: boolean;
|
2026-07-11 19:20:17 +08:00
|
|
|
app: {
|
|
|
|
|
windows: PlatformInfo;
|
|
|
|
|
macos: PlatformInfo;
|
|
|
|
|
linux: PlatformInfo;
|
|
|
|
|
};
|
2026-08-31 12:01:41 +08:00
|
|
|
aboutversion?: AboutVersion;
|
2026-07-11 19:20:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const platforms = [
|
|
|
|
|
{ key: "windows" as const, label: "Windows", icon: Monitor },
|
|
|
|
|
{ key: "macos" as const, label: "macOS", icon: Apple },
|
|
|
|
|
{ key: "linux" as const, label: "Linux", icon: Terminal },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export default function JoinBetaPage() {
|
|
|
|
|
const [data, setData] = useState<BetaData | null>(null);
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
|
const [dialogOpen, setDialogOpen] = useState(false);
|
|
|
|
|
const [activePlatform, setActivePlatform] = useState<PlatformInfo | null>(null);
|
2026-08-31 12:01:41 +08:00
|
|
|
const [downloadSource, setDownloadSource] = useState<DownloadSourceKey>("github");
|
2026-07-11 19:20:17 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetch("/api/beta-version")
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
|
|
|
return res.json();
|
|
|
|
|
})
|
|
|
|
|
.then((json: BetaData) => {
|
|
|
|
|
setData(json);
|
|
|
|
|
setLoading(false);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
setError(err.message);
|
|
|
|
|
setLoading(false);
|
|
|
|
|
});
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const handleDownload = (platform: PlatformInfo) => {
|
|
|
|
|
if (platform.licence.isNeedAgreat === "true") {
|
|
|
|
|
setActivePlatform(platform);
|
|
|
|
|
setDialogOpen(true);
|
|
|
|
|
} else {
|
2026-08-31 12:01:41 +08:00
|
|
|
window.open(
|
|
|
|
|
resolveDownloadUrl(downloadSource, platform.DownlodeURL),
|
|
|
|
|
"_blank"
|
|
|
|
|
);
|
2026-07-11 19:20:17 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const confirmDownload = () => {
|
|
|
|
|
if (activePlatform?.DownlodeURL) {
|
2026-08-31 12:01:41 +08:00
|
|
|
window.open(
|
|
|
|
|
resolveDownloadUrl(downloadSource, activePlatform.DownlodeURL),
|
|
|
|
|
"_blank"
|
|
|
|
|
);
|
2026-07-11 19:20:17 +08:00
|
|
|
}
|
|
|
|
|
setDialogOpen(false);
|
|
|
|
|
setActivePlatform(null);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col items-center justify-center min-h-[60vh] gap-4">
|
|
|
|
|
<Loader2 className="size-8 animate-spin text-muted-foreground" />
|
|
|
|
|
<p className="text-muted-foreground">正在获取版本信息...</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error || !data) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col items-center justify-center min-h-[60vh] gap-4">
|
|
|
|
|
<AlertCircle className="size-8 text-destructive" />
|
|
|
|
|
<p className="text-muted-foreground">获取版本信息失败</p>
|
|
|
|
|
<Button variant="outline" onClick={() => window.location.reload()}>
|
|
|
|
|
重试
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-31 12:01:41 +08:00
|
|
|
if (data.noRelease) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col items-center justify-center min-h-[60vh] gap-4 text-center px-4">
|
|
|
|
|
<PackageOpen className="size-10 text-muted-foreground" />
|
|
|
|
|
<div>
|
|
|
|
|
<p className="font-semibold text-lg">暂无预览版本</p>
|
|
|
|
|
<p className="text-sm text-muted-foreground max-w-sm mt-1">
|
|
|
|
|
GitHub Releases 中暂时没有可用的预览(Beta)版本,请稍后再来看看
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<a
|
|
|
|
|
href="https://github.com/dream-pep/koring-launcher/releases"
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
>
|
|
|
|
|
<Button variant="outline">
|
|
|
|
|
前往 GitHub Releases
|
|
|
|
|
<ArrowUpRight className="size-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-11 19:20:17 +08:00
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col w-full h-full gap-10 pb-24">
|
|
|
|
|
{/* Header */}
|
|
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
|
<Badge variant="outline" className="w-fit">
|
|
|
|
|
加入 Beta 测试
|
|
|
|
|
</Badge>
|
|
|
|
|
<h1 className="text-3xl md:text-5xl font-bold tracking-tight">
|
|
|
|
|
Koring Launcher
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="text-muted-foreground text-base md:text-lg max-w-xl">
|
|
|
|
|
参与 Koring Launcher 的 Beta 测试计划,抢先体验最新功能
|
|
|
|
|
</p>
|
2026-08-31 12:01:41 +08:00
|
|
|
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground">
|
|
|
|
|
{data.source === "github" ? (
|
|
|
|
|
<>
|
|
|
|
|
<span className="flex items-center gap-1">
|
|
|
|
|
<GitBranch className="size-3" />
|
|
|
|
|
版本信息由 GitHub Releases 自动识别
|
|
|
|
|
</span>
|
|
|
|
|
{data.htmlUrl && (
|
|
|
|
|
<a
|
|
|
|
|
href={data.htmlUrl}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
className="flex items-center gap-1 text-primary underline underline-offset-3 hover:text-primary/80"
|
|
|
|
|
>
|
|
|
|
|
在 GitHub 查看发布页
|
|
|
|
|
<ArrowUpRight className="size-3" />
|
|
|
|
|
</a>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="flex items-center gap-1">
|
|
|
|
|
<GitBranch className="size-3" />
|
|
|
|
|
版本信息来自缓存数据源
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-07-11 19:20:17 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Version Info Card */}
|
|
|
|
|
<div className="rounded-2xl border border-border/50 p-6 bg-background/60 backdrop-blur-xl flex flex-col sm:flex-row gap-6">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="flex items-center justify-center w-10 h-10 rounded-xl bg-primary/10">
|
|
|
|
|
<Package className="size-5 text-primary" />
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<p className="text-xs text-muted-foreground">版本号</p>
|
|
|
|
|
<p className="font-semibold text-lg">{data.version}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="flex items-center justify-center w-10 h-10 rounded-xl bg-primary/10">
|
2026-08-31 12:01:41 +08:00
|
|
|
{data.source === "github" ? (
|
|
|
|
|
<Calendar className="size-5 text-primary" />
|
|
|
|
|
) : (
|
|
|
|
|
<Hash className="size-5 text-primary" />
|
|
|
|
|
)}
|
2026-07-11 19:20:17 +08:00
|
|
|
</div>
|
|
|
|
|
<div>
|
2026-08-31 12:01:41 +08:00
|
|
|
<p className="text-xs text-muted-foreground">
|
|
|
|
|
{data.source === "github" ? "发布时间" : "编译号"}
|
|
|
|
|
</p>
|
|
|
|
|
<p className="font-semibold text-lg">
|
|
|
|
|
{data.source === "github"
|
|
|
|
|
? data.builddate
|
|
|
|
|
? new Date(data.builddate).toLocaleDateString("zh-CN")
|
|
|
|
|
: "未知"
|
|
|
|
|
: data.builddate}
|
|
|
|
|
</p>
|
2026-07-11 19:20:17 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Platform Cards */}
|
|
|
|
|
<div>
|
2026-08-31 12:01:41 +08:00
|
|
|
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4">
|
|
|
|
|
<h2 className="text-xl font-semibold">选择平台</h2>
|
|
|
|
|
{data.source === "github" &&
|
|
|
|
|
platforms.some(({ key }) => !!data.app[key].DownlodeURL) && (
|
|
|
|
|
<div className="flex items-center gap-2 flex-wrap">
|
|
|
|
|
<span className="text-xs text-muted-foreground">下载源</span>
|
|
|
|
|
{DOWNLOAD_SOURCES.map((s) => (
|
|
|
|
|
<button
|
|
|
|
|
key={s.key}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setDownloadSource(s.key)}
|
|
|
|
|
className={cn(
|
|
|
|
|
"rounded-full border px-3 py-1 text-xs transition-colors",
|
|
|
|
|
downloadSource === s.key
|
|
|
|
|
? "border-primary bg-primary/10 text-primary"
|
|
|
|
|
: "border-border text-muted-foreground hover:text-foreground"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{s.label}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-07-11 19:20:17 +08:00
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
|
|
|
|
{platforms.map(({ key, label, icon: Icon }) => {
|
|
|
|
|
const platform = data.app[key];
|
|
|
|
|
const noVersion = platform.isNoVersion === "true";
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={key}
|
|
|
|
|
className={cn(
|
|
|
|
|
"rounded-2xl border p-6 flex flex-col gap-4 transition-all duration-300",
|
|
|
|
|
noVersion
|
|
|
|
|
? "border-border/30 opacity-60"
|
|
|
|
|
: "border-border/50 bg-background/60 backdrop-blur-xl hover:scale-[1.02]"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex items-center justify-center w-10 h-10 rounded-xl",
|
|
|
|
|
noVersion ? "bg-muted" : "bg-primary/10"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<Icon
|
|
|
|
|
className={cn(
|
|
|
|
|
"size-5",
|
|
|
|
|
noVersion ? "text-muted-foreground" : "text-primary"
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<span className="font-semibold text-lg">{label}</span>
|
|
|
|
|
</div>
|
|
|
|
|
{noVersion ? (
|
|
|
|
|
<p className="text-sm text-muted-foreground">
|
|
|
|
|
未提供对应版本
|
|
|
|
|
</p>
|
|
|
|
|
) : (
|
|
|
|
|
<Button
|
|
|
|
|
className="w-full mt-auto"
|
|
|
|
|
onClick={() => handleDownload(platform)}
|
|
|
|
|
>
|
|
|
|
|
<Download className="size-4" />
|
|
|
|
|
下载
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-08-31 12:01:41 +08:00
|
|
|
{/* Release Notes / About This Version */}
|
2026-07-11 19:20:17 +08:00
|
|
|
<div className="rounded-2xl border border-border/50 p-6 md:p-8 bg-background/60 backdrop-blur-xl">
|
|
|
|
|
<div className="flex items-center gap-2 mb-4">
|
|
|
|
|
<FileText className="size-5 text-primary" />
|
2026-08-31 12:01:41 +08:00
|
|
|
<h2 className="text-xl font-semibold">
|
|
|
|
|
{data.releaseNotes ? "版本更新内容" : "关于此版本"}
|
|
|
|
|
</h2>
|
2026-07-11 19:20:17 +08:00
|
|
|
</div>
|
2026-08-31 12:01:41 +08:00
|
|
|
{data.releaseNotes ? (
|
|
|
|
|
<MarkdownLite text={data.releaseNotes} />
|
|
|
|
|
) : data.aboutversion ? (
|
|
|
|
|
<>
|
|
|
|
|
<p className="text-muted-foreground leading-relaxed mb-4">
|
|
|
|
|
{data.aboutversion.about}
|
|
|
|
|
</p>
|
|
|
|
|
<ul className="flex flex-col gap-2">
|
|
|
|
|
{Object.entries(data.aboutversion["about-list"]).map(
|
|
|
|
|
([key, text]) => (
|
|
|
|
|
<li key={key} className="flex items-start gap-2 text-sm">
|
|
|
|
|
<span className="mt-1.5 size-1.5 rounded-full bg-primary shrink-0" />
|
|
|
|
|
<span className="text-muted-foreground">{text}</span>
|
|
|
|
|
</li>
|
|
|
|
|
)
|
|
|
|
|
)}
|
|
|
|
|
</ul>
|
|
|
|
|
</>
|
|
|
|
|
) : null}
|
2026-07-11 19:20:17 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* License Dialog */}
|
|
|
|
|
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
|
|
|
|
|
<DialogContent className="sm:max-w-md">
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle>{activePlatform?.licence.title}</DialogTitle>
|
|
|
|
|
<DialogDescription className="text-sm leading-relaxed whitespace-pre-line mt-2">
|
|
|
|
|
{activePlatform?.licence.text}
|
|
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
{activePlatform?.licence.liceURL && (
|
|
|
|
|
<a
|
|
|
|
|
href={activePlatform.licence.liceURL}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
className="text-sm text-primary underline underline-offset-3 hover:text-primary/80 flex items-center gap-1 w-fit"
|
|
|
|
|
>
|
|
|
|
|
<ArrowUpRight className="size-3.5" />
|
|
|
|
|
查看《Koring APP Beta 测试协议》
|
|
|
|
|
</a>
|
|
|
|
|
)}
|
|
|
|
|
<DialogFooter>
|
|
|
|
|
<Button variant="outline" onClick={() => setDialogOpen(false)}>
|
|
|
|
|
取消
|
|
|
|
|
</Button>
|
|
|
|
|
<Button onClick={confirmDownload}>
|
|
|
|
|
<ArrowUpRight className="size-4" />
|
|
|
|
|
同意并下载
|
|
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|