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