enhance: remove duplicate install checks

This commit is contained in:
a7m-1st 2025-09-23 21:34:46 +03:00
parent 01acb458cc
commit 65bf0f546a
3 changed files with 27 additions and 52 deletions

View file

@ -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();
}

View file

@ -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);

View file

@ -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;