feat(webui): notify when a newer release is available

Advisory, read-only update check: the core polls GitHub's latest stable release, compares it against the running build, and surfaces a notice in the sidebar footer plus a detailed card (changelog + download link + platform-matched asset hint) in Settings → About.

SnowLuma never downloads or applies anything itself — cross-platform self-update is a minefield (Windows locks loaded .node/.dll, Docker bakes the app into image layers, bare installs have no supervisor), so the user downloads and applies manually.

The backend caches results for 6h to stay under GitHub's unauthenticated rate limit, degrades silently on failure, and can be disabled via SNOWLUMA_UPDATE_CHECK=0.
This commit is contained in:
DrSmoothl committed 2026-06-05 16:08:38 +08:00
1 parent 28db1d1079
commit 56dc934106
9 files changed
+362 -5

No files matched your search

@@ -1,10 +1,11 @@
import { LayoutDashboard, PlugZap, Settings, SlidersHorizontal, Terminal } from 'lucide-react';
import { LayoutDashboard, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react';
import { motion } from 'motion/react';
import { Link, useRouterState } from '@tanstack/react-router';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Separator } from '@/components/ui/separator';
import { cn } from '@/lib/utils';
import { APP_NAME, APP_VERSION } from '@/types';
import { useAppState } from '@/contexts/AppStateContext';
import type { AppPath } from '@/router';
export interface NavItem {
@@ -29,6 +30,7 @@ interface SidebarProps {
export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
const pathname = useRouterState({ select: (s) => s.location.pathname });
const { updateInfo } = useAppState();
return (
<div className="flex h-full w-full flex-col bg-sidebar text-sidebar-foreground">
@@ -89,6 +91,31 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
</ScrollArea>
<Separator />
{updateInfo?.hasUpdate && (
<div className={cn('px-2 pt-2', collapsed && 'px-0')}>
<Link
to="/settings"
onClick={onItemClick}
title={updateInfo.latest ? `有新版本 v${updateInfo.latest} · 点击查看` : '有可用更新'}
aria-label="有可用更新"
className={cn(
'group relative flex items-center gap-2.5 rounded-lg border border-primary/30 bg-primary/[0.07] px-3 py-2 text-left transition-colors hover:bg-primary/10',
collapsed && 'mx-auto w-10 justify-center px-0',
)}
>
<Sparkles className="size-4 shrink-0 text-primary" />
{!collapsed && (
<span className="flex min-w-0 flex-1 flex-col">
<span className="text-xs font-medium leading-tight text-foreground">有新版本可用</span>
<span className="truncate text-[10px] text-muted-foreground">v{updateInfo.latest} · 点击查看</span>
</span>
)}
{collapsed && (
<span className="absolute right-1 top-1 size-2 rounded-full border-2 border-sidebar bg-primary" />
)}
</Link>
</div>
)}
<div className={cn('px-4 py-3 text-[10px] text-muted-foreground', collapsed && 'text-center px-2')}>
{collapsed ? '©' : `© ${new Date().getFullYear()} SnowLuma`}
</div>
@@ -1,6 +1,6 @@
import { useState, type ReactNode } from 'react';
import { motion } from 'motion/react';
import { Bug, Check, ExternalLink, Github, Info, KeyRound, Monitor, Moon, Palette, RefreshCw, ShieldCheck, Star, Sun, Tag } from 'lucide-react';
import { Bug, Check, Download, ExternalLink, Github, Info, KeyRound, Loader2, Monitor, Moon, Palette, RefreshCw, ShieldCheck, Sparkles, Star, Sun, Tag } from 'lucide-react';
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
@@ -312,6 +312,101 @@ function AccountPanel() {
const REPO_URL = 'https://github.com/SnowLuma/SnowLuma';
// Best-effort guess of the release asset matching the running platform, so
// the user knows which file to grab on the GitHub release page. Returns null
// for platforms with no official asset (e.g. macOS).
function assetHint(latest: string, platform?: string, arch?: string): string | null {
if (!platform) return null;
const tag = `v${latest}`;
if (platform === 'win32') return `SnowLuma-${tag}-win-x64.zip`;
if (platform === 'linux') return `SnowLuma-${tag}-linux-${arch === 'arm64' ? 'arm64' : 'x64'}.tar.gz`;
return null;
}
// Advisory update status. Read-only: links to the GitHub release; SnowLuma
// never downloads or applies anything itself.
function UpdateStatus() {
const { updateInfo, refreshUpdate, systemInfo } = useAppState();
const [checking, setChecking] = useState(false);
const onCheck = async () => {
setChecking(true);
try {
await refreshUpdate(true);
} finally {
setChecking(false);
}
};
const checkButton = (
<Button variant="outline" size="sm" onClick={onCheck} disabled={checking}>
{checking ? <Loader2 className="size-4 animate-spin" /> : <RefreshCw className="size-4" />}
重新检查
</Button>
);
if (updateInfo?.hasUpdate && updateInfo.latest) {
const hint = assetHint(updateInfo.latest, systemInfo?.platform, systemInfo?.arch);
return (
<div className="w-full max-w-md rounded-xl border border-primary/30 bg-primary/[0.06] p-4 text-left">
<div className="flex items-center gap-2">
<Sparkles className="size-4 text-primary" />
<span className="text-sm font-medium">发现新版本 v{updateInfo.latest}</span>
{updateInfo.publishedAt && (
<span className="ml-auto text-[11px] tabular-nums text-muted-foreground">
{new Date(updateInfo.publishedAt).toLocaleDateString()}
</span>
)}
</div>
<p className="mt-1 text-[11px] text-muted-foreground">
当前 v{updateInfo.current} → 最新 v{updateInfo.latest}
</p>
{updateInfo.notes && (
<pre className="mt-3 max-h-40 overflow-auto whitespace-pre-wrap rounded-lg bg-muted/50 p-3 text-[11px] leading-relaxed text-muted-foreground">
{updateInfo.notes}
</pre>
)}
{hint && (
<p className="mt-3 text-[11px] text-muted-foreground">
适合你的平台:
<code className="rounded bg-muted px-1 py-0.5 font-mono">{hint}</code>
(在下载页选择)
</p>
)}
<div className="mt-3 flex items-center gap-2">
{updateInfo.htmlUrl && (
<Button asChild size="sm">
<a href={updateInfo.htmlUrl} target="_blank" rel="noreferrer noopener">
<Download className="size-4" />
前往下载
</a>
</Button>
)}
{checkButton}
</div>
</div>
);
}
let text: string;
if (!updateInfo) text = '正在检查更新…';
else if (updateInfo.error === 'disabled') text = '更新检查已关闭';
else if (updateInfo.error) text = '无法检查更新';
else text = `已是最新版本(v${updateInfo.current})`;
const ok = !!updateInfo && !updateInfo.error;
return (
<div className="flex w-full max-w-md flex-wrap items-center justify-center gap-3 text-[12px] text-muted-foreground">
<span className="inline-flex items-center gap-1.5">
{ok ? <Check className="size-3.5 text-success" /> : <Info className="size-3.5" />}
{text}
</span>
{updateInfo?.error !== 'disabled' && checkButton}
</div>
);
}
function AboutPanel() {
return (
<Card className="overflow-hidden">
@@ -340,6 +435,9 @@ function AboutPanel() {
以轻量注入驱动 QQ NT,对外提供标准 OneBot v11 接口,让机器人一次部署、长期稳定运行。
</p>
{/* Update status */}
<UpdateStatus />
{/* Star CTA */}
<div className="flex w-full max-w-sm flex-col items-center gap-2 rounded-xl border bg-gradient-to-b from-primary/[0.07] to-transparent p-5">
<Star className="size-6 fill-primary/20 text-primary" />