refactor: 重构环境检查逻辑,添加环境不完整提示页面
This commit is contained in:
@@ -516,6 +516,47 @@ ipcMain.handle('check-environment', async () => {
|
||||
return checkEnvironment(appRoot)
|
||||
})
|
||||
|
||||
// 关键文件检查 - 每次都重新检查exe文件是否存在
|
||||
ipcMain.handle('check-critical-files', async () => {
|
||||
try {
|
||||
const appRoot = getAppRoot()
|
||||
|
||||
// 检查Python可执行文件
|
||||
const pythonPath = path.join(appRoot, 'environment', 'python', 'python.exe')
|
||||
const pythonExists = fs.existsSync(pythonPath)
|
||||
|
||||
// 检查pip(通常与Python一起安装)
|
||||
const pipPath = path.join(appRoot, 'environment', 'python', 'Scripts', 'pip.exe')
|
||||
const pipExists = fs.existsSync(pipPath)
|
||||
|
||||
// 检查Git可执行文件
|
||||
const gitPath = path.join(appRoot, 'environment', 'git', 'bin', 'git.exe')
|
||||
const gitExists = fs.existsSync(gitPath)
|
||||
|
||||
// 检查后端主文件
|
||||
const mainPyPath = path.join(appRoot, 'main.py')
|
||||
const mainPyExists = fs.existsSync(mainPyPath)
|
||||
|
||||
const result = {
|
||||
pythonExists,
|
||||
pipExists,
|
||||
gitExists,
|
||||
mainPyExists
|
||||
}
|
||||
|
||||
log.info('关键文件检查结果:', result)
|
||||
return result
|
||||
} catch (error) {
|
||||
log.error('检查关键文件失败:', error)
|
||||
return {
|
||||
pythonExists: false,
|
||||
pipExists: false,
|
||||
gitExists: false,
|
||||
mainPyExists: false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Python相关
|
||||
ipcMain.handle('download-python', async (_event, mirror = 'tsinghua') => {
|
||||
const appRoot = getAppRoot()
|
||||
@@ -547,6 +588,17 @@ ipcMain.handle('download-git', async () => {
|
||||
return downloadGit(appRoot)
|
||||
})
|
||||
|
||||
ipcMain.handle('check-git-update', async () => {
|
||||
try {
|
||||
// 这里可以实现检查Git仓库更新的逻辑
|
||||
// 暂时返回false,表示没有更新
|
||||
return { hasUpdate: false }
|
||||
} catch (error) {
|
||||
log.error('检查Git更新失败:', error)
|
||||
return { hasUpdate: false, error: error instanceof Error ? error.message : String(error) }
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle(
|
||||
'clone-backend',
|
||||
async (_event, repoUrl = 'https://github.com/AUTO-MAS-Project/AUTO-MAS.git') => {
|
||||
|
||||
@@ -19,9 +19,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||
|
||||
// 初始化相关API
|
||||
checkEnvironment: () => ipcRenderer.invoke('check-environment'),
|
||||
checkCriticalFiles: () => ipcRenderer.invoke('check-critical-files'),
|
||||
downloadPython: (mirror?: string) => ipcRenderer.invoke('download-python', mirror),
|
||||
installPip: () => ipcRenderer.invoke('install-pip'),
|
||||
downloadGit: () => ipcRenderer.invoke('download-git'),
|
||||
checkGitUpdate: () => ipcRenderer.invoke('check-git-update'),
|
||||
installDependencies: (mirror?: string) => ipcRenderer.invoke('install-dependencies', mirror),
|
||||
cloneBackend: (repoUrl?: string) => ipcRenderer.invoke('clone-backend', repoUrl),
|
||||
updateBackend: (repoUrl?: string) => ipcRenderer.invoke('update-backend', repoUrl),
|
||||
|
||||
Reference in New Issue
Block a user