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

Function restartSidecarAndReload

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

Source from the content-addressed store, hash-verified

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