59 lines
2.4 KiB
TypeScript
59 lines
2.4 KiB
TypeScript
import { contextBridge, ipcRenderer } from 'electron';
|
|
import type { HostedSessionConfig } from '../../../packages/domain/entities/HostedSessionConfig';
|
|
import type { AuthenticationState } from '../../../packages/domain/value-objects/AuthenticationState';
|
|
|
|
export interface AuthStatusEvent {
|
|
state: AuthenticationState;
|
|
message?: string;
|
|
error?: string;
|
|
}
|
|
|
|
export interface AuthCheckResponse {
|
|
success: boolean;
|
|
state?: AuthenticationState;
|
|
error?: string;
|
|
}
|
|
|
|
export interface AuthActionResponse {
|
|
success: boolean;
|
|
message?: string;
|
|
error?: string;
|
|
}
|
|
|
|
export interface ElectronAPI {
|
|
startAutomation: (config: HostedSessionConfig) => Promise<{
|
|
success: boolean;
|
|
sessionId?: string;
|
|
error?: string;
|
|
}>;
|
|
stopAutomation: (sessionId: string) => Promise<{ success: boolean; error?: string }>;
|
|
getSessionStatus: (sessionId: string) => Promise<any>;
|
|
pauseAutomation: (sessionId: string) => Promise<{ success: boolean; error?: string }>;
|
|
resumeAutomation: (sessionId: string) => Promise<{ success: boolean; error?: string }>;
|
|
onSessionProgress: (callback: (progress: any) => void) => void;
|
|
// Authentication APIs
|
|
onAuthStatus: (callback: (status: AuthStatusEvent) => void) => void;
|
|
checkAuth: () => Promise<AuthCheckResponse>;
|
|
initiateLogin: () => Promise<AuthActionResponse>;
|
|
confirmLogin: () => Promise<AuthActionResponse>;
|
|
logout: () => Promise<AuthActionResponse>;
|
|
}
|
|
|
|
contextBridge.exposeInMainWorld('electronAPI', {
|
|
startAutomation: (config: HostedSessionConfig) => ipcRenderer.invoke('start-automation', config),
|
|
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),
|
|
resumeAutomation: (sessionId: string) => ipcRenderer.invoke('resume-automation', sessionId),
|
|
onSessionProgress: (callback: (progress: any) => void) => {
|
|
ipcRenderer.on('session-progress', (_event, progress) => callback(progress));
|
|
},
|
|
// Authentication APIs
|
|
onAuthStatus: (callback: (status: AuthStatusEvent) => void) => {
|
|
ipcRenderer.on('auth:status', (_event, status) => callback(status));
|
|
},
|
|
checkAuth: () => ipcRenderer.invoke('auth:check'),
|
|
initiateLogin: () => ipcRenderer.invoke('auth:login'),
|
|
confirmLogin: () => ipcRenderer.invoke('auth:confirmLogin'),
|
|
logout: () => ipcRenderer.invoke('auth:logout'),
|
|
} as ElectronAPI); |