| 176 | } |
| 177 | |
| 178 | private async waitUntilReady(maxRetries = 180, delayMs = 500): Promise<void> { |
| 179 | for (let i = 0; i < maxRetries; i++) { |
| 180 | if (!this.process) throw new Error('FastAPI process exited unexpectedly during startup') |
| 181 | try { |
| 182 | await axios.get(`${API_BASE_URL}/health`, { timeout: 2000 }) |
| 183 | this.ready = true |
| 184 | console.log('[PythonBridge] FastAPI is ready') |
| 185 | return |
| 186 | } catch { |
| 187 | await new Promise((r) => setTimeout(r, delayMs)) |
| 188 | } |
| 189 | } |
| 190 | throw new Error('FastAPI did not start in time') |
| 191 | } |
| 192 | |
| 193 | private resolvePythonExecutable(): string { |
| 194 | const userData = app.getPath('userData') |