internal-electron.d.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. sendToAll(webContentsId: number, channel: string, ...args: any[]): void
  57. }
  58. interface RemoteInternal extends Electron.Remote {
  59. getGuestWebContents(guestInstanceId: number): Electron.WebContents;
  60. }
  61. interface WebContentsInternal extends Electron.WebContents {
  62. _sendInternal(channel: string, ...args: any[]): void;
  63. _sendInternalToAll(channel: string, ...args: any[]): void;
  64. }
  65. const deprecate: ElectronInternal.DeprecationUtil;
  66. }
  67. declare namespace ElectronInternal {
  68. type DeprecationHandler = (message: string) => void;
  69. interface DeprecationUtil {
  70. warnOnce(oldName: string, newName?: string): () => void;
  71. setHandler(handler: DeprecationHandler): void;
  72. getHandler(): DeprecationHandler | null;
  73. warn(oldName: string, newName: string): void;
  74. log(message: string): void;
  75. removeFunction(fn: Function, removedName: string): Function;
  76. renameFunction(fn: Function, newName: string): Function;
  77. event(emitter: NodeJS.EventEmitter, oldName: string, newName: string): void;
  78. fnToProperty(module: any, prop: string, getter: string, setter?: string): void;
  79. removeProperty<T, K extends (keyof T & string)>(object: T, propertyName: K): T;
  80. renameProperty<T, K extends (keyof T & string)>(object: T, oldName: string, newName: K): T;
  81. moveAPI(fn: Function, oldUsage: string, newUsage: string): Function;
  82. promisify<T extends (...args: any[]) => any>(fn: T): T;
  83. // convertPromiseValue: Temporarily disabled until it's used
  84. promisifyMultiArg<T extends (...args: any[]) => any>(fn: T, /*convertPromiseValue: (v: any) => any*/): T;
  85. }
  86. interface DesktopCapturer {
  87. startHandling(captureWindow: boolean, captureScreen: boolean, thumbnailSize: Electron.Size, fetchWindowIcons: boolean): void;
  88. emit: typeof NodeJS.EventEmitter.prototype.emit | null;
  89. }
  90. interface GetSourcesOptions {
  91. captureWindow: boolean;
  92. captureScreen: boolean;
  93. thumbnailSize: Electron.Size;
  94. fetchWindowIcons: boolean;
  95. }
  96. interface GetSourcesResult {
  97. id: string;
  98. name: string;
  99. thumbnail: string;
  100. display_id: string;
  101. appIcon: string | null;
  102. }
  103. // Internal IPC has _replyInternal and NO reply method
  104. interface IpcMainInternalEvent extends Omit<Electron.IpcMainEvent, 'reply'> {
  105. _replyInternal(...args: any[]): void;
  106. }
  107. interface IpcMainInternal extends NodeJS.EventEmitter {
  108. on(channel: string, listener: (event: IpcMainInternalEvent, ...args: any[]) => void): this;
  109. once(channel: string, listener: (event: IpcMainInternalEvent, ...args: any[]) => void): this;
  110. }
  111. interface WebFrameInternal extends Electron.WebFrame {
  112. getWebFrameId(window: Window): number;
  113. allowGuestViewElementDefinition(window: Window, context: any): void;
  114. }
  115. interface WebFrameResizeEvent extends Electron.Event {
  116. newWidth: number;
  117. newHeight: number;
  118. }
  119. interface WebViewEvent extends Event {
  120. url: string;
  121. isMainFrame: boolean;
  122. }
  123. abstract class WebViewElement extends HTMLElement {
  124. static observedAttributes: Array<string>;
  125. public contentWindow: Window;
  126. public connectedCallback(): void;
  127. public attributeChangedCallback(): void;
  128. public disconnectedCallback(): void;
  129. // Created in web-view-impl
  130. public getWebContents(): Electron.WebContents;
  131. public getWebContentsId(): number;
  132. public capturePage(rect?: Electron.Rectangle): Promise<Electron.NativeImage>;
  133. }
  134. }
  135. declare namespace Chrome {
  136. namespace Tabs {
  137. // https://developer.chrome.com/extensions/tabs#method-executeScript
  138. interface ExecuteScriptDetails {
  139. code?: string;
  140. file?: string;
  141. allFrames?: boolean;
  142. frameId?: number;
  143. matchAboutBlank?: boolean;
  144. runAt?: 'document-start' | 'document-end' | 'document_idle';
  145. cssOrigin: 'author' | 'user';
  146. }
  147. type ExecuteScriptCallback = (result: Array<any>) => void;
  148. // https://developer.chrome.com/extensions/tabs#method-sendMessage
  149. interface SendMessageDetails {
  150. frameId?: number;
  151. }
  152. type SendMessageCallback = (result: any) => void;
  153. }
  154. }
  155. interface Global extends NodeJS.Global {
  156. require: NodeRequire;
  157. module: NodeModule;
  158. __filename: string;
  159. __dirname: string;
  160. }