internal-electron.d.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. _setDefaultAppPaths(packagePath: string | null): void;
  14. setVersion(version: string): void;
  15. setDesktopName(name: string): void;
  16. setAppPath(path: string | null): void;
  17. }
  18. interface ContextBridge {
  19. internalContextBridge: {
  20. contextIsolationEnabled: boolean;
  21. overrideGlobalValueFromIsolatedWorld(keys: string[], value: any): void;
  22. overrideGlobalValueWithDynamicPropsFromIsolatedWorld(keys: string[], value: any): void;
  23. overrideGlobalPropertyFromIsolatedWorld(keys: string[], getter: Function, setter?: Function): void;
  24. isInMainWorld(): boolean;
  25. }
  26. }
  27. interface WebContents {
  28. _getURL(): string;
  29. getOwnerBrowserWindow(): Electron.BrowserWindow;
  30. _initiallyShown: boolean;
  31. }
  32. interface WebPreferences {
  33. guestInstanceId?: number;
  34. openerId?: number;
  35. }
  36. interface SerializedError {
  37. message: string;
  38. stack?: string,
  39. name: string,
  40. from: Electron.ProcessType,
  41. cause: SerializedError,
  42. __ELECTRON_SERIALIZED_ERROR__: true
  43. }
  44. interface ErrorWithCause extends Error {
  45. from?: string;
  46. cause?: ErrorWithCause;
  47. }
  48. interface InjectionBase {
  49. url: string;
  50. code: string
  51. }
  52. interface ContentScript {
  53. js: Array<InjectionBase>;
  54. css: Array<InjectionBase>;
  55. runAt: string;
  56. matches: {
  57. some: (input: (pattern: string) => boolean | RegExpMatchArray | null) => boolean;
  58. }
  59. /**
  60. * Whether to match all frames, or only the top one.
  61. * https://developer.chrome.com/extensions/content_scripts#frames
  62. */
  63. allFrames: boolean
  64. }
  65. type ContentScriptEntry = {
  66. extensionId: string;
  67. contentScripts: ContentScript[];
  68. }
  69. interface IpcRendererInternal extends Electron.IpcRenderer {
  70. invoke<T>(channel: string, ...args: any[]): Promise<T>;
  71. sendToAll(webContentsId: number, channel: string, ...args: any[]): void
  72. onMessageFromMain(channel: string, listener: (event: Electron.IpcRendererEvent, ...args: any[]) => void): this;
  73. onceMessageFromMain(channel: string, listener: (event: Electron.IpcRendererEvent, ...args: any[]) => void): this;
  74. }
  75. interface WebContentsInternal extends Electron.WebContents {
  76. _sendInternal(channel: string, ...args: any[]): void;
  77. _sendInternalToAll(channel: string, ...args: any[]): void;
  78. }
  79. const deprecate: ElectronInternal.DeprecationUtil;
  80. namespace Main {
  81. const deprecate: ElectronInternal.DeprecationUtil;
  82. }
  83. }
  84. declare namespace ElectronInternal {
  85. type DeprecationHandler = (message: string) => void;
  86. interface DeprecationUtil {
  87. warnOnce(oldName: string, newName?: string): () => void;
  88. setHandler(handler: DeprecationHandler | null): void;
  89. getHandler(): DeprecationHandler | null;
  90. warn(oldName: string, newName: string): void;
  91. log(message: string): void;
  92. removeFunction(fn: Function, removedName: string): Function;
  93. renameFunction(fn: Function, newName: string | Function): Function;
  94. event(emitter: NodeJS.EventEmitter, oldName: string, newName: string): void;
  95. fnToProperty(module: any, prop: string, getter: string, setter?: string): void;
  96. removeProperty<T, K extends (keyof T & string)>(object: T, propertyName: K, onlyForValues?: any[]): T;
  97. renameProperty<T, K extends (keyof T & string)>(object: T, oldName: string, newName: K): T;
  98. moveAPI(fn: Function, oldUsage: string, newUsage: string): Function;
  99. }
  100. interface DesktopCapturer {
  101. startHandling(captureWindow: boolean, captureScreen: boolean, thumbnailSize: Electron.Size, fetchWindowIcons: boolean): void;
  102. _onerror: (error: string) => void;
  103. _onfinished: (sources: Electron.DesktopCapturerSource[], fetchWindowIcons: boolean) => void;
  104. }
  105. interface GetSourcesOptions {
  106. captureWindow: boolean;
  107. captureScreen: boolean;
  108. thumbnailSize: Electron.Size;
  109. fetchWindowIcons: boolean;
  110. }
  111. interface GetSourcesResult {
  112. id: string;
  113. name: string;
  114. thumbnail: Electron.NativeImage;
  115. display_id: string;
  116. appIcon: Electron.NativeImage | null;
  117. }
  118. interface KeyWeakMap<K, V> {
  119. set(key: K, value: V): void;
  120. get(key: K): V | undefined;
  121. has(key: K): boolean;
  122. remove(key: K): void;
  123. }
  124. // Internal IPC has _replyInternal and NO reply method
  125. interface IpcMainInternalEvent extends Omit<Electron.IpcMainEvent, 'reply'> {
  126. _replyInternal(...args: any[]): void;
  127. }
  128. interface IpcMainInternal extends NodeJS.EventEmitter {
  129. handle(channel: string, listener: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => Promise<any> | any): void;
  130. on(channel: string, listener: (event: IpcMainInternalEvent, ...args: any[]) => void): this;
  131. once(channel: string, listener: (event: IpcMainInternalEvent, ...args: any[]) => void): this;
  132. }
  133. type ModuleLoader = () => any;
  134. interface ModuleEntry {
  135. name: string;
  136. private?: boolean;
  137. loader: ModuleLoader;
  138. }
  139. interface WebFrameInternal extends Electron.WebFrame {
  140. getWebFrameId(window: Window): number;
  141. allowGuestViewElementDefinition(window: Window, context: any): void;
  142. }
  143. class WebViewElement extends HTMLElement {
  144. static observedAttributes: Array<string>;
  145. public contentWindow: Window;
  146. public connectedCallback(): void;
  147. public attributeChangedCallback(): void;
  148. public disconnectedCallback(): void;
  149. // Created in web-view-impl
  150. public getWebContentsId(): number;
  151. public capturePage(rect?: Electron.Rectangle): Promise<Electron.NativeImage>;
  152. }
  153. }
  154. declare namespace Chrome {
  155. namespace Tabs {
  156. // https://developer.chrome.com/extensions/tabs#method-executeScript
  157. interface ExecuteScriptDetails {
  158. code?: string;
  159. file?: string;
  160. allFrames?: boolean;
  161. frameId?: number;
  162. matchAboutBlank?: boolean;
  163. runAt?: 'document-start' | 'document-end' | 'document_idle';
  164. cssOrigin: 'author' | 'user';
  165. }
  166. type ExecuteScriptCallback = (result: Array<any>) => void;
  167. // https://developer.chrome.com/extensions/tabs#method-sendMessage
  168. interface SendMessageDetails {
  169. frameId?: number;
  170. }
  171. type SendMessageCallback = (result: any) => void;
  172. }
  173. }
  174. interface Global extends NodeJS.Global {
  175. require: NodeRequire;
  176. module: NodeModule;
  177. __filename: string;
  178. __dirname: string;
  179. }