agent-ecosystem/src/main/ipc/handlers.ts
matt 5bf41c6ed8 refactor(02-02): main/index.ts to use ServiceContextRegistry
- Replace global service variables with ServiceContextRegistry
- Create local context at startup with LocalFileSystemProvider
- Register local context in registry and start it
- Wire file watcher events via wireFileWatcherEvents helper
- Export onContextSwitched callback for SSH handler
- Remove handleModeSwitch callback (replaced by registry pattern)
- Update initializeIpcHandlers to accept registry instead of individual services
- Remove reinitializeServiceHandlers entirely from handlers.ts
- ServiceContextRegistry pattern eliminates need for service recreation on mode switch
2026-02-12 01:04:20 +00:00

98 lines
3.1 KiB
TypeScript

/**
* IPC Handlers - Orchestrates domain-specific handler modules.
*
* This module initializes and registers all IPC handlers from domain modules:
* - projects.ts: Project listing and repository groups
* - sessions.ts: Session operations and pagination
* - search.ts: Session search functionality
* - subagents.ts: Subagent detail retrieval
* - validation.ts: Path validation and scroll handling
* - utility.ts: Shell operations and file reading
* - notifications.ts: Notification management
* - config.ts: App configuration
* - ssh.ts: SSH connection management
*/
import { createLogger } from '@shared/utils/logger';
import { ipcMain } from 'electron';
import { registerConfigHandlers, removeConfigHandlers } from './config';
const logger = createLogger('IPC:handlers');
import { registerNotificationHandlers, removeNotificationHandlers } from './notifications';
import {
initializeProjectHandlers,
registerProjectHandlers,
removeProjectHandlers,
} from './projects';
import { initializeSearchHandlers, registerSearchHandlers, removeSearchHandlers } from './search';
import {
initializeSessionHandlers,
registerSessionHandlers,
removeSessionHandlers,
} from './sessions';
import { initializeSshHandlers, registerSshHandlers, removeSshHandlers } from './ssh';
import {
initializeSubagentHandlers,
registerSubagentHandlers,
removeSubagentHandlers,
} from './subagents';
import {
initializeUpdaterHandlers,
registerUpdaterHandlers,
removeUpdaterHandlers,
} from './updater';
import { registerUtilityHandlers, removeUtilityHandlers } from './utility';
import { registerValidationHandlers, removeValidationHandlers } from './validation';
import type { ServiceContextRegistry, SshConnectionManager, UpdaterService } from '../services';
/**
* Initializes IPC handlers with service registry.
*/
export function initializeIpcHandlers(
registry: ServiceContextRegistry,
updater: UpdaterService,
sshManager: SshConnectionManager
): void {
// Initialize domain handlers with registry
initializeProjectHandlers(registry);
initializeSessionHandlers(registry);
initializeSearchHandlers(registry);
initializeSubagentHandlers(registry);
initializeUpdaterHandlers(updater);
initializeSshHandlers(sshManager, registry);
// Register all handlers
registerProjectHandlers(ipcMain);
registerSessionHandlers(ipcMain);
registerSearchHandlers(ipcMain);
registerSubagentHandlers(ipcMain);
registerValidationHandlers(ipcMain);
registerUtilityHandlers(ipcMain);
registerNotificationHandlers(ipcMain);
registerConfigHandlers(ipcMain);
registerUpdaterHandlers(ipcMain);
registerSshHandlers(ipcMain);
logger.info('All handlers registered');
}
/**
* Removes all IPC handlers.
* Should be called when shutting down.
*/
export function removeIpcHandlers(): void {
removeProjectHandlers(ipcMain);
removeSessionHandlers(ipcMain);
removeSearchHandlers(ipcMain);
removeSubagentHandlers(ipcMain);
removeValidationHandlers(ipcMain);
removeUtilityHandlers(ipcMain);
removeNotificationHandlers(ipcMain);
removeConfigHandlers(ipcMain);
removeUpdaterHandlers(ipcMain);
removeSshHandlers(ipcMain);
logger.info('All handlers removed');
}