()
| 667 | }; |
| 668 | |
| 669 | const restartSidecarAndReload = async (): Promise<DesktopServerConnection> => { |
| 670 | // A supervised daemon owns its own process lifetime. Re-installing the unit |
| 671 | // rewrites settings such as the configured port, then launchd restarts it. |
| 672 | if (connection?.supervisedDaemon) { |
| 673 | const port = getServerSettings().port; |
| 674 | await installSupervisedService({ |
| 675 | port, |
| 676 | dataDir: DESKTOP_DATA_DIR, |
| 677 | }); |
| 678 | const next = await waitForSupervisedAttach(30_000, { port }); |
| 679 | if (!next) { |
| 680 | // oxlint-disable-next-line executor/no-error-constructor, executor/no-try-catch-or-throw -- boundary: surfaces to renderer as a rejected IPC call |
| 681 | throw new Error("Supervised daemon failed to restart — see Settings"); |
| 682 | } |
| 683 | connection = next; |
| 684 | installBearerAuthHeader(next.baseUrl, next.authToken); |
| 685 | const window = liveMainWindow(); |
| 686 | if (window) await window.loadURL(webUrlForConnection(next)); |
| 687 | return toDesktopServerConnection(next); |
| 688 | } |
| 689 | if (connection) { |
| 690 | await stopConnection(connection); |
| 691 | connection = null; |
| 692 | } |
| 693 | const next = await startWithCurrentSettings(); |
| 694 | if (!next) { |
| 695 | // oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: surfaces to renderer as a rejected IPC call |
| 696 | throw new Error("Sidecar failed to restart — see Settings"); |
| 697 | } |
| 698 | connection = next; |
| 699 | // A restart can adopt a daemon that already owns the data dir (the |
| 700 | // attach-on-conflict fallback). An adopted daemon has no child process, so |
| 701 | // onUnexpectedSidecarExit can't see it die — watch it with the supervised |
| 702 | // monitor instead. A freshly spawned sidecar keeps the child-exit path. |
| 703 | if (next.supervisedDaemon) armSupervisedMonitor(); |
| 704 | else stopSupervisedMonitor(); |
| 705 | installBearerAuthHeader(next.baseUrl, next.authToken); |
| 706 | const window = liveMainWindow(); |
| 707 | if (window) await window.loadURL(webUrlForConnection(next)); |
| 708 | return toDesktopServerConnection(next); |
| 709 | }; |
| 710 | |
| 711 | // The renderer's connection carries NO auth: the main process injects the |
| 712 | // bearer header at the session layer (installBearerAuthHeader), so the token |
no test coverage detected