import { GetTextTranslations } from 'gettext-parser'; import { ILinuxSplitTunnelingApplication, ISplitTunnelingApplication } from './application-types'; import { AccessMethodExistsError, AccessMethodSetting, AccountDataError, AccountNumber, BridgeSettings, BridgeState, CustomListError, CustomProxy, DeviceEvent, DeviceState, IAccountData, IAppVersionInfo, ICustomList, IDevice, IDeviceRemoval, IDnsOptions, IRelayListWithEndpointData, ISettings, NewAccessMethodSetting, NewCustomList, ObfuscationSettings, RelaySettings, TunnelState, VoucherResponse, } from './daemon-rpc-types'; import { IGuiSettingsState } from './gui-settings-state'; import { LogLevel } from './logging-types'; interface ILogEntry { level: LogLevel; message: string; } import { MapData } from '../renderer/lib/3dmap'; import { AppUpgradeError, AppUpgradeEvent } from './app-upgrade'; import { invoke, invokeSync, notifyRenderer, send } from './ipc-helpers'; import { DaemonStatus, IChangelog, ICurrentAppVersionInfo, IHistoryObject, IWindowShapeParameters, } from './ipc-types'; import { RoutePath } from './routes'; export interface ITranslations { locale: string; messages?: GetTextTranslations; relayLocations?: GetTextTranslations; } export type LaunchApplicationResult = { success: true } | { error: string }; export enum MacOsScrollbarVisibility { always, whenScrolling, automatic, } export interface IAppStateSnapshot { isConnected: boolean; autoStart: boolean; accountData?: IAccountData; accountHistory?: AccountNumber; tunnelState: TunnelState; settings: ISettings; isPerformingPostUpgrade: boolean; daemonAllowed?: boolean; deviceState?: DeviceState; relayList?: IRelayListWithEndpointData; currentVersion: ICurrentAppVersionInfo; upgradeVersion: IAppVersionInfo; guiSettings: IGuiSettingsState; translations: ITranslations; splitTunnelingApplications?: ISplitTunnelingApplication[]; macOsScrollbarVisibility?: MacOsScrollbarVisibility; changelog: IChangelog; navigationHistory?: IHistoryObject; currentApiAccessMethod?: AccessMethodSetting; isMacOs13OrNewer: boolean; } export type IpcSchema = typeof ipcSchema; // 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(), }, map: { getData: invoke(), }, window: { shape: notifyRenderer(), focus: notifyRenderer(), macOsScrollbarVisibility: notifyRenderer(), scaleFactorChange: notifyRenderer(), }, navigation: { reset: notifyRenderer(), setHistory: send(), }, daemon: { isPerformingPostUpgrade: notifyRenderer(), daemonAllowed: notifyRenderer(), connected: notifyRenderer(), disconnected: notifyRenderer(), prepareRestart: send(), tryStart: send(), tryStartEvent: notifyRenderer(), }, relays: { '': notifyRenderer(), }, customLists: { createCustomList: invoke(), deleteCustomList: invoke(), updateCustomList: invoke(), }, currentVersion: { '': notifyRenderer(), displayedChangelog: send(), }, upgradeVersion: { '': notifyRenderer(), dismissedUpgrade: send(), }, app: { quit: send(), openUrl: invoke(), openRoute: notifyRenderer(), showOpenDialog: invoke(), showLaunchDaemonSettings: invoke(), showFullDiskAccessSettings: invoke(), getPathBaseName: invoke(), upgrade: send(), upgradeAbort: send(), upgradeEvent: notifyRenderer(), upgradeError: notifyRenderer(), upgradeInstallerStart: send(), getUpgradeCacheDir: invoke(), }, tunnel: { '': notifyRenderer(), connect: invoke(), disconnect: invoke(), reconnect: invoke(), }, settings: { '': notifyRenderer(), importFile: invoke(), importText: invoke(), apiAccessMethodSettingChange: notifyRenderer(), setAllowLan: invoke(), setShowBetaReleases: invoke(), setEnableIpv6: invoke(), setLockdownMode: invoke(), setBridgeState: invoke(), setOpenVpnMssfix: invoke(), setWireguardMtu: invoke(), setWireguardQuantumResistant: invoke(), setRelaySettings: invoke(), updateBridgeSettings: invoke(), setDnsOptions: invoke(), setObfuscationSettings: invoke(), addApiAccessMethod: invoke(), updateApiAccessMethod: invoke(), removeApiAccessMethod: invoke(), setApiAccessMethod: invoke(), testApiAccessMethodById: invoke(), testCustomApiAccessMethod: invoke(), clearAllRelayOverrides: invoke(), setEnableDaita: invoke(), setDaitaDirectOnly: invoke(), }, guiSettings: { '': notifyRenderer(), setEnableSystemNotifications: send(), setAutoConnect: send(), setStartMinimized: send(), setMonochromaticIcon: send(), setPreferredLocale: invoke(), setUnpinnedWindow: send(), setAnimateMap: send(), }, account: { '': notifyRenderer(), device: notifyRenderer(), devices: notifyRenderer>(), create: invoke(), login: invoke(), logout: invoke(), getWwwAuthToken: invoke(), submitVoucher: invoke(), updateData: send(), listDevices: invoke>(), removeDevice: invoke(), }, accountHistory: { '': notifyRenderer(), clear: invoke(), }, autoStart: { '': notifyRenderer(), set: invoke(), }, problemReport: { collectLogs: invoke(), sendReport: invoke<{ email: string; message: string; savedReportId: string }, void>(), viewLog: invoke(), }, logging: { log: send(), }, linuxSplitTunneling: { isSplitTunnelingSupported: invoke(), getApplications: invoke(), launchApplication: invoke(), }, macOsSplitTunneling: { needFullDiskPermissions: invoke(), }, splitTunneling: { '': notifyRenderer(), setState: invoke(), getApplications: invoke< boolean, { fromCache: boolean; applications: ISplitTunnelingApplication[] } >(), addApplication: invoke(), removeApplication: invoke(), forgetManuallyAddedApplication: invoke(), }, };