feat(overlay-sync): wire OverlaySyncService into DI, IPC and renderer gating
This commit is contained in:
@@ -7,6 +7,7 @@ import { AuthenticationState } from '@/packages/domain/value-objects/Authenticat
|
||||
import { ElectronCheckoutConfirmationAdapter } from '@/packages/infrastructure/adapters/ipc/ElectronCheckoutConfirmationAdapter';
|
||||
|
||||
let progressMonitorInterval: NodeJS.Timeout | null = null;
|
||||
let lifecycleSubscribed = false;
|
||||
|
||||
export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
const container = DIContainer.getInstance();
|
||||
@@ -326,6 +327,11 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
const loader = container.getBrowserModeConfigLoader();
|
||||
loader.setDevelopmentMode(mode);
|
||||
// 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();
|
||||
}
|
||||
logger.info('Browser mode updated', { mode });
|
||||
return { success: true, mode };
|
||||
}
|
||||
@@ -337,4 +343,44 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
return { success: false, error: err.message };
|
||||
}
|
||||
});
|
||||
|
||||
// Handle overlay action requests from renderer and forward to the OverlaySyncService
|
||||
ipcMain.handle('overlay-action-request', async (_event: IpcMainInvokeEvent, action: any) => {
|
||||
try {
|
||||
const overlayPort = (container as any).getOverlaySyncPort ? container.getOverlaySyncPort() : null;
|
||||
if (!overlayPort) {
|
||||
logger.warn('OverlaySyncPort not available');
|
||||
return { id: action?.id ?? 'unknown', status: 'failed', reason: 'OverlaySyncPort not available' };
|
||||
}
|
||||
const ack = await overlayPort.startAction(action);
|
||||
return ack;
|
||||
} 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 };
|
||||
}
|
||||
});
|
||||
|
||||
// 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) => {
|
||||
try {
|
||||
if (mainWindow && mainWindow.webContents) {
|
||||
mainWindow.webContents.send('automation-event', ev);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.debug?.('Failed to forward automation-event', e);
|
||||
}
|
||||
});
|
||||
lifecycleSubscribed = true;
|
||||
logger.debug('Subscribed to adapter lifecycle events for renderer relay');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
logger.debug?.('Failed to subscribe to adapter lifecycle events', e);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user