diff --git a/electron/main/install-deps.ts b/electron/main/install-deps.ts index d4205c18e..9c251b629 100644 --- a/electron/main/install-deps.ts +++ b/electron/main/install-deps.ts @@ -151,6 +151,36 @@ const installedLockPath = path.join(backendPath, 'uv_installed.lock') // const proxyArgs = ['--default-index', 'https://pypi.tuna.tsinghua.edu.cn/simple'] const proxyArgs = ['--default-index', 'https://mirrors.aliyun.com/pypi/simple/'] +/** + * Get current installation status by checking lock files + * @returns Object with installation status information + */ +export async function getInstallationStatus(): Promise<{ + isInstalling: boolean; + hasLockFile: boolean; + installedExists: boolean; +}> { + try { + const installingExists = fs.existsSync(installingLockPath); + const installedExists = fs.existsSync(installedLockPath); + + // If installing lock exists, installation is in progress + // If installed lock exists, installation completed previously + return { + isInstalling: installingExists, + hasLockFile: installingExists || installedExists, + installedExists: installedExists + }; + } catch (error) { + console.error('[getInstallationStatus] Error checking installation status:', error); + return { + isInstalling: false, + hasLockFile: false, + installedExists: false + }; + } +} + class InstallLogs { private node_process; diff --git a/electron/preload/index.ts b/electron/preload/index.ts index 2c8c0b65f..d1c5e9e85 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -64,6 +64,7 @@ contextBridge.exposeInMainWorld('electronAPI', { // install dependencies related API checkAndInstallDepsOnUpdate: () => ipcRenderer.invoke('install-dependencies'), checkInstallBrowser: () => ipcRenderer.invoke('check-install-browser'), + getInstallationStatus: () => ipcRenderer.invoke('get-installation-status'), onInstallDependenciesStart: (callback: () => void) => { ipcRenderer.on('install-dependencies-start', callback); }, diff --git a/src/types/electron.d.ts b/src/types/electron.d.ts index b46ab6c05..470529c9e 100644 --- a/src/types/electron.d.ts +++ b/src/types/electron.d.ts @@ -47,6 +47,14 @@ interface ElectronAPI { executeCommand: (command: string,email:string) => Promise<{ success: boolean; stdout?: string; stderr?: string; error?: string }>; checkAndInstallDepsOnUpdate: () => Promise<{ success: boolean; error?: string }>; checkInstallBrowser: () => Promise<{ data:any[] }>; + getInstallationStatus: () => Promise<{ + success: boolean; + isInstalling?: boolean; + hasLockFile?: boolean; + installedExists?: boolean; + timestamp?: number; + error?: string + }>; onInstallDependenciesStart: (callback: () => void) => void; onInstallDependenciesLog: (callback: (data: { type: string; data: string }) => void) => void; onInstallDependenciesComplete: (callback: (data: { success: boolean; code?: number; error?: string }) => void) => void;