internal-electron.d.ts 6.2 KB

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