wip
This commit is contained in:
@@ -354,14 +354,40 @@ export class DIContainer {
|
||||
const playwrightAdapter = this.browserAutomation as PlaywrightAutomationAdapter;
|
||||
const result = await playwrightAdapter.connect();
|
||||
if (!result.success) {
|
||||
this.logger.error('Automation connection failed', new Error(result.error || 'Unknown error'), { mode: this.automationMode });
|
||||
this.logger.error(
|
||||
'Automation connection failed',
|
||||
new Error(result.error || 'Unknown error'),
|
||||
{ mode: this.automationMode }
|
||||
);
|
||||
return { success: false, error: result.error };
|
||||
}
|
||||
this.logger.info('Automation connection established', { mode: this.automationMode, adapter: 'Playwright' });
|
||||
|
||||
const isConnected = playwrightAdapter.isConnected();
|
||||
const page = playwrightAdapter.getPage();
|
||||
|
||||
if (!isConnected || !page) {
|
||||
const errorMsg = 'Browser not connected';
|
||||
this.logger.error(
|
||||
'Automation connection reported success but has no usable page',
|
||||
new Error(errorMsg),
|
||||
{ mode: this.automationMode, isConnected, hasPage: !!page }
|
||||
);
|
||||
return { success: false, error: errorMsg };
|
||||
}
|
||||
|
||||
this.logger.info('Automation connection established', {
|
||||
mode: this.automationMode,
|
||||
adapter: 'Playwright'
|
||||
});
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : 'Failed to initialize Playwright';
|
||||
this.logger.error('Automation connection failed', error instanceof Error ? error : new Error(errorMsg), { mode: this.automationMode });
|
||||
const errorMsg =
|
||||
error instanceof Error ? error.message : 'Failed to initialize Playwright';
|
||||
this.logger.error(
|
||||
'Automation connection failed',
|
||||
error instanceof Error ? error : new Error(errorMsg),
|
||||
{ mode: this.automationMode }
|
||||
);
|
||||
return {
|
||||
success: false,
|
||||
error: errorMsg
|
||||
|
||||
@@ -11,9 +11,6 @@ let lifecycleSubscribed = false;
|
||||
|
||||
export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
const container = DIContainer.getInstance();
|
||||
const startAutomationUseCase = container.getStartAutomationUseCase();
|
||||
const sessionRepository = container.getSessionRepository();
|
||||
const automationEngine = container.getAutomationEngine();
|
||||
const logger = container.getLogger();
|
||||
|
||||
// Setup checkout confirmation adapter and wire it into the container
|
||||
@@ -156,15 +153,18 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
|
||||
ipcMain.handle('start-automation', async (_event: IpcMainInvokeEvent, config: HostedSessionConfig) => {
|
||||
try {
|
||||
const container = DIContainer.getInstance();
|
||||
const startAutomationUseCase = container.getStartAutomationUseCase();
|
||||
const sessionRepository = container.getSessionRepository();
|
||||
const automationEngine = container.getAutomationEngine();
|
||||
|
||||
logger.info('Starting automation', { sessionName: config.sessionName });
|
||||
|
||||
// Clear any existing progress interval
|
||||
if (progressMonitorInterval) {
|
||||
clearInterval(progressMonitorInterval);
|
||||
progressMonitorInterval = null;
|
||||
}
|
||||
|
||||
// Connect to browser first (required for dev mode)
|
||||
const connectionResult = await container.initializeBrowserConnection();
|
||||
if (!connectionResult.success) {
|
||||
logger.error('Browser connection failed', undefined, { errorMessage: connectionResult.error });
|
||||
@@ -172,7 +172,6 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
}
|
||||
logger.info('Browser connection established');
|
||||
|
||||
// Check authentication before starting automation (production/development mode only)
|
||||
const checkAuthUseCase = container.getCheckAuthenticationUseCase();
|
||||
if (checkAuthUseCase) {
|
||||
const authResult = await checkAuthUseCase.execute();
|
||||
@@ -199,14 +198,14 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
const session = await sessionRepository.findById(result.sessionId);
|
||||
|
||||
if (session) {
|
||||
// Start the automation by executing step 1
|
||||
logger.info('Executing step 1');
|
||||
await automationEngine.executeStep(StepId.create(1), config);
|
||||
}
|
||||
|
||||
// Set up progress monitoring
|
||||
progressMonitorInterval = setInterval(async () => {
|
||||
const updatedSession = await sessionRepository.findById(result.sessionId);
|
||||
const containerForProgress = DIContainer.getInstance();
|
||||
const repoForProgress = containerForProgress.getSessionRepository();
|
||||
const updatedSession = await repoForProgress.findById(result.sessionId);
|
||||
if (!updatedSession) {
|
||||
if (progressMonitorInterval) {
|
||||
clearInterval(progressMonitorInterval);
|
||||
@@ -250,6 +249,8 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
});
|
||||
|
||||
ipcMain.handle('get-session-status', async (_event: IpcMainInvokeEvent, sessionId: string) => {
|
||||
const container = DIContainer.getInstance();
|
||||
const sessionRepository = container.getSessionRepository();
|
||||
const session = await sessionRepository.findById(sessionId);
|
||||
if (!session) {
|
||||
return { found: false };
|
||||
@@ -275,20 +276,21 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
|
||||
ipcMain.handle('stop-automation', async (_event: IpcMainInvokeEvent, sessionId: string) => {
|
||||
try {
|
||||
const container = DIContainer.getInstance();
|
||||
const automationEngine = container.getAutomationEngine();
|
||||
const sessionRepository = container.getSessionRepository();
|
||||
|
||||
logger.info('Stopping automation', { sessionId });
|
||||
|
||||
// Clear progress monitoring interval
|
||||
if (progressMonitorInterval) {
|
||||
clearInterval(progressMonitorInterval);
|
||||
progressMonitorInterval = null;
|
||||
logger.info('Progress monitor cleared');
|
||||
}
|
||||
|
||||
// Stop the automation engine interval
|
||||
automationEngine.stopAutomation();
|
||||
logger.info('Automation engine stopped');
|
||||
|
||||
// Update session state to failed with user stop reason
|
||||
const session = await sessionRepository.findById(sessionId);
|
||||
if (session) {
|
||||
session.fail('User stopped automation');
|
||||
|
||||
Reference in New Issue
Block a user