feat(initialization): 新增配置文件操作和管理员权限检查

- 新增配置文件保存、加载和重置功能
- 添加管理员权限检查和重启为管理员的功能
- 实现 pip 包管理器安装功能
- 优化初始化流程,自动检测并安装依赖
This commit is contained in:
2025-08-07 20:18:53 +08:00
parent e7f898f357
commit 0171c3ca4d
15 changed files with 2397 additions and 8 deletions

View File

@@ -399,6 +399,50 @@ export async function installDependencies(appRoot: string, mirror = 'tsinghua'):
}
}
// 导出pip安装函数
export async function installPipPackage(appRoot: string): Promise<{ success: boolean; error?: string }> {
try {
const pythonPath = path.join(appRoot, 'environment', 'python')
if (!fs.existsSync(pythonPath)) {
throw new Error('Python环境不存在请先安装Python')
}
if (mainWindow) {
mainWindow.webContents.send('download-progress', {
type: 'pip',
progress: 0,
status: 'installing',
message: '正在安装pip...'
})
}
await installPip(pythonPath, appRoot)
if (mainWindow) {
mainWindow.webContents.send('download-progress', {
type: 'pip',
progress: 100,
status: 'completed',
message: 'pip安装完成'
})
}
return { success: true }
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
if (mainWindow) {
mainWindow.webContents.send('download-progress', {
type: 'pip',
progress: 0,
status: 'error',
message: `pip安装失败: ${errorMessage}`
})
}
return { success: false, error: errorMessage }
}
}
// 启动后端
export async function startBackend(appRoot: string): Promise<{ success: boolean; error?: string }> {
try {