internal-electron.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /// <reference path="../electron.d.ts" />
  2. /**
  3. * This file augments the Electron TS namespace with the internal APIs
  4. * that are not documented but are used by Electron internally
  5. */
  6. declare namespace Electron {
  7. enum ProcessType {
  8. browser = 'browser',
  9. renderer = 'renderer',
  10. worker = 'worker'
  11. }
  12. interface App {
  13. setVersion(version: string): void;
  14. setDesktopName(name: string): void;
  15. setAppPath(path: string | null): void;
  16. }
  17. type TouchBarItemType = NonNullable<Electron.TouchBarConstructorOptions['items']>[0];
  18. interface BaseWindow {
  19. _init(): void;
  20. }
  21. interface BrowserWindow {
  22. _init(): void;
  23. _touchBar: Electron.TouchBar | null;
  24. _setTouchBarItems: (items: TouchBarItemType[]) => void;
  25. _setEscapeTouchBarItem: (item: TouchBarItemType | {}) => void;
  26. _refreshTouchBarItem: (itemID: string) => void;
  27. _getWindowButtonVisibility: () => boolean;
  28. frameName: string;
  29. on(event: '-touch-bar-interaction', listener: (event: Event, itemID: string, details: any) => void): this;
  30. removeListener(event: '-touch-bar-interaction', listener: (event: Event, itemID: string, details: any) => void): this;
  31. }
  32. interface BrowserWindowConstructorOptions {
  33. webContents?: WebContents;
  34. }
  35. interface ContextBridge {
  36. internalContextBridge?: {
  37. contextIsolationEnabled: boolean;
  38. overrideGlobalValueFromIsolatedWorld(keys: string[], value: any): void;
  39. overrideGlobalValueWithDynamicPropsFromIsolatedWorld(keys: string[], value: any): void;
  40. overrideGlobalPropertyFromIsolatedWorld(keys: string[], getter: Function, setter?: Function): void;
  41. isInMainWorld(): boolean;
  42. }
  43. }
  44. interface TouchBar {
  45. _removeFromWindow: (win: BrowserWindow) => void;
  46. }
  47. interface WebContents {
  48. _loadURL(url: string, options: ElectronInternal.LoadURLOptions): void;
  49. getOwnerBrowserWindow(): Electron.BrowserWindow | null;
  50. getLastWebPreferences(): Electron.WebPreferences | null;
  51. _getProcessMemoryInfo(): Electron.ProcessMemoryInfo;
  52. _getPreloadPaths(): string[];
  53. equal(other: WebContents): boolean;
  54. browserWindowOptions: BrowserWindowConstructorOptions;
  55. _windowOpenHandler: ((details: Electron.HandlerDetails) => any) | null;
  56. _callWindowOpenHandler(event: any, details: Electron.HandlerDetails): {browserWindowConstructorOptions: Electron.BrowserWindowConstructorOptions | null, outlivesOpener: boolean};
  57. _setNextChildWebPreferences(prefs: Partial<Electron.BrowserWindowConstructorOptions['webPreferences']> & Pick<Electron.BrowserWindowConstructorOptions, 'backgroundColor'>): void;
  58. _send(internal: boolean, channel: string, args: any): boolean;
  59. _sendInternal(channel: string, ...args: any[]): void;
  60. _printToPDF(options: any): Promise<Buffer>;
  61. _print(options: any, callback?: (success: boolean, failureReason: string) => void): void;
  62. _getPrinters(): Electron.PrinterInfo[];
  63. _getPrintersAsync(): Promise<Electron.PrinterInfo[]>;
  64. _init(): void;
  65. canGoToIndex(index: number): boolean;
  66. getActiveIndex(): number;
  67. length(): number;
  68. destroy(): void;
  69. // <webview>
  70. attachToIframe(embedderWebContents: Electron.WebContents, embedderFrameId: number): void;
  71. detachFromOuterFrame(): void;
  72. setEmbedder(embedder: Electron.WebContents): void;
  73. viewInstanceId: number;
  74. }
  75. interface WebFrameMain {
  76. _send(internal: boolean, channel: string, args: any): void;
  77. _sendInternal(channel: string, ...args: any[]): void;
  78. _postMessage(channel: string, message: any, transfer?: any[]): void;
  79. }
  80. interface WebFrame {
  81. _isEvalAllowed(): boolean;
  82. }
  83. interface WebPreferences {
  84. disablePopups?: boolean;
  85. embedder?: Electron.WebContents;
  86. type?: 'backgroundPage' | 'window' | 'browserView' | 'remote' | 'webview' | 'offscreen';
  87. }
  88. interface Menu {
  89. _init(): void;
  90. _isCommandIdChecked(id: string): boolean;
  91. _isCommandIdEnabled(id: string): boolean;
  92. _shouldCommandIdWorkWhenHidden(id: string): boolean;
  93. _isCommandIdVisible(id: string): boolean;
  94. _getAcceleratorForCommandId(id: string, useDefaultAccelerator: boolean): Accelerator | undefined;
  95. _shouldRegisterAcceleratorForCommandId(id: string): boolean;
  96. _getSharingItemForCommandId(id: string): SharingItem | null;
  97. _callMenuWillShow(): void;
  98. _executeCommand(event: any, id: number): void;
  99. _menuWillShow(): void;
  100. commandsMap: Record<string, MenuItem>;
  101. groupsMap: Record<string, MenuItem[]>;
  102. getItemCount(): number;
  103. popupAt(window: BaseWindow, x: number, y: number, positioning: number, callback: () => void): void;
  104. closePopupAt(id: number): void;
  105. setSublabel(index: number, label: string): void;
  106. setToolTip(index: number, tooltip: string): void;
  107. setIcon(index: number, image: string | NativeImage): void;
  108. setRole(index: number, role: string): void;
  109. insertItem(index: number, commandId: number, label: string): void;
  110. insertCheckItem(index: number, commandId: number, label: string): void;
  111. insertRadioItem(index: number, commandId: number, label: string, groupId: number): void;
  112. insertSeparator(index: number): void;
  113. insertSubMenu(index: number, commandId: number, label: string, submenu?: Menu): void;
  114. delegate?: any;
  115. _getAcceleratorTextAt(index: number): string;
  116. }
  117. interface MenuItem {
  118. overrideReadOnlyProperty(property: string, value: any): void;
  119. groupId: number;
  120. getDefaultRoleAccelerator(): Accelerator | undefined;
  121. getCheckStatus(): boolean;
  122. acceleratorWorksWhenHidden?: boolean;
  123. }
  124. interface IpcMainEvent {
  125. sendReply(value: any): void;
  126. }
  127. interface IpcMainInvokeEvent {
  128. sendReply(value: any): void;
  129. _reply(value: any): void;
  130. _throw(error: Error | string): void;
  131. }
  132. const deprecate: ElectronInternal.DeprecationUtil;
  133. namespace Main {
  134. const deprecate: ElectronInternal.DeprecationUtil;
  135. }
  136. class View {}
  137. // Experimental views API
  138. class BaseWindow {
  139. constructor(args: {show: boolean})
  140. setContentView(view: View): void
  141. static fromId(id: number): BaseWindow;
  142. static getAllWindows(): BaseWindow[];
  143. isFocused(): boolean;
  144. static getFocusedWindow(): BaseWindow | undefined;
  145. setMenu(menu: Menu): void;
  146. }
  147. class WebContentsView {
  148. constructor(options: BrowserWindowConstructorOptions)
  149. }
  150. // Deprecated / undocumented BrowserWindow methods
  151. interface BrowserWindow {
  152. getURL(): string;
  153. send(channel: string, ...args: any[]): void;
  154. openDevTools(options?: Electron.OpenDevToolsOptions): void;
  155. closeDevTools(): void;
  156. isDevToolsOpened(): void;
  157. isDevToolsFocused(): void;
  158. toggleDevTools(): void;
  159. inspectElement(x: number, y: number): void;
  160. inspectSharedWorker(): void;
  161. inspectServiceWorker(): void;
  162. getBackgroundThrottling(): void;
  163. setBackgroundThrottling(allowed: boolean): void;
  164. }
  165. namespace Main {
  166. class BaseWindow extends Electron.BaseWindow {}
  167. class View extends Electron.View {}
  168. class WebContentsView extends Electron.WebContentsView {}
  169. }
  170. }
  171. declare namespace ElectronInternal {
  172. type DeprecationHandler = (message: string) => void;
  173. interface DeprecationUtil {
  174. warnOnce(oldName: string, newName?: string): () => void;
  175. setHandler(handler: DeprecationHandler | null): void;
  176. getHandler(): DeprecationHandler | null;
  177. warn(oldName: string, newName: string): void;
  178. log(message: string): void;
  179. removeFunction<T extends Function>(fn: T, removedName: string): T;
  180. renameFunction<T extends Function>(fn: T, newName: string): T;
  181. event(emitter: NodeJS.EventEmitter, oldName: string, newName: string): void;
  182. removeProperty<T, K extends (keyof T & string)>(object: T, propertyName: K, onlyForValues?: any[]): T;
  183. renameProperty<T, K extends (keyof T & string)>(object: T, oldName: string, newName: K): T;
  184. moveAPI<T extends Function>(fn: T, oldUsage: string, newUsage: string): T;
  185. }
  186. interface DesktopCapturer {
  187. startHandling(captureWindow: boolean, captureScreen: boolean, thumbnailSize: Electron.Size, fetchWindowIcons: boolean): void;
  188. _onerror?: (error: string) => void;
  189. _onfinished?: (sources: Electron.DesktopCapturerSource[], fetchWindowIcons: boolean) => void;
  190. }
  191. interface GetSourcesOptions {
  192. captureWindow: boolean;
  193. captureScreen: boolean;
  194. thumbnailSize: Electron.Size;
  195. fetchWindowIcons: boolean;
  196. }
  197. interface GetSourcesResult {
  198. id: string;
  199. name: string;
  200. thumbnail: Electron.NativeImage;
  201. display_id: string;
  202. appIcon: Electron.NativeImage | null;
  203. }
  204. interface IpcRendererInternal extends NodeJS.EventEmitter, Pick<Electron.IpcRenderer, 'send' | 'sendSync' | 'invoke'> {
  205. invoke<T>(channel: string, ...args: any[]): Promise<T>;
  206. }
  207. interface IpcMainInternalEvent extends Omit<Electron.IpcMainEvent, 'reply'> {
  208. }
  209. interface IpcMainInternal extends NodeJS.EventEmitter {
  210. handle(channel: string, listener: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => Promise<any> | any): void;
  211. on(channel: string, listener: (event: IpcMainInternalEvent, ...args: any[]) => void): this;
  212. once(channel: string, listener: (event: IpcMainInternalEvent, ...args: any[]) => void): this;
  213. }
  214. interface Event extends Electron.Event {
  215. sender: WebContents;
  216. }
  217. interface LoadURLOptions extends Electron.LoadURLOptions {
  218. reloadIgnoringCache?: boolean;
  219. }
  220. interface WebContentsPrintOptions extends Electron.WebContentsPrintOptions {
  221. mediaSize?: MediaSize;
  222. }
  223. type MediaSize = {
  224. name: string,
  225. custom_display_name: string,
  226. height_microns: number,
  227. width_microns: number,
  228. is_default?: 'true',
  229. }
  230. type PageSize = {
  231. width: number,
  232. height: number,
  233. }
  234. type ModuleLoader = () => any;
  235. interface ModuleEntry {
  236. name: string;
  237. private?: boolean;
  238. loader: ModuleLoader;
  239. }
  240. class WebViewElement extends HTMLElement {
  241. static observedAttributes: Array<string>;
  242. public contentWindow: Window;
  243. public connectedCallback?(): void;
  244. public attributeChangedCallback?(): void;
  245. public disconnectedCallback?(): void;
  246. // Created in web-view-impl
  247. public getWebContentsId(): number;
  248. public capturePage(rect?: Electron.Rectangle): Promise<Electron.NativeImage>;
  249. }
  250. class WebContents extends Electron.WebContents {
  251. static create(opts: Electron.WebPreferences): Electron.WebContents;
  252. }
  253. }
  254. declare namespace Chrome {
  255. namespace Tabs {
  256. // https://developer.chrome.com/docs/extensions/tabs#method-executeScript
  257. interface ExecuteScriptDetails {
  258. code?: string;
  259. file?: string;
  260. allFrames?: boolean;
  261. frameId?: number;
  262. matchAboutBlank?: boolean;
  263. runAt?: 'document-start' | 'document-end' | 'document_idle';
  264. cssOrigin: 'author' | 'user';
  265. }
  266. type ExecuteScriptCallback = (result: Array<any>) => void;
  267. // https://developer.chrome.com/docs/extensions/tabs#method-sendMessage
  268. interface SendMessageDetails {
  269. frameId?: number;
  270. }
  271. type SendMessageCallback = (result: any) => void;
  272. }
  273. }
  274. interface Global extends NodeJS.Global {
  275. require: NodeRequire;
  276. module: NodeModule;
  277. __filename: string;
  278. __dirname: string;
  279. }