From 65bf0f546a5a4e7e7a642bf3a87f0acdcb7cd956 Mon Sep 17 00:00:00 2001 From: a7m-1st Date: Tue, 23 Sep 2025 21:34:46 +0300 Subject: [PATCH] enhance: remove duplicate install checks --- electron/main/index.ts | 73 ++++++++++++++------------------------- electron/preload/index.ts | 3 +- src/types/electron.d.ts | 3 +- 3 files changed, 27 insertions(+), 52 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index 0c8560d50..fa2b45d5d 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -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(); } diff --git a/electron/preload/index.ts b/electron/preload/index.ts index 0c89d17d2..2c8c0b65f 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -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); diff --git a/src/types/electron.d.ts b/src/types/electron.d.ts index e1319bac5..b46ab6c05 100644 --- a/src/types/electron.d.ts +++ b/src/types/electron.d.ts @@ -45,8 +45,7 @@ interface ElectronAPI { envRemove: (email: string, key: string) => Promise; getEnvPath: (email: string) => Promise; 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;