* fix:尝试修复闪退的问题

* hhhhh
This commit is contained in:
xuncha
2026-01-22 18:46:22 +08:00
committed by GitHub
parent 0e3ab8e4d6
commit 49614bf6d8
4 changed files with 52 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
import { app, BrowserWindow, ipcMain, nativeTheme } from 'electron'
import { Worker } from 'worker_threads'
import { join } from 'path'
import { join, dirname } from 'path'
import { autoUpdater } from 'electron-updater'
import { readFile, writeFile, mkdir } from 'fs/promises'
import { existsSync } from 'fs'
@@ -28,6 +28,47 @@ const AUTO_UPDATE_ENABLED =
process.env.AUTO_UPDATE_ENABLED === '1' ||
(process.env.AUTO_UPDATE_ENABLED == null && !process.env.VITE_DEV_SERVER_URL)
// 使用白名单过滤 PATH避免被第三方目录中的旧版 VC++ 运行库劫持。
// 仅保留系统目录Windows/System32/SysWOW64和应用自身目录可执行目录、resources
function sanitizePathEnv() {
// 开发模式不做裁剪,避免影响本地工具链
if (process.env.VITE_DEV_SERVER_URL) return
const rawPath = process.env.PATH || process.env.Path
if (!rawPath) return
const sep = process.platform === 'win32' ? ';' : ':'
const parts = rawPath.split(sep).filter(Boolean)
const systemRoot = process.env.SystemRoot || process.env.WINDIR || ''
const safePrefixes = [
systemRoot,
systemRoot ? join(systemRoot, 'System32') : '',
systemRoot ? join(systemRoot, 'SysWOW64') : '',
dirname(process.execPath),
process.resourcesPath,
join(process.resourcesPath || '', 'resources')
].filter(Boolean)
const normalize = (p: string) => p.replace(/\\/g, '/').toLowerCase()
const isSafe = (p: string) => {
const np = normalize(p)
return safePrefixes.some((prefix) => np.startsWith(normalize(prefix)))
}
const filtered = parts.filter(isSafe)
if (filtered.length !== parts.length) {
const removed = parts.filter((p) => !isSafe(p))
console.warn('[WeFlow] 使用白名单裁剪 PATH移除目录:', removed)
const nextPath = filtered.join(sep)
process.env.PATH = nextPath
process.env.Path = nextPath
}
}
// 启动时立即清理 PATH后续创建的 worker 也能继承安全的环境
sanitizePathEnv()
// 单例服务
let configService: ConfigService | null = null