wip
This commit is contained in:
@@ -255,7 +255,18 @@ export function configureDIContainer(): void {
|
||||
}
|
||||
|
||||
// Overlay Sync Service - create singleton instance directly
|
||||
const lifecycleEmitter = browserAutomation as unknown as IAutomationLifecycleEmitter;
|
||||
const lifecycleEmitter: IAutomationLifecycleEmitter = {
|
||||
onLifecycle: (cb) => {
|
||||
if ('onLifecycle' in browserAutomation && typeof (browserAutomation as { onLifecycle?: unknown }).onLifecycle === 'function') {
|
||||
(browserAutomation as IAutomationLifecycleEmitter).onLifecycle(cb);
|
||||
}
|
||||
},
|
||||
offLifecycle: (cb) => {
|
||||
if ('offLifecycle' in browserAutomation && typeof (browserAutomation as { offLifecycle?: unknown }).offLifecycle === 'function') {
|
||||
(browserAutomation as IAutomationLifecycleEmitter).offLifecycle(cb);
|
||||
}
|
||||
},
|
||||
};
|
||||
const publisher = {
|
||||
publish: async (event: unknown) => {
|
||||
try {
|
||||
|
||||
@@ -374,9 +374,10 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
// Subscribe to automation adapter lifecycle events and relay to renderer
|
||||
try {
|
||||
if (!lifecycleSubscribed) {
|
||||
const lifecycleEmitter = container.getBrowserAutomation() as unknown as IAutomationLifecycleEmitter;
|
||||
if (typeof lifecycleEmitter.onLifecycle === 'function') {
|
||||
lifecycleEmitter.onLifecycle((ev) => {
|
||||
const browserAutomation = container.getBrowserAutomation();
|
||||
const candidate = browserAutomation as Partial<IAutomationLifecycleEmitter>;
|
||||
if (typeof candidate.onLifecycle === 'function' && typeof candidate.offLifecycle === 'function') {
|
||||
candidate.onLifecycle((ev) => {
|
||||
try {
|
||||
if (mainWindow && mainWindow.webContents) {
|
||||
mainWindow.webContents.send('automation-event', ev);
|
||||
@@ -388,6 +389,8 @@ export function setupIpcHandlers(mainWindow: BrowserWindow): void {
|
||||
});
|
||||
lifecycleSubscribed = true;
|
||||
logger.debug('Subscribed to adapter lifecycle events for renderer relay');
|
||||
} else {
|
||||
logger.debug?.('Browser automation does not expose lifecycle events; skipping subscription');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -31,12 +31,16 @@ export interface CheckoutConfirmationRequest {
|
||||
timeoutMs: number;
|
||||
}
|
||||
|
||||
export interface StartAutomationResponse {
|
||||
success: boolean;
|
||||
sessionId?: string;
|
||||
error?: string;
|
||||
authRequired?: boolean;
|
||||
authState?: AuthenticationState;
|
||||
}
|
||||
|
||||
export interface ElectronAPI {
|
||||
startAutomation: (config: HostedSessionConfig) => Promise<{
|
||||
success: boolean;
|
||||
sessionId?: string;
|
||||
error?: string;
|
||||
}>;
|
||||
startAutomation: (config: HostedSessionConfig) => Promise<StartAutomationResponse>;
|
||||
stopAutomation: (sessionId: string) => Promise<{ success: boolean; error?: string }>;
|
||||
getSessionStatus: (sessionId: string) => Promise<any>;
|
||||
pauseAutomation: (sessionId: string) => Promise<{ success: boolean; error?: string }>;
|
||||
@@ -60,7 +64,8 @@ export interface ElectronAPI {
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld('electronAPI', {
|
||||
startAutomation: (config: HostedSessionConfig) => ipcRenderer.invoke('start-automation', config),
|
||||
startAutomation: (config: HostedSessionConfig) =>
|
||||
ipcRenderer.invoke('start-automation', config) as Promise<StartAutomationResponse>,
|
||||
stopAutomation: (sessionId: string) => ipcRenderer.invoke('stop-automation', sessionId),
|
||||
getSessionStatus: (sessionId: string) => ipcRenderer.invoke('get-session-status', sessionId),
|
||||
pauseAutomation: (sessionId: string) => ipcRenderer.invoke('pause-automation', sessionId),
|
||||
|
||||
@@ -6,6 +6,8 @@ import { BrowserModeToggle } from './components/BrowserModeToggle';
|
||||
import { CheckoutConfirmationDialog } from './components/CheckoutConfirmationDialog';
|
||||
import { RaceCreationSuccessScreen } from './components/RaceCreationSuccessScreen';
|
||||
import type { HostedSessionConfig } from '../../../packages/automation/domain/types/HostedSessionConfig';
|
||||
import type { AuthenticationState } from '../../../packages/automation/domain/value-objects/AuthenticationState';
|
||||
import type { StartAutomationResponse } from '../main/preload';
|
||||
|
||||
interface SessionProgress {
|
||||
sessionId: string;
|
||||
@@ -16,7 +18,7 @@ interface SessionProgress {
|
||||
errorMessage: string | null;
|
||||
}
|
||||
|
||||
type AuthState = 'UNKNOWN' | 'AUTHENTICATED' | 'EXPIRED' | 'LOGGED_OUT' | 'CHECKING';
|
||||
type AuthState = AuthenticationState | 'CHECKING';
|
||||
type LoginStatus = 'idle' | 'waiting' | 'success' | 'error';
|
||||
|
||||
export function App() {
|
||||
@@ -84,7 +86,7 @@ export function App() {
|
||||
try {
|
||||
const result = await window.electronAPI.checkAuth();
|
||||
if (result.success && result.state) {
|
||||
setAuthState(result.state as AuthState);
|
||||
setAuthState(result.state);
|
||||
} else {
|
||||
setAuthError(result.error);
|
||||
setAuthState('UNKNOWN');
|
||||
@@ -103,7 +105,7 @@ export function App() {
|
||||
try {
|
||||
const result = await window.electronAPI.checkAuth();
|
||||
if (result.success && result.state) {
|
||||
setAuthState(result.state as AuthState);
|
||||
setAuthState(result.state);
|
||||
} else {
|
||||
setAuthError(result.error || 'Failed to check authentication');
|
||||
setAuthState('UNKNOWN');
|
||||
@@ -138,13 +140,7 @@ export function App() {
|
||||
|
||||
const handleStartAutomation = async (config: HostedSessionConfig) => {
|
||||
setIsRunning(true);
|
||||
const result = await window.electronAPI.startAutomation(config) as {
|
||||
success: boolean;
|
||||
sessionId?: string;
|
||||
error?: string;
|
||||
authRequired?: boolean;
|
||||
authState?: AuthState;
|
||||
};
|
||||
const result: StartAutomationResponse = await window.electronAPI.startAutomation(config);
|
||||
|
||||
if (result.success && result.sessionId) {
|
||||
setSessionId(result.sessionId);
|
||||
@@ -153,8 +149,8 @@ export function App() {
|
||||
|
||||
setIsRunning(false);
|
||||
|
||||
if ('authRequired' in result && result.authRequired) {
|
||||
const nextAuthState = result.authState as AuthState | undefined;
|
||||
if (result.authRequired) {
|
||||
const nextAuthState = result.authState;
|
||||
setAuthState(nextAuthState ?? 'EXPIRED');
|
||||
setAuthError(result.error ?? 'Authentication required before starting automation.');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user