This commit is contained in:
puzhen 2025-11-20 23:17:37 +08:00
parent 5cff23d1fe
commit bac5652082

View file

@ -677,116 +677,4 @@ export async function installDependencies(version: string): Promise<PromiseRetur
resolve({ message: "Both default and mirror install failed", success: false })
}
})
}
let dependencyInstallationDetected = false;
let installationNotificationSent = false;
/**
* @deprecated This function is no longer called and should not be used.
*
* REASON FOR DEPRECATION:
* - Keyword-based detection causes false positives when backend logs contain
* words like "Installing", "Updating", "Syncing" during normal operation
* - Checking file system on every backend log line is inefficient
* - Installation is now only handled through explicit installation flow in createWindow
*
* This function is kept for backwards compatibility but is not invoked anywhere.
*/
export function detectInstallationLogs(msg:string) {
// CRITICAL FIX: Use file system to check if installation is complete
// Don't rely on module variables as they can be reset during hot reload
// Check if dependencies are already installed
const isAlreadyInstalled = fs.existsSync(installedLockPath);
// If installed lock file exists, dependencies are already installed
// Skip all detection to avoid false positives
if (isAlreadyInstalled) {
// Dependencies are already installed, skip detection entirely
return;
}
// Also skip if notification was already sent (in current session)
if (installationNotificationSent) {
return;
}
// Check for UV dependency installation patterns
const installPatterns = [
"Resolved", // UV resolving dependencies
"Downloaded", // UV downloading packages
"Installing", // UV installing packages
"Built", // UV building packages
"Prepared", // UV preparing virtual environment
"Syncing", // UV sync process
"Creating virtualenv", // Virtual environment creation
"Updating", // UV updating packages
"× No solution found when resolving dependencies", // Dependency resolution issues
"Audited" // UV auditing dependencies
];
// Detect if UV is installing dependencies
if (!dependencyInstallationDetected && installPatterns.some(pattern =>
msg.includes(pattern) && !msg.includes("Uvicorn running on")
)) {
dependencyInstallationDetected = true;
log.info('[BACKEND STARTUP] UV dependency installation detected during uvicorn startup');
// Create installing lock file to maintain consistency with install-deps.ts
InstallLogs.setLockPath();
log.info('[BACKEND STARTUP] Created uv_installing.lock file');
// Notify frontend that installation has started (only once)
if (!installationNotificationSent) {
installationNotificationSent = true;
const notificationSent = safeMainWindowSend('install-dependencies-start');
if (notificationSent) {
log.info('[BACKEND STARTUP] Notified frontend of dependency installation start');
} else {
log.warn('[BACKEND STARTUP] Failed to notify frontend of dependency installation start');
}
}
}
// Send installation logs to frontend if installation was detected
if (dependencyInstallationDetected && !msg.includes("Uvicorn running on")) {
safeMainWindowSend('install-dependencies-log', {
type: msg.toLowerCase().includes("error") || msg.toLowerCase().includes("traceback") ? 'stderr' : 'stdout',
data: msg
});
}
// Check if installation is complete (uvicorn starts successfully)
if (dependencyInstallationDetected && msg.includes("Uvicorn running on")) {
log.info('[BACKEND STARTUP] UV dependency installation completed, uvicorn started successfully');
// Clean up installing lock and create installed lock
InstallLogs.cleanLockPath();
fs.writeFileSync(installedLockPath, '');
log.info('[BACKEND STARTUP] Created uv_installed.lock file');
safeMainWindowSend('install-dependencies-complete', {
success: true,
message: 'Dependencies installed successfully during backend startup'
});
}
// Handle installation failures
if (dependencyInstallationDetected && (
msg.toLowerCase().includes("failed to resolve dependencies") ||
msg.toLowerCase().includes("installation failed") ||
msg.includes("× No solution found when resolving dependencies")
)) {
log.error('[BACKEND STARTUP] UV dependency installation failed');
// Clean up installing lock file
InstallLogs.cleanLockPath();
log.info('[BACKEND STARTUP] Cleaned up uv_installing.lock file after failure');
safeMainWindowSend('install-dependencies-complete', {
success: false,
error: 'Dependency installation failed during backend startup'
});
}
}