wip
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { ipcMain } from 'electron';
|
||||
import type { BrowserWindow, IpcMainInvokeEvent } from 'electron';
|
||||
import { DIContainer } from './di-container';
|
||||
import type { HostedSessionConfig } from '@/packages/domain/entities/HostedSessionConfig';
|
||||
import { StepId } from '@/packages/domain/value-objects/StepId';
|
||||
import { AuthenticationState } from '@/packages/domain/value-objects/AuthenticationState';
|
||||
import { ElectronCheckoutConfirmationAdapter } from '@/packages/infrastructure/adapters/ipc/ElectronCheckoutConfirmationAdapter';
|
||||
import type { HostedSessionConfig } from 'packages/automation/domain/types/HostedSessionConfig';
|
||||
import { StepId } from 'packages/automation/domain/value-objects/StepId';
|
||||
import { AuthenticationState } from 'packages/automation/domain/value-objects/AuthenticationState';
|
||||
import { ElectronCheckoutConfirmationAdapter } from 'packages/automation/infrastructure/adapters/ipc/ElectronCheckoutConfirmationAdapter';
|
||||
import type { OverlayAction } from 'packages/automation/application/ports/OverlaySyncPort';
|
||||
import type { IAutomationLifecycleEmitter } from 'packages/automation/infrastructure/adapters/IAutomationLifecycleEmitter';
|
||||
|
||||
let progressMonitorInterval: NodeJS.Timeout | null = null;
|
||||
let lifecycleSubscribed = false;
|
||||
@@ -95,8 +97,8 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
}
|
||||
|
||||
// Call confirmLoginComplete on the adapter if it exists
|
||||
if ('confirmLoginComplete' in authService) {
|
||||
const result = await (authService as any).confirmLoginComplete();
|
||||
if ('confirmLoginComplete' in authService && typeof authService.confirmLoginComplete === 'function') {
|
||||
const result = await authService.confirmLoginComplete();
|
||||
if (result.isErr()) {
|
||||
logger.error('Confirm login failed', result.unwrapErr());
|
||||
return { success: false, error: result.unwrapErr().message };
|
||||
@@ -334,7 +336,7 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
// Ensure runtime automation wiring reflects the new browser mode
|
||||
if ('refreshBrowserAutomation' in container) {
|
||||
// Call method to refresh adapters/use-cases that depend on browser mode
|
||||
(container as any).refreshBrowserAutomation();
|
||||
container.refreshBrowserAutomation();
|
||||
}
|
||||
logger.info('Browser mode updated', { mode });
|
||||
return { success: true, mode };
|
||||
@@ -349,9 +351,9 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
});
|
||||
|
||||
// Handle overlay action requests from renderer and forward to the OverlaySyncService
|
||||
ipcMain.handle('overlay-action-request', async (_event: IpcMainInvokeEvent, action: any) => {
|
||||
ipcMain.handle('overlay-action-request', async (_event: IpcMainInvokeEvent, action: OverlayAction) => {
|
||||
try {
|
||||
const overlayPort = (container as any).getOverlaySyncPort ? container.getOverlaySyncPort() : null;
|
||||
const overlayPort = 'getOverlaySyncPort' in container ? container.getOverlaySyncPort() : null;
|
||||
if (!overlayPort) {
|
||||
logger.warn('OverlaySyncPort not available');
|
||||
return { id: action?.id ?? 'unknown', status: 'failed', reason: 'OverlaySyncPort not available' };
|
||||
@@ -361,16 +363,20 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
} catch (e) {
|
||||
const err = e instanceof Error ? e : new Error(String(e));
|
||||
logger.error('Overlay action request failed', err);
|
||||
return { id: action?.id ?? 'unknown', status: 'failed', reason: err.message };
|
||||
const id = typeof action === 'object' && action !== null && 'id' in action
|
||||
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(action as { id?: string }).id ?? 'unknown'
|
||||
: 'unknown';
|
||||
return { id, status: 'failed', reason: err.message };
|
||||
}
|
||||
});
|
||||
|
||||
// Subscribe to automation adapter lifecycle events and relay to renderer
|
||||
try {
|
||||
if (!lifecycleSubscribed) {
|
||||
const browserAutomation = container.getBrowserAutomation() as any;
|
||||
if (browserAutomation && typeof browserAutomation.onLifecycle === 'function') {
|
||||
browserAutomation.onLifecycle((ev: any) => {
|
||||
const lifecycleEmitter = container.getBrowserAutomation() as unknown as IAutomationLifecycleEmitter;
|
||||
if (typeof lifecycleEmitter.onLifecycle === 'function') {
|
||||
lifecycleEmitter.onLifecycle((ev) => {
|
||||
try {
|
||||
if (mainWindow && mainWindow.webContents) {
|
||||
mainWindow.webContents.send('automation-event', ev);
|
||||
|
||||
Reference in New Issue
Block a user