【核心重构】
- 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 同步更新架构图和流程说明
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { ipcRenderer, contextBridge } from 'electron';
|
||
import { BIDIRECTIONAL } from '../shared/constants/ipc-channels';
|
||
|
||
// --------- Expose some API to the Renderer process ---------
|
||
contextBridge.exposeInMainWorld('ipcRenderer', {
|
||
on(...args: Parameters<typeof ipcRenderer.on>) {
|
||
const [channel, listener] = args;
|
||
return ipcRenderer.on(channel, (event, ...args) => listener(event, ...args));
|
||
},
|
||
off(...args: Parameters<typeof ipcRenderer.off>) {
|
||
const [channel, ...omit] = args;
|
||
return ipcRenderer.off(channel, ...omit);
|
||
},
|
||
send(...args: Parameters<typeof ipcRenderer.send>) {
|
||
const [channel, ...omit] = args;
|
||
return ipcRenderer.send(channel, ...omit);
|
||
},
|
||
invoke(...args: Parameters<typeof ipcRenderer.invoke>) {
|
||
const [channel, ...omit] = args;
|
||
return ipcRenderer.invoke(channel, ...omit);
|
||
},
|
||
});
|
||
|
||
// --------- 安全加密 API(基于 Electron safeStorage)---------
|
||
contextBridge.exposeInMainWorld('safeStorage', {
|
||
/**
|
||
* 加密明文字符串
|
||
* @param plaintext - 待加密的明文
|
||
* @returns Base64 编码的密文,失败返回 null
|
||
*/
|
||
async encrypt(plaintext: string): Promise<string | null> {
|
||
const result = await ipcRenderer.invoke(BIDIRECTIONAL.SAFESTORAGE_ENCRYPT, plaintext);
|
||
return result?.success ? result.data : null;
|
||
},
|
||
|
||
/**
|
||
* 解密 Base64 密文
|
||
* @param encryptedBase64 - Base64 编码的密文
|
||
* @returns 解密后的明文,失败返回 null
|
||
*/
|
||
async decrypt(encryptedBase64: string): Promise<string | null> {
|
||
const result = await ipcRenderer.invoke(BIDIRECTIONAL.SAFESTORAGE_DECRYPT, encryptedBase64);
|
||
return result?.success ? result.data : null;
|
||
},
|
||
});
|