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

Function restartSidecarAndReload

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

Source from the content-addressed store, hash-verified

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