(win: BrowserWindow, name: string)
| 303 | } |
| 304 | |
| 305 | function wireWindowRecovery(win: BrowserWindow, name: string) { |
| 306 | let showing = false |
| 307 | const sampler = createUnresponsiveSampler(win, name) |
| 308 | |
| 309 | const handle = async (button: string | undefined, wait: boolean) => { |
| 310 | if (button === "Export Logs") { |
| 311 | const sampling = sampler.stopAndFlush() |
| 312 | await exportDebugLogs().catch((error) => writeLog("main", "failed to export debug logs", { error }, "error")) |
| 313 | if (wait && sampling) sampler.start() |
| 314 | return true |
| 315 | } |
| 316 | if (button === "Relaunch") { |
| 317 | sampler.stopAndFlush() |
| 318 | relaunchHandler() |
| 319 | return false |
| 320 | } |
| 321 | if (button === "Quit") { |
| 322 | sampler.stopAndFlush() |
| 323 | app.quit() |
| 324 | } |
| 325 | return false |
| 326 | } |
| 327 | |
| 328 | const show = async (message: string, detail: string, wait: boolean) => { |
| 329 | if (showing || win.isDestroyed()) return |
| 330 | showing = true |
| 331 | try { |
| 332 | while (!win.isDestroyed()) { |
| 333 | const buttons = wait ? ["Relaunch", "Export Logs", "Keep Waiting"] : ["Relaunch", "Export Logs", "Quit"] |
| 334 | const result = await dialog.showMessageBox(win, { |
| 335 | type: "warning", |
| 336 | buttons, |
| 337 | defaultId: 0, |
| 338 | cancelId: 2, |
| 339 | message, |
| 340 | detail, |
| 341 | }) |
| 342 | if (await handle(buttons[result.response], wait)) continue |
| 343 | return |
| 344 | } |
| 345 | } finally { |
| 346 | showing = false |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | const failed = ( |
| 351 | event: string, |
| 352 | errorCode: number, |
| 353 | errorDescription: string, |
| 354 | validatedURL: string, |
| 355 | isMainFrame: boolean, |
| 356 | ) => { |
| 357 | writeLog( |
| 358 | "window", |
| 359 | "renderer load failed", |
| 360 | { |
| 361 | window: name, |
| 362 | event, |
no test coverage detected