mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-05-16 11:19:58 +00:00
enhance: remove duplicate install checks
This commit is contained in:
parent
01acb458cc
commit
65bf0f546a
3 changed files with 27 additions and 52 deletions
|
|
@ -18,7 +18,7 @@ import kill from 'tree-kill';
|
|||
import { zipFolder } from './utils/log'
|
||||
import axios from 'axios';
|
||||
import FormData from 'form-data';
|
||||
import { checkAndInstallDepsOnUpdate, installDependencies, PromiseReturnType } from './install-deps'
|
||||
import { checkAndInstallDepsOnUpdate, PromiseReturnType, getInstallationStatus } from './install-deps'
|
||||
import e from 'express'
|
||||
|
||||
const userData = app.getPath('userData');
|
||||
|
|
@ -197,51 +197,6 @@ const checkManagerInstance = (manager: any, name: string) => {
|
|||
return manager;
|
||||
};
|
||||
|
||||
export const handleDependencyInstallation = async () => {
|
||||
try {
|
||||
log.info(' start install dependencies...');
|
||||
|
||||
const isSuccess:PromiseReturnType = await installDependencies();
|
||||
if (!isSuccess.success) {
|
||||
log.error('[DEPS INSTALL] install dependencies failed '+isSuccess.message);
|
||||
return { success: false, error: 'install dependencies failed' };
|
||||
}
|
||||
|
||||
log.info('[DEPS INSTALL] install dependencies success, check tool installed status...');
|
||||
const isToolInstalled = await checkToolInstalled();
|
||||
log.info('[DEPS INSTALL] isToolInstalled && !python_process', isToolInstalled.success && !python_process);
|
||||
if (isToolInstalled.success && !python_process) {
|
||||
log.info('[DEPS INSTALL] tool installed, start backend service...');
|
||||
python_process = await startBackend((port) => {
|
||||
backendPort = port;
|
||||
log.info('[DEPS INSTALL] backend service start success', { port });
|
||||
});
|
||||
|
||||
// Notify frontend to install success
|
||||
if (win && !win.isDestroyed()) {
|
||||
win.webContents.send('install-dependencies-complete', { success: true, code: 0 });
|
||||
}
|
||||
|
||||
python_process?.on('exit', (code, signal) => {
|
||||
log.info('[DEPS INSTALL] python process exit', { code, signal });
|
||||
});
|
||||
} else if (!isToolInstalled.success) {
|
||||
log.warn('[DEPS INSTALL] tool not installed, skip backend start'+isToolInstalled.message);
|
||||
} else {
|
||||
log.info('[DEPS INSTALL] backend process already exist, skip start');
|
||||
}
|
||||
|
||||
log.info('[DEPS INSTALL] install dependencies complete');
|
||||
return { success: true };
|
||||
} catch (error: any) {
|
||||
log.error('[DEPS INSTALL] install dependencies error:', error);
|
||||
if (win && !win.isDestroyed()) {
|
||||
win.webContents.send('install-dependencies-complete', { success: false, code: 2 });
|
||||
}
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
};
|
||||
|
||||
function registerIpcHandlers() {
|
||||
// ==================== basic info handler ====================
|
||||
ipcMain.handle('get-browser-port', () => {
|
||||
|
|
@ -872,8 +827,16 @@ function registerIpcHandlers() {
|
|||
});
|
||||
|
||||
// ==================== dependency install handler ====================
|
||||
ipcMain.handle('install-dependencies', handleDependencyInstallation);
|
||||
ipcMain.handle('frontend-ready', handleDependencyInstallation);
|
||||
ipcMain.handle('install-dependencies', async () => {
|
||||
try {
|
||||
if(win === null) throw new Error("Window is null");
|
||||
//Force installation even if versionFile exists
|
||||
const isInstalled = await checkAndInstallDepsOnUpdate({win, forceInstall: true});
|
||||
return { success: true, isInstalled };
|
||||
} catch (error) {
|
||||
return { success: false, error: (error as Error).message };
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('check-tool-installed', async () => {
|
||||
try {
|
||||
|
|
@ -884,6 +847,20 @@ function registerIpcHandlers() {
|
|||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('get-installation-status', async () => {
|
||||
try {
|
||||
const { isInstalling, hasLockFile } = await getInstallationStatus();
|
||||
return {
|
||||
success: true,
|
||||
isInstalling,
|
||||
hasLockFile,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
} catch (error) {
|
||||
return { success: false, error: (error as Error).message };
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== register update related handler ====================
|
||||
registerUpdateIpcHandlers();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,8 +62,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||
deleteFolder: (email: string) => ipcRenderer.invoke('delete-folder', email),
|
||||
getMcpConfigPath: (email: string) => ipcRenderer.invoke('get-mcp-config-path', email),
|
||||
// install dependencies related API
|
||||
installDependencies: () => ipcRenderer.invoke('install-dependencies'),
|
||||
frontendReady: () => ipcRenderer.invoke('frontend-ready'),
|
||||
checkAndInstallDepsOnUpdate: () => ipcRenderer.invoke('install-dependencies'),
|
||||
checkInstallBrowser: () => ipcRenderer.invoke('check-install-browser'),
|
||||
onInstallDependenciesStart: (callback: () => void) => {
|
||||
ipcRenderer.on('install-dependencies-start', callback);
|
||||
|
|
|
|||
3
src/types/electron.d.ts
vendored
3
src/types/electron.d.ts
vendored
|
|
@ -45,8 +45,7 @@ interface ElectronAPI {
|
|||
envRemove: (email: string, key: string) => Promise<any>;
|
||||
getEnvPath: (email: string) => Promise<string>;
|
||||
executeCommand: (command: string,email:string) => Promise<{ success: boolean; stdout?: string; stderr?: string; error?: string }>;
|
||||
installDependencies: () => Promise<{ success: boolean; error?: string }>;
|
||||
frontendReady: () => Promise<{ success: boolean; error?: string }>;
|
||||
checkAndInstallDepsOnUpdate: () => Promise<{ success: boolean; error?: string }>;
|
||||
checkInstallBrowser: () => Promise<{ data:any[] }>;
|
||||
onInstallDependenciesStart: (callback: () => void) => void;
|
||||
onInstallDependenciesLog: (callback: (data: { type: string; data: string }) => void) => void;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue