import { GetTextTranslations } from 'gettext-parser'; import { IApplication, ILinuxSplitTunnelingApplication } from './application-types'; import { AccountToken, BridgeSettings, BridgeState, IAccountData, IAppVersionInfo, IDnsOptions, ILocation, IRelayList, ISettings, IWireguardPublicKey, KeygenEvent, RelaySettingsUpdate, TunnelState, VoucherResponse, } from './daemon-rpc-types'; import { IGuiSettingsState } from './gui-settings-state'; import { LogLevel } from './logging-types'; interface ILogEntry { level: LogLevel; message: string; } import { invoke, invokeSync, notifyRenderer, send } from './ipc-helpers'; import { ICurrentAppVersionInfo, IWindowShapeParameters } from './ipc-types'; export interface ITranslations { locale: string; messages?: GetTextTranslations; relayLocations?: GetTextTranslations; } export interface IRelayListPair { relays: IRelayList; bridges: IRelayList; } export type LaunchApplicationResult = { success: true } | { error: string }; export enum MacOsScrollbarVisibility { always, whenScrolling, automatic, } export interface IAppStateSnapshot { isConnected: boolean; autoStart: boolean; accountData?: IAccountData; accountHistory?: AccountToken; tunnelState: TunnelState; settings: ISettings; relayListPair: IRelayListPair; currentVersion: ICurrentAppVersionInfo; upgradeVersion: IAppVersionInfo; guiSettings: IGuiSettingsState; wireguardPublicKey?: IWireguardPublicKey; translations: ITranslations; windowsSplitTunnelingApplications?: IApplication[]; macOsScrollbarVisibility?: MacOsScrollbarVisibility; } // The different types of requests are: // * send(), which is used for one-way communication from the renderer process to the // main process. The main channel will have a property named 'handle' and the // renderer will have a property named the same as the one specified. // * invoke(), which is used for two-way communication from the renderer // process to the main process. The naming is the same as `send()`. // * invokeSync(), same as `invoke()` but synchronous. // * notifyRenderer(), which is used for one-way communication from the main process // to the renderer process. The renderer ipc channel will have a property named // `listen` and the main channel will have a property named `notify`. // // Example: // const ipc = { // groupOfCalls: { // first: send(), // second: request(), // third: requestSync(), // fourth: notifyRenderer(), // }, // }; // // createIpcMain(ipc) // => { // groupOfCalls: { // handleFirst: (fn: (arg: boolean) => void) => void, // handleSecond: (fn: (arg: boolean) => Promise) => void, // handleThird: (fn: (arg: boolean) => number) => void, // notifyFourth: (arg: boolean) => void, // }, // // createIpcRenderer(ipc) // => { // groupOfCalls: { // first: (arg: boolean) => void, // second: (arg: boolean) => Promise, // third: (arg: boolean) => number, // listenFourth: (fn: (arg: boolean) => void) => void, // }, // } export const ipcSchema = { state: { get: invokeSync(), }, window: { shape: notifyRenderer(), focus: notifyRenderer(), macOsScrollbarVisibility: notifyRenderer(), }, navigation: { reset: notifyRenderer(), }, daemon: { connected: notifyRenderer(), disconnected: notifyRenderer(), }, relays: { '': notifyRenderer(), }, currentVersion: { '': notifyRenderer(), }, upgradeVersion: { '': notifyRenderer(), }, app: { quit: send(), openUrl: invoke(), showOpenDialog: invoke(), }, location: { get: invoke(), }, tunnel: { '': notifyRenderer(), connect: invoke(), disconnect: invoke(), reconnect: invoke(), }, settings: { '': notifyRenderer(), setAllowLan: invoke(), setShowBetaReleases: invoke(), setEnableIpv6: invoke(), setBlockWhenDisconnected: invoke(), setBridgeState: invoke(), setOpenVpnMssfix: invoke(), setWireguardMtu: invoke(), updateRelaySettings: invoke(), updateBridgeSettings: invoke(), setDnsOptions: invoke(), }, guiSettings: { '': notifyRenderer(), setEnableSystemNotifications: send(), setAutoConnect: send(), setStartMinimized: send(), setMonochromaticIcon: send(), setPreferredLocale: invoke(), setUnpinnedWindow: send(), }, account: { '': notifyRenderer(), create: invoke(), login: invoke(), logout: invoke(), getWwwAuthToken: invoke(), submitVoucher: invoke(), updateData: send(), }, accountHistory: { '': notifyRenderer(), clear: invoke(), }, autoStart: { '': notifyRenderer(), set: invoke(), }, wireguardKeys: { publicKey: notifyRenderer(), keygenEvent: notifyRenderer(), generateKey: invoke(), verifyKey: invoke(), }, problemReport: { collectLogs: invoke(), sendReport: invoke<{ email: string; message: string; savedReportId: string }, void>(), viewLog: invoke(), }, logging: { log: send(), }, linuxSplitTunneling: { getApplications: invoke(), launchApplication: invoke(), }, windowsSplitTunneling: { '': notifyRenderer(), setState: invoke(), getApplications: invoke(), addApplication: invoke(), removeApplication: invoke(), }, };