feat: 重构更新流程 — 无更新不抛异常、用户决定下载、更新详情展示(md文件中的)
【核心重构】
- getLatestVersion() 不再 throw Error,无更新时返回 { version: APP_VERSION }
- checkForUpdates() 先自行预检 → 无更新直发 IPC,有更新才交 electron-updater
- 移除 NO_UPDATE_MESSAGE 常量及所有字符串匹配拦截代码
- HeiXiuProvider 增加 500ms TTL 缓存,避免预检+electron-updater 重复请求 API
【用户体验】
- 检查到新版本后不再自动下载,展示更新内容供用户决定
- 新增"下载更新"按钮(与"安装更新"分离为两步操作)
- 设置页新增"查看详情"弹窗,Markdown 格式化渲染更新日志
- available / downloading / downloaded 三个状态 UI 独立展示
【Bug 修复】
- 测试服务器版本排序:字符串序 → 语义版本序(_version_key),0.0.10 正确 > 0.0.9
- 版本比较:!= → <(_version_key),防止高版本误判为有更新
- get_best_release fallback 同样改为语义版本排序
- Windows cmd set 命令尾部空格 → Invalid URL(.trim() 修复)
- electron-updater 'error' 事件中拦截 NO_UPDATE_MESSAGE → UPDATE_NOT_AVAILABLE
【文档更新】
- CHANGELOG.md、PROJECT.md、UpdateA.md 同步更新架构图和流程说明
This commit is contained in:
@@ -2,18 +2,67 @@
|
||||
// UpdateSetting — 版本更新区块
|
||||
// ============================================================
|
||||
|
||||
import { Card, Button, Typography, Progress, Tag } from 'antd';
|
||||
import { useState } from 'react';
|
||||
import { Card, Button, Typography, Progress, Tag, Modal, Divider } from 'antd';
|
||||
import {
|
||||
SyncOutlined,
|
||||
CheckCircleOutlined,
|
||||
ExclamationCircleOutlined,
|
||||
RocketOutlined,
|
||||
DownloadOutlined,
|
||||
FileTextOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { useUpdater } from '@/hooks/use-updater';
|
||||
import { isDev } from '@/utils/platform';
|
||||
|
||||
const { Text } = Typography;
|
||||
const { Text, Title } = Typography;
|
||||
|
||||
/** 简单渲染 changelog(Markdown → JSX),支持 ## / - / --- */
|
||||
function renderChangelog(markdown: string) {
|
||||
const lines = markdown.split('\n');
|
||||
const elements: React.ReactNode[] = [];
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
const key = `cl-${i}`;
|
||||
|
||||
if (line.startsWith('## ')) {
|
||||
elements.push(
|
||||
<Title key={key} level={5} className="!mt-3! !mb-1!">
|
||||
{line.slice(3)}
|
||||
</Title>,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (/^-{3,}$/.test(line.trim())) {
|
||||
elements.push(<Divider key={key} className="!my-2!" />);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.trim().startsWith('- ')) {
|
||||
elements.push(
|
||||
<Text key={key} className="block pl-3 text-sm leading-relaxed">
|
||||
• {line.trim().slice(2)}
|
||||
</Text>,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.trim() === '') {
|
||||
elements.push(<div key={key} className="h-2" />);
|
||||
continue;
|
||||
}
|
||||
|
||||
elements.push(
|
||||
<Text key={key} className="block text-sm leading-relaxed">
|
||||
{line}
|
||||
</Text>,
|
||||
);
|
||||
}
|
||||
|
||||
return elements.length > 0 ? elements : <Text type="secondary">暂无更新详情</Text>;
|
||||
}
|
||||
|
||||
export function UpdateSetting() {
|
||||
const {
|
||||
@@ -22,19 +71,23 @@ export function UpdateSetting() {
|
||||
progress,
|
||||
error,
|
||||
checkForUpdates,
|
||||
downloadUpdate,
|
||||
installUpdate,
|
||||
} = useUpdater();
|
||||
|
||||
const [detailOpen, setDetailOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<Card size="small" title="版本更新" className="rounded-md!">
|
||||
<div className="flex flex-col gap-3">
|
||||
{/* ---- 状态展示 ---- */}
|
||||
{/* ---- idle ---- */}
|
||||
{status === 'idle' && (
|
||||
<Text type="secondary" className="text-sm">
|
||||
点击下方按钮检查是否有新版本
|
||||
</Text>
|
||||
)}
|
||||
|
||||
{/* ---- checking ---- */}
|
||||
{status === 'checking' && (
|
||||
<div className="flex items-center gap-2">
|
||||
<SyncOutlined spin style={{ color: 'var(--color-primary, #4F46E5)' }} />
|
||||
@@ -42,6 +95,7 @@ export function UpdateSetting() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ---- no-update ---- */}
|
||||
{status === 'no-update' && (
|
||||
<div className="flex items-center gap-2">
|
||||
<CheckCircleOutlined style={{ color: 'var(--color-success, #52c41a)' }} />
|
||||
@@ -49,6 +103,7 @@ export function UpdateSetting() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ---- error ---- */}
|
||||
{status === 'error' && (
|
||||
<div className="flex items-center gap-2">
|
||||
<ExclamationCircleOutlined style={{ color: 'var(--color-error, #ff4d4f)' }} />
|
||||
@@ -56,8 +111,8 @@ export function UpdateSetting() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ---- 发现新版本 / 下载中 ---- */}
|
||||
{(status === 'available' || status === 'downloading') && (
|
||||
{/* ---- 发现新版本(等待用户决定)---- */}
|
||||
{status === 'available' && (
|
||||
<>
|
||||
<div className="flex items-center gap-2">
|
||||
<RocketOutlined style={{ color: 'var(--color-primary, #4F46E5)' }} />
|
||||
@@ -65,20 +120,52 @@ export function UpdateSetting() {
|
||||
{info?.forceUpdate && <Tag color="red">强制更新</Tag>}
|
||||
</div>
|
||||
{info?.releaseNotes && (
|
||||
<Text type="secondary" className="text-xs whitespace-pre-line">
|
||||
{info.releaseNotes}
|
||||
</Text>
|
||||
<div className="flex items-start gap-2">
|
||||
<Text
|
||||
type="secondary"
|
||||
className="text-xs whitespace-pre-line line-clamp-2 flex-1"
|
||||
>
|
||||
{info.releaseNotes
|
||||
.replace(/^## .+?\n\n?/, '')
|
||||
.replace(/\n---\n?[\s\S]*$/, '')
|
||||
.trim()}
|
||||
</Text>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
icon={<FileTextOutlined />}
|
||||
onClick={() => setDetailOpen(true)}
|
||||
className="!px-1! flex-shrink-0"
|
||||
>
|
||||
查看详情
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
icon={<DownloadOutlined />}
|
||||
onClick={downloadUpdate}
|
||||
className="self-start"
|
||||
>
|
||||
下载更新
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ---- 下载进度 ---- */}
|
||||
{/* ---- 下载中 ---- */}
|
||||
{status === 'downloading' && (
|
||||
<Progress
|
||||
percent={progress.percent}
|
||||
strokeColor={{ '0%': '#4F46E5', '100%': '#7C3AED' }}
|
||||
size="small"
|
||||
/>
|
||||
<>
|
||||
<div className="flex items-center gap-2">
|
||||
<DownloadOutlined style={{ color: 'var(--color-primary, #4F46E5)' }} />
|
||||
<Text>正在下载 v{info?.version}...</Text>
|
||||
</div>
|
||||
<Progress
|
||||
percent={progress.percent}
|
||||
strokeColor={{ '0%': '#4F46E5', '100%': '#7C3AED' }}
|
||||
size="small"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ---- 下载完成 ---- */}
|
||||
@@ -106,17 +193,34 @@ export function UpdateSetting() {
|
||||
size="small"
|
||||
icon={<SyncOutlined spin={status === 'checking'} />}
|
||||
onClick={checkForUpdates}
|
||||
disabled={status === 'checking'}
|
||||
disabled={status === 'checking' || status === 'downloading'}
|
||||
>
|
||||
检查更新
|
||||
</Button>
|
||||
{isDev() && (
|
||||
<Text type="secondary" className="text-xs">
|
||||
生产环境启动 5 秒后自动检查
|
||||
生产环境启动 5 秒后自动检查
|
||||
</Text>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ---- 更新详情弹窗 ---- */}
|
||||
<Modal
|
||||
title={`更新详情 — v${info?.version || ''}`}
|
||||
open={detailOpen}
|
||||
onCancel={() => setDetailOpen(false)}
|
||||
footer={
|
||||
<Button onClick={() => setDetailOpen(false)}>关闭</Button>
|
||||
}
|
||||
width={520}
|
||||
>
|
||||
<div className="max-h-96 overflow-y-auto py-2">
|
||||
{info?.releaseNotes
|
||||
? renderChangelog(info.releaseNotes)
|
||||
: <Text type="secondary">暂无更新详情</Text>}
|
||||
</div>
|
||||
</Modal>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user