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:
130
vite.config.ts
130
vite.config.ts
@@ -1,4 +1,4 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { defineConfig, loadEnv } from 'vite';
|
||||
import path from 'node:path';
|
||||
import electron from 'vite-plugin-electron/simple';
|
||||
import react from '@vitejs/plugin-react';
|
||||
@@ -17,66 +17,80 @@ const __dirname = import.meta.dirname;
|
||||
// 如需避免,可把仅渲染进程用的类型放到 src/types/
|
||||
// ============================================================
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
react(),
|
||||
tailwindcss(),
|
||||
electron({
|
||||
main: {
|
||||
// 主进程入口
|
||||
entry: 'electron/main.ts',
|
||||
// 只监听 electron/ 目录,避免 shared/ 变更误触重启
|
||||
// (默认会监听 entry 文件的所有依赖,包括 shared/)
|
||||
},
|
||||
preload: {
|
||||
input: path.join(__dirname, 'electron/preload.ts'),
|
||||
},
|
||||
}),
|
||||
renderer(),
|
||||
// 打包体积分析(仅 ANALYZE=true 时生成 stats.html)
|
||||
process.env.ANALYZE &&
|
||||
visualizer({
|
||||
open: true,
|
||||
gzipSize: true,
|
||||
brotliSize: true,
|
||||
filename: 'dist/stats.html',
|
||||
export default defineConfig(({ mode }) => {
|
||||
// 加载 .env.development / .env.production 中的环境变量
|
||||
const env = loadEnv(mode, __dirname, '');
|
||||
|
||||
return {
|
||||
plugins: [
|
||||
react(),
|
||||
tailwindcss(),
|
||||
electron({
|
||||
main: {
|
||||
// 主进程入口
|
||||
entry: 'electron/main.ts',
|
||||
// 只监听 electron/ 目录,避免 shared/ 变更误触重启
|
||||
// (默认会监听 entry 文件的所有依赖,包括 shared/)
|
||||
},
|
||||
preload: {
|
||||
input: path.join(__dirname, 'electron/preload.ts'),
|
||||
},
|
||||
}),
|
||||
].filter(Boolean),
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, 'src'),
|
||||
'@shared': path.resolve(__dirname, 'shared'),
|
||||
renderer(),
|
||||
// 打包体积分析(仅 ANALYZE=true 时生成 stats.html)
|
||||
process.env.ANALYZE &&
|
||||
visualizer({
|
||||
open: true,
|
||||
gzipSize: true,
|
||||
brotliSize: true,
|
||||
filename: 'dist/stats.html',
|
||||
}),
|
||||
].filter(Boolean),
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, 'src'),
|
||||
'@shared': path.resolve(__dirname, 'shared'),
|
||||
},
|
||||
},
|
||||
},
|
||||
// ============================================================
|
||||
// 开发服务器 & HMR 配置
|
||||
// ============================================================
|
||||
server: {
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
host: 'localhost',
|
||||
// 文件监听(Windows 优化)
|
||||
watch: {
|
||||
// Windows 上默认的 fs.watch 有时不稳定,
|
||||
// 如果文件保存后界面无反应,可临时开启 usePolling
|
||||
// usePolling: true,
|
||||
// interval: 100,
|
||||
// 忽略不需要监听的目录,减少 CPU 占用
|
||||
ignored: ['**/node_modules/**', '**/dist/**', '**/dist-electron/**', '**/release/**'],
|
||||
// ============================================================
|
||||
// 编译时注入环境变量到主进程
|
||||
// 主进程中的 process.env.xxx 会在编译时被替换为实际值
|
||||
// 这样无需在 OS 环境中设置这些变量
|
||||
// ============================================================
|
||||
define: {
|
||||
'process.env.UPDATE_API_URL': JSON.stringify(env.UPDATE_API_URL || 'https://www.heixiu.com'),
|
||||
'process.env.EDITION': JSON.stringify(env.EDITION || 'personal'),
|
||||
},
|
||||
// HMR 配置
|
||||
hmr: {
|
||||
// 在浏览器控制台显示 HMR 覆盖层(错误/警告时)
|
||||
overlay: true,
|
||||
// 协议默认 ws://,localhost 下无需额外配置
|
||||
// ============================================================
|
||||
// 开发服务器 & HMR 配置
|
||||
// ============================================================
|
||||
server: {
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
host: 'localhost',
|
||||
// 文件监听(Windows 优化)
|
||||
watch: {
|
||||
// Windows 上默认的 fs.watch 有时不稳定,
|
||||
// 如果文件保存后界面无反应,可临时开启 usePolling
|
||||
// usePolling: true,
|
||||
// interval: 100,
|
||||
// 忽略不需要监听的目录,减少 CPU 占用
|
||||
ignored: ['**/node_modules/**', '**/dist/**', '**/dist-electron/**', '**/release/**', '**/test-server/**'],
|
||||
},
|
||||
// HMR 配置
|
||||
hmr: {
|
||||
// 在浏览器控制台显示 HMR 覆盖层(错误/警告时)
|
||||
overlay: true,
|
||||
// 协议默认 ws://,localhost 下无需额外配置
|
||||
},
|
||||
},
|
||||
},
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {},
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
preview: {
|
||||
port: 5173,
|
||||
},
|
||||
preview: {
|
||||
port: 5173,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user