()
| 613 | }); |
| 614 | |
| 615 | const registerIpcHandlers = () => { |
| 616 | ipcMain.handle("executor:server:connection", (): DesktopServerConnection | null => |
| 617 | connection ? toDesktopServerConnection(connection) : null, |
| 618 | ); |
| 619 | // The bearer token, exposed only for the "Connect an agent" install command |
| 620 | // (an external agent needs it in plaintext). The renderer's own requests |
| 621 | // never use it — the header is injected at the session layer. |
| 622 | ipcMain.handle("executor:server:auth-token", (): string | null => connection?.authToken ?? null); |
| 623 | ipcMain.handle("executor:settings:get", (): DesktopServerSettings => getServerSettings()); |
| 624 | ipcMain.handle( |
| 625 | "executor:settings:update", |
| 626 | (_evt, patch: Partial<DesktopServerSettings>): DesktopServerSettings => |
| 627 | updateServerSettings(patch), |
| 628 | ); |
| 629 | // Rotate the bearer token (auth.json). A supervised daemon must be restarted |
| 630 | // so it re-reads auth.json at boot, then re-attached; a managed sidecar is |
| 631 | // restarted in-process. Either way the webview header is re-injected. |
| 632 | ipcMain.handle("executor:server:rotate-token", async (): Promise<DesktopServerConnection> => { |
| 633 | rotateServerToken(); |
| 634 | if (connection?.supervisedDaemon) { |
| 635 | const previous = connection; |
| 636 | await restartSupervisedService(); |
| 637 | const active = (await waitForSupervisedAttach(15_000)) ?? previous; |
| 638 | connection = active; |
| 639 | installBearerAuthHeader(active.baseUrl, active.authToken); |
| 640 | const window = liveMainWindow(); |
| 641 | if (window) await window.loadURL(webUrlForConnection(active)); |
| 642 | return toDesktopServerConnection(active); |
| 643 | } |
| 644 | return restartSidecarAndReload(); |
| 645 | }); |
| 646 | // Background-service control surface — lets a Settings toggle enable or |
| 647 | // disable the supervised daemon. Disabling tears down the service and falls |
| 648 | // back to a managed sidecar on next launch. |
| 649 | ipcMain.handle("executor:service:status", () => supervisedServiceStatus()); |
| 650 | ipcMain.handle( |
| 651 | "executor:service:set-enabled", |
| 652 | async (_evt, enabled: unknown): Promise<boolean> => { |
| 653 | if (typeof enabled !== "boolean") return false; |
| 654 | if (enabled) { |
| 655 | const settings = getServerSettings(); |
| 656 | await installSupervisedService({ |
| 657 | port: settings.port, |
| 658 | dataDir: DESKTOP_DATA_DIR, |
| 659 | }); |
| 660 | const next = await waitForSupervisedAttach(15_000); |
| 661 | if (next) { |
| 662 | if (connection && !connection.supervisedDaemon) await stopConnection(connection); |
| 663 | connection = next; |
| 664 | armSupervisedMonitor(); |
| 665 | installBearerAuthHeader(next.baseUrl, next.authToken); |
| 666 | const window = liveMainWindow(); |
| 667 | if (window) await window.loadURL(webUrlForConnection(next)); |
| 668 | } |
| 669 | return true; |
| 670 | } |
| 671 | stopSupervisedMonitor(); |
| 672 | await uninstallSupervisedService(DESKTOP_DATA_DIR); |
no test coverage detected