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

Function registerIpcHandlers

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

Source from the content-addressed store, hash-verified

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