MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / restartSidecarAndReload

Function restartSidecarAndReload

apps/desktop/src/main/index.ts:627–667  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

625};
626
627const restartSidecarAndReload = async (): Promise<DesktopServerConnection> => {
628 // A supervised daemon owns its own process lifetime. Re-installing the unit
629 // rewrites settings such as the configured port, then launchd restarts it.
630 if (connection?.supervisedDaemon) {
631 const port = getServerSettings().port;
632 await installSupervisedService({
633 port,
634 dataDir: DESKTOP_DATA_DIR,
635 });
636 const next = await waitForSupervisedAttach(30_000, { port });
637 if (!next) {
638 // oxlint-disable-next-line executor/no-error-constructor, executor/no-try-catch-or-throw -- boundary: surfaces to renderer as a rejected IPC call
639 throw new Error("Supervised daemon failed to restart — see Settings");
640 }
641 connection = next;
642 installBearerAuthHeader(next.baseUrl, next.authToken);
643 const window = liveMainWindow();
644 if (window) await window.loadURL(webUrlForConnection(next));
645 return toDesktopServerConnection(next);
646 }
647 if (connection) {
648 await stopConnection(connection);
649 connection = null;
650 }
651 const next = await startWithCurrentSettings();
652 if (!next) {
653 // oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: surfaces to renderer as a rejected IPC call
654 throw new Error("Sidecar failed to restart — see Settings");
655 }
656 connection = next;
657 // A restart can adopt a daemon that already owns the data dir (the
658 // attach-on-conflict fallback). An adopted daemon has no child process, so
659 // onUnexpectedSidecarExit can't see it die — watch it with the supervised
660 // monitor instead. A freshly spawned sidecar keeps the child-exit path.
661 if (next.supervisedDaemon) armSupervisedMonitor();
662 else stopSupervisedMonitor();
663 installBearerAuthHeader(next.baseUrl, next.authToken);
664 const window = liveMainWindow();
665 if (window) await window.loadURL(webUrlForConnection(next));
666 return toDesktopServerConnection(next);
667};
668
669// The renderer's connection carries NO auth: the main process injects the
670// bearer header at the session layer (installBearerAuthHeader), so the token

Callers 1

registerIpcHandlersFunction · 0.85

Calls 11

getServerSettingsFunction · 0.90
installSupervisedServiceFunction · 0.90
waitForSupervisedAttachFunction · 0.85
installBearerAuthHeaderFunction · 0.85
liveMainWindowFunction · 0.85
webUrlForConnectionFunction · 0.85
stopConnectionFunction · 0.85
startWithCurrentSettingsFunction · 0.85
armSupervisedMonitorFunction · 0.85
stopSupervisedMonitorFunction · 0.85

Tested by

no test coverage detected