/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ // eslint-disable-next-line no-restricted-imports import type { NativeTheme, SaveDialogReturnValue, SaveDialogOptions, OpenDialogOptions, OpenDialogReturnValue, } from 'electron'; import {ipcRenderer} from 'electron/renderer'; export interface ElectronIpcAsyncCommands { getPath: (path: 'app' | 'home' | 'temp' | 'desktop') => Promise; getProcess: () => Promise<{execPath: string; pid: number}>; relaunch: (options?: {args: string[]}) => Promise; showSaveDialog: ( options: SaveDialogOptions, ) => Promise; showOpenDialog: ( options: OpenDialogOptions, ) => Promise; getNativeTheme: () => Promise< Pick< NativeTheme, | 'inForcedColorsMode' | 'shouldUseDarkColors' | 'shouldUseHighContrastColors' | 'shouldUseInvertedColorScheme' | 'themeSource' > >; quit: () => Promise; exit: () => Promise; getApp: () => Promise<{ name: string; }>; } export interface ElectronIpcSyncCommands { getCurrentWindowState: () => { isFocused: boolean; }; } export interface ElectronIpcEvents { menuItemAction: { menu: 'view' | 'root'; label: string; action: 'click'; }; } export class ElectronIpcClientRenderer { on( eventName: T, cb: (data: ElectronIpcEvents[T]) => void, ) { ipcRenderer.on(eventName, (_event, data) => cb(data)); } send( eventName: T, ...args: Parameters ): ReturnType extends Promise ? ReturnType : never { return ipcRenderer.invoke(eventName, ...args) as any; } sendSync( eventName: T, ...args: Parameters ): ReturnType { // eslint-disable-next-line node/no-sync return ipcRenderer.sendSync(eventName, ...args); } }