import { MessageBoxOptions } from 'electron'; import { Observable } from 'rxjs'; import { ProxyPropertyType } from 'electron-ipc-cat/common'; import { NativeChannel } from '@/constants/channels'; import { WindowNames } from '@services/windows/WindowProperties'; import { IZxFileInput } from './zxWorker'; /** * Wrap call to electron api, so we won't need remote module in renderer process */ export interface INativeService { executeZxScript$(zxWorkerArguments: IZxFileInput): Observable; open(uri: string, isDirectory?: boolean): Promise; openInEditor(filePath: string, editorName?: string | undefined): Promise; openInGitGuiApp(filePath: string, editorName?: string | undefined): Promise; pickDirectory(defaultPath?: string): Promise; pickFile(filters?: Electron.OpenDialogOptions['filters']): Promise; quit(): void; showElectronMessageBox(message: string, type: MessageBoxOptions['type'], WindowName?: WindowNames): Promise; } export const NativeServiceIPCDescriptor = { channel: NativeChannel.name, properties: { executeZxScript$: ProxyPropertyType.Function$, open: ProxyPropertyType.Function, openInEditor: ProxyPropertyType.Function, openInGitGuiApp: ProxyPropertyType.Function, pickDirectory: ProxyPropertyType.Function, pickFile: ProxyPropertyType.Function, quit: ProxyPropertyType.Function, showElectronMessageBox: ProxyPropertyType.Function, }, }; export type IZxWorkerMessage = IZxWorkerLogMessage | IZxWorkerControlMessage; export interface IZxWorkerLogMessage { message: string; type: 'stdout' | 'stderr'; } export enum ZxWorkerControlActions { ended = 'ended', error = 'error', /** means worker is just started */ start = 'start', } export interface IZxWorkerControlMessage { actions: ZxWorkerControlActions; message?: string; type: 'control'; }