internal-electron.d.ts 6.0 KB

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