[feat] more hw info and update feature

This commit is contained in:
2025-11-08 18:09:35 +08:00
parent 41105d3bab
commit c8d8339f30
13 changed files with 813 additions and 500 deletions

View File

@@ -1,29 +1,76 @@
"use client"
import { useEffect } from "react"
import { useAppStore } from "@/store/app"
import { Switch } from "@heroui/react"
import { Switch, Chip } from "@heroui/react"
import { UpdateChecker } from "@/components/cstb/UpdateChecker"
import { getVersion } from "@tauri-apps/api/app"
export default function Page() {
const app = useAppStore()
// 初始化版本号(如果还没有设置)
useEffect(() => {
if (typeof window !== "undefined" && (!app.state.version || app.state.version === "0.0.1")) {
void getVersion().then((version) => {
app.setVersion(version)
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
// 从环境变量或配置中获取更新服务器地址
// 这里可以改为从 store 或配置文件中读取
const customEndpoint = process.env.NEXT_PUBLIC_UPDATE_ENDPOINT || ""
const githubRepo = process.env.NEXT_PUBLIC_GITHUB_REPO || ""
return (
<section className="flex flex-col gap-4 overflow-hidden">
<div className="flex flex-col items-start gap-4 pt-2 pb-1">
<div className="space-y-2">
<p className="text-sm">{app.state.version}</p>
<p className="text-sm">{app.state.hasUpdate ? "有" : "无"}</p>
<p className="text-sm">使{app.state.useMirror ? "是" : "否"}</p>
<div className="flex items-center gap-2">
<p className="text-sm">{app.state.version}</p>
{app.state.hasUpdate && app.state.latestVersion && (
<Chip size="sm" color="success" variant="flat">
{app.state.latestVersion}
</Chip>
)}
</div>
{/* <p className="text-sm">是否有更新:{app.state.hasUpdate ? "有" : "无"}</p> */}
{/* <p className="text-sm">是否使用镜像源:{app.state.useMirror ? "是" : "否"}</p> */}
</div>
{/* <div className="w-full pt-4 border-t border-zinc-200 dark:border-zinc-800">
<div className="w-full pt-4 border-t border-zinc-200 dark:border-zinc-800">
<h3 className="mb-3 text-sm font-semibold"></h3>
<UpdateChecker customEndpoint={customEndpoint} githubRepo={githubRepo} />
</div> */}
<div className="mb-3 space-y-3">
{/* <Switch
isSelected={app.state.useMirror}
size="sm"
onChange={(e) => app.setUseMirror(e.target.checked)}
>
使用镜像源
</Switch> */}
{/* <p className="text-xs text-zinc-500">
{app.state.useMirror
? "使用自建更新服务检查更新"
: "使用 GitHub Release 检查更新"}
</p> */}
<Switch
isSelected={app.state.includePrerelease}
size="sm"
onChange={(e) => app.setIncludePrerelease(e.target.checked)}
>
</Switch>
<p className="text-xs text-zinc-500">
{app.state.includePrerelease
? "检查更新时会包含预发布版本beta、alpha等"
: "仅检查正式版本"}
</p>
</div>
<UpdateChecker
useMirror={app.state.useMirror}
customEndpoint={customEndpoint || undefined}
includePrerelease={app.state.includePrerelease}
/>
</div>
<div className="flex flex-col w-full pt-4 space-y-3 border-t border-zinc-200 dark:border-zinc-800">
<h3 className="mb-3 text-sm font-semibold"></h3>