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

Function registerIpcHandlers

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

Source from the content-addressed store, hash-verified

727});
728
729const registerIpcHandlers = () => {
730 ipcMain.handle("executor:server:connection", (): DesktopServerConnection | null =>
731 connection ? toDesktopServerConnection(connection) : null,
732 );
733 // The bearer token, exposed only for the "Connect an agent" install command
734 // (an external agent needs it in plaintext). The renderer's own requests
735 // never use it — the header is injected at the session layer.
736 ipcMain.handle("executor:server:auth-token", (): string | null => connection?.authToken ?? null);
737 ipcMain.handle("executor:settings:get", (): DesktopServerSettings => getServerSettings());
738 ipcMain.handle(
739 "executor:settings:update",
740 (_evt, patch: Partial<DesktopServerSettings>): DesktopServerSettings =>
741 updateServerSettings(patch),
742 );
743 // Rotate the bearer token (auth.json). A supervised daemon must be restarted
744 // so it re-reads auth.json at boot, then re-attached; a managed sidecar is
745 // restarted in-process. Either way the webview header is re-injected.
746 ipcMain.handle("executor:server:rotate-token", async (): Promise<DesktopServerConnection> => {
747 rotateServerToken();
748 if (connection?.supervisedDaemon) {
749 const previous = connection;
750 await restartSupervisedService();
751 const active = (await waitForSupervisedAttach(15_000)) ?? previous;
752 connection = active;
753 installBearerAuthHeader(active.baseUrl, active.authToken);
754 const window = liveMainWindow();
755 if (window) await window.loadURL(webUrlForConnection(active));
756 return toDesktopServerConnection(active);
757 }
758 return restartSidecarAndReload();
759 });
760 // Background-service control surface — lets a Settings toggle enable or
761 // disable the supervised daemon. Disabling tears down the service and falls
762 // back to a managed sidecar on next launch.
763 ipcMain.handle("executor:service:status", () => supervisedServiceStatus());
764 ipcMain.handle(
765 "executor:service:set-enabled",
766 async (_evt, enabled: unknown): Promise<boolean> => {
767 if (typeof enabled !== "boolean") return false;
768 if (enabled) {
769 const settings = getServerSettings();
770 await installSupervisedService({
771 port: settings.port,
772 dataDir: DESKTOP_DATA_DIR,
773 });
774 const next = await waitForSupervisedAttach(15_000);
775 if (next) {
776 if (connection && !connection.supervisedDaemon) await stopConnection(connection);
777 connection = next;
778 armSupervisedMonitor();
779 installBearerAuthHeader(next.baseUrl, next.authToken);
780 const window = liveMainWindow();
781 if (window) await window.loadURL(webUrlForConnection(next));
782 }
783 return true;
784 }
785 stopSupervisedMonitor();
786 await uninstallSupervisedService(DESKTOP_DATA_DIR);

Callers 1

bootFunction · 0.85

Calls 15

getServerSettingsFunction · 0.90
updateServerSettingsFunction · 0.90
rotateServerTokenFunction · 0.90
restartSupervisedServiceFunction · 0.90
supervisedServiceStatusFunction · 0.90
installSupervisedServiceFunction · 0.90
getServerProfilesFunction · 0.90
setServerProfilesFunction · 0.90
exportDiagnosticsFunction · 0.90
getCrashReportingConfigFunction · 0.90
confirmResetStateFunction · 0.90

Tested by

no test coverage detected