internal-electron.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 SerializedError {
  19. message: string;
  20. stack?: string,
  21. name: string,
  22. from: Electron.ProcessType,
  23. cause: SerializedError,
  24. __ELECTRON_SERIALIZED_ERROR__: true
  25. }
  26. interface InjectionBase {
  27. url: string;
  28. code: string
  29. }
  30. interface ContentScript {
  31. js: Array<InjectionBase>;
  32. css: Array<InjectionBase>;
  33. runAt: string;
  34. matches: {
  35. some: (input: (pattern: string) => boolean | RegExpMatchArray | null) => boolean;
  36. }
  37. /**
  38. * Whether to match all frames, or only the top one.
  39. * https://developer.chrome.com/extensions/content_scripts#frames
  40. */
  41. allFrames: boolean
  42. }
  43. interface RendererProcessPreference {
  44. contentScripts: Array<ContentScript>
  45. extensionId: string;
  46. }
  47. interface IpcRendererInternal extends Electron.IpcRenderer {
  48. sendToAll(webContentsId: number, channel: string, ...args: any[]): void
  49. }
  50. interface RemoteInternal extends Electron.Remote {
  51. getGuestWebContents(guestInstanceId: number): Electron.WebContents;
  52. }
  53. interface WebContentsInternal extends Electron.WebContents {
  54. _sendInternal(channel: string, ...args: any[]): void;
  55. _sendInternalToAll(channel: string, ...args: any[]): void;
  56. }
  57. const deprecate: ElectronInternal.DeprecationUtil;
  58. }
  59. declare namespace ElectronInternal {
  60. type DeprecationHandler = (message: string) => void;
  61. interface DeprecationUtil {
  62. setHandler(handler: DeprecationHandler): void;
  63. getHandler(): DeprecationHandler | null;
  64. warn(oldName: string, newName: string): void;
  65. log(message: string): void;
  66. removeFunction(fn: Function, removedName: string): Function;
  67. renameFunction(fn: Function, newName: string): Function;
  68. event(emitter: NodeJS.EventEmitter, oldName: string, newName: string): void;
  69. fnToProperty(module: any, prop: string, getter: string, setter: string): void;
  70. removeProperty<T, K extends (keyof T & string)>(object: T, propertyName: K): T;
  71. renameProperty<T, K extends (keyof T & string)>(object: T, oldName: string, newName: K): T;
  72. promisify<T extends (...args: any[]) => any>(fn: T): T;
  73. promisifyMultiArg<T extends (...args: any[]) => any>(fn: T, convertPromiseValue: (v: any) => any): T;
  74. }
  75. // Internal IPC has _replyInternal and NO reply method
  76. interface IpcMainInternalEvent extends Omit<Electron.IpcMainEvent, 'reply'> {
  77. _replyInternal(...args: any[]): void;
  78. }
  79. interface IpcMainInternal extends Electron.EventEmitter {
  80. on(channel: string, listener: (event: IpcMainInternalEvent, ...args: any[]) => void): this;
  81. once(channel: string, listener: (event: IpcMainInternalEvent, ...args: any[]) => void): this;
  82. }
  83. interface WebFrameInternal extends Electron.WebFrame {
  84. getWebFrameId(window: Window): number;
  85. allowGuestViewElementDefinition(window: Window, context: any): void;
  86. }
  87. interface WebFrameResizeEvent extends Electron.Event {
  88. newWidth: number;
  89. newHeight: number;
  90. }
  91. interface WebViewEvent extends Event {
  92. url: string;
  93. isMainFrame: boolean;
  94. }
  95. abstract class WebViewElement extends HTMLElement {
  96. static observedAttributes: Array<string>;
  97. public contentWindow: Window;
  98. public connectedCallback(): void;
  99. public attributeChangedCallback(): void;
  100. public disconnectedCallback(): void;
  101. // Created in web-view-impl
  102. public getWebContents(): Electron.WebContents;
  103. public getWebContentsId(): number;
  104. }
  105. }
  106. declare namespace Chrome {
  107. namespace Tabs {
  108. // https://developer.chrome.com/extensions/tabs#method-executeScript
  109. interface ExecuteScriptDetails {
  110. code?: string;
  111. file?: string;
  112. allFrames?: boolean;
  113. frameId?: number;
  114. matchAboutBlank?: boolean;
  115. runAt?: 'document-start' | 'document-end' | 'document_idle';
  116. cssOrigin: 'author' | 'user';
  117. }
  118. type ExecuteScriptCallback = (result: Array<any>) => void;
  119. // https://developer.chrome.com/extensions/tabs#method-sendMessage
  120. interface SendMessageDetails {
  121. frameId?: number;
  122. }
  123. type SendMessageCallback = (result: any) => void;
  124. }
  125. }
  126. interface Global extends NodeJS.Global {
  127. require: NodeRequire;
  128. module: NodeModule;
  129. __filename: string;
  130. __dirname: string;
  131. }