feat: 升级至 v0.3.16 — 工单修复 51 项 + 审查修复 30 项(安全加固/适配器/工具系统/数据层/前端)

This commit is contained in:
2026-07-22 10:31:13 +08:00
parent 516d8a728f
commit 2c2ca4a692
43 changed files with 1454 additions and 301 deletions
+23 -2
View File
@@ -140,6 +140,9 @@ const metonaAPI = {
showItemInFolder: (path: string) => ipcRenderer.invoke('app:showItemInFolder', path),
selectFolder: (defaultPath?: string) => ipcRenderer.invoke('app:selectFolder', defaultPath),
restart: () => ipcRenderer.invoke('app:restart'),
// #49 修复: 前端错误上报通道(主进程可注册 'error:report' handler 记录到 electron-log/审计日志)
// 使用 send(单向)而非 invoke,即使主进程未注册 handler 也不会 reject
reportError: (payload: unknown) => ipcRenderer.send('error:report', payload),
},
// ===== 工作空间管理 =====
@@ -148,6 +151,9 @@ const metonaAPI = {
inheritFiles: (params: { targetPath: string; sourcePath: string; files: string[] }) =>
ipcRenderer.invoke('workspace:inheritFiles', params),
getInfo: () => ipcRenderer.invoke('workspace:getInfo'),
// #51 修复: 校验源数据库完整性(PRAGMA integrity_check),用于 inheritDatabase 前置校验
checkDatabaseIntegrity: (sourcePath: string) =>
ipcRenderer.invoke('workspace:checkDatabaseIntegrity', sourcePath),
},
// ===== 工具管理 =====
@@ -187,10 +193,25 @@ if (process.contextIsolated) {
contextBridge.exposeInMainWorld('electron', electronAPI);
contextBridge.exposeInMainWorld('metona', metonaAPI);
} catch (error) {
console.error('Failed to expose APIs:', error);
console.error('Failed to expose APIs via contextBridge:', error);
// #7 修复: 生产环境强制失败,防止以不安全状态启动(contextBridge 失败意味着
// context isolation 边界已破坏,继续运行可能导致渲染进程直接访问 Node API)
// 开发环境降级到 globalThis 以便调试
// 审查修复: process.defaultApp 在 sandbox: true 下可能为 undefined
// 导致开发环境也无法降级。补充 process.env.NODE_ENV 判断(sandbox 下 process.env 仍可用)
if (process.env.NODE_ENV === 'development' || process.defaultApp) {
console.warn('[DEV] Falling back to globalThis assignment — context isolation is weakened');
(globalThis as unknown as Record<string, unknown>).electron = electronAPI;
(globalThis as unknown as Record<string, unknown>).metona = metonaAPI;
} else {
// 审查修复 M19: 在 throw 前记录详细错误,便于在 DevTools 中排查白屏问题。
// 生产环境 contextBridge 失败时用户只看到白屏,console.error 至少能在 DevTools 中留下线索。
console.error('[FATAL] contextBridge failed in production:', error);
throw error;
}
}
} else {
// 降级方案(不推荐
// context isolation 未启用(不推荐,仅开发环境
(globalThis as unknown as Record<string, unknown>).electron = electronAPI;
(globalThis as unknown as Record<string, unknown>).metona = metonaAPI;
}