Task 13: Create Automation Controller with IPC handlers
Implements the automation controller with three IPC handlers for automation operations: - automation:clean - Returns NOT_IMPLEMENTED (TODO: later phase) - automation:extract - Returns NOT_IMPLEMENTED (TODO: later phase) - automation:stop - Returns success (TODO: task cancellation in later phase) Each handler: - Logs requests via LoggerService - Returns structured AutomationResponse with success/error fields - Uses proper TypeScript typing Updates: - Created src/main/controllers/automation.controller.ts - Updated src/main/index.ts to register automation handlers - Updated src/main/models/ipc.types.ts with AutomationResponse interface Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
84
src/main/controllers/automation.controller.ts
Normal file
84
src/main/controllers/automation.controller.ts
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import { ipcMain } from 'electron';
|
||||||
|
import { LoggerService } from '../services/logger.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response structure for automation IPC handlers
|
||||||
|
*/
|
||||||
|
interface AutomationResponse {
|
||||||
|
success: boolean;
|
||||||
|
error?: {
|
||||||
|
code: string;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error codes for automation operations
|
||||||
|
*/
|
||||||
|
enum AutomationErrorCode {
|
||||||
|
NOT_IMPLEMENTED = 'NOT_IMPLEMENTED',
|
||||||
|
OPERATION_FAILED = 'OPERATION_FAILED',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register IPC handlers for automation operations
|
||||||
|
*
|
||||||
|
* This function sets up the following handlers:
|
||||||
|
* - automation:clean: Clean automation (TODO: implement in later phase)
|
||||||
|
* - automation:extract: Extract automation (TODO: implement in later phase)
|
||||||
|
* - automation:stop: Stop automation (TODO: implement task cancellation)
|
||||||
|
*/
|
||||||
|
export function registerAutomationHandlers(): void {
|
||||||
|
/**
|
||||||
|
* Handler for automation:clean
|
||||||
|
* Currently returns NOT_IMPLEMENTED error
|
||||||
|
* Full implementation will be added in a later phase
|
||||||
|
*/
|
||||||
|
ipcMain.handle('automation:clean', async (): Promise<AutomationResponse> => {
|
||||||
|
LoggerService.info('automation:clean request received');
|
||||||
|
|
||||||
|
// TODO: Implement clean automation logic in later phase
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: {
|
||||||
|
code: AutomationErrorCode.NOT_IMPLEMENTED,
|
||||||
|
message: 'Clean automation not yet implemented',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for automation:extract
|
||||||
|
* Currently returns NOT_IMPLEMENTED error
|
||||||
|
* Full implementation will be added in a later phase
|
||||||
|
*/
|
||||||
|
ipcMain.handle('automation:extract', async (): Promise<AutomationResponse> => {
|
||||||
|
LoggerService.info('automation:extract request received');
|
||||||
|
|
||||||
|
// TODO: Implement extract automation logic in later phase
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: {
|
||||||
|
code: AutomationErrorCode.NOT_IMPLEMENTED,
|
||||||
|
message: 'Extract automation not yet implemented',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for automation:stop
|
||||||
|
* Currently returns success without actual cancellation
|
||||||
|
* Full task cancellation implementation will be added in a later phase
|
||||||
|
*/
|
||||||
|
ipcMain.handle('automation:stop', async (): Promise<AutomationResponse> => {
|
||||||
|
LoggerService.info('automation:stop request received');
|
||||||
|
|
||||||
|
// TODO: Implement task cancellation logic in later phase
|
||||||
|
// For now, just acknowledge the stop request
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
LoggerService.info('Automation IPC handlers registered successfully');
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import { app, shell, BrowserWindow, ipcMain } from 'electron'
|
|||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||||
import icon from '../../resources/icon.png?asset'
|
import icon from '../../resources/icon.png?asset'
|
||||||
|
import { registerAutomationHandlers } from './controllers/automation.controller'
|
||||||
|
|
||||||
function createWindow(): void {
|
function createWindow(): void {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
@@ -53,8 +54,9 @@ app.whenReady().then(() => {
|
|||||||
ipcMain.on('ping', () => console.log('pong'))
|
ipcMain.on('ping', () => console.log('pong'))
|
||||||
|
|
||||||
// IPC Handler Registration
|
// IPC Handler Registration
|
||||||
|
registerAutomationHandlers()
|
||||||
// TODO: Register IPC handlers for:
|
// TODO: Register IPC handlers for:
|
||||||
// - automation:clean, automation:extract, automation:stop, automation:progress
|
// - automation:progress
|
||||||
// - database:query-production-orders, database:query-materials-to-delete
|
// - database:query-production-orders, database:query-materials-to-delete
|
||||||
// - auth:login, auth:logout
|
// - auth:login, auth:logout
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Response structure for automation IPC handlers
|
||||||
|
*/
|
||||||
|
export interface AutomationResponse {
|
||||||
|
success: boolean;
|
||||||
|
error?: {
|
||||||
|
code: string;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export interface IPCChannels {
|
export interface IPCChannels {
|
||||||
'automation:clean': any;
|
'automation:clean': () => Promise<AutomationResponse>;
|
||||||
'automation:extract': any;
|
'automation:extract': () => Promise<AutomationResponse>;
|
||||||
'automation:stop': any;
|
'automation:stop': () => Promise<AutomationResponse>;
|
||||||
'automation:progress': any;
|
'automation:progress': any;
|
||||||
'database:query-production-orders': any;
|
'database:query-production-orders': any;
|
||||||
'database:query-materials-to-delete': any;
|
'database:query-materials-to-delete': any;
|
||||||
|
|||||||
Reference in New Issue
Block a user