chore: cleanup typings/internal-electron.d.ts (#25711)

This commit is contained in:
Milan Burda 2020-10-02 04:52:29 +02:00 committed by GitHub
parent 17c7c5cfdd
commit 8df4faa8f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 76 deletions

View file

@ -121,7 +121,7 @@ const defaultPrintingSetting = {
// JavaScript implementations of WebContents.
const binding = process._linkedBinding('electron_browser_web_contents');
const { WebContents } = binding as { WebContents: { prototype: Electron.WebContentsInternal } };
const { WebContents } = binding as { WebContents: { prototype: Electron.WebContents } };
WebContents.prototype.send = function (channel, ...args) {
if (typeof channel !== 'string') {
@ -200,7 +200,7 @@ for (const method of webFrameMethods) {
};
}
const waitTillCanExecuteJavaScript = async (webContents: Electron.WebContentsInternal) => {
const waitTillCanExecuteJavaScript = async (webContents: Electron.WebContents) => {
if (webContents.getURL() && !webContents.isLoadingMainFrame()) return;
return new Promise((resolve) => {
@ -491,7 +491,7 @@ WebContents.prototype._init = function () {
this.setMaxListeners(0);
// Dispatch IPC messages to the ipc module.
this.on('-ipc-message' as any, function (this: Electron.WebContentsInternal, event: any, internal: boolean, channel: string, args: any[]) {
this.on('-ipc-message' as any, function (this: Electron.WebContents, event: any, internal: boolean, channel: string, args: any[]) {
if (internal) {
addReplyInternalToEvent(event);
ipcMainInternal.emit(channel, event, ...args);
@ -516,7 +516,7 @@ WebContents.prototype._init = function () {
}
});
this.on('-ipc-message-sync' as any, function (this: Electron.WebContentsInternal, event: any, internal: boolean, channel: string, args: any[]) {
this.on('-ipc-message-sync' as any, function (this: Electron.WebContents, event: any, internal: boolean, channel: string, args: any[]) {
addReturnValueToEvent(event);
if (internal) {
addReplyInternalToEvent(event);
@ -559,7 +559,7 @@ WebContents.prototype._init = function () {
});
// The devtools requests the webContents to reload.
this.on('devtools-reload-page', function (this: Electron.WebContentsInternal) {
this.on('devtools-reload-page', function (this: Electron.WebContents) {
this.reload();
});
@ -582,7 +582,7 @@ WebContents.prototype._init = function () {
// Create a new browser window for the native implementation of
// "window.open", used in sandbox and nativeWindowOpen mode.
this.on('-add-new-contents' as any, (event: any, webContents: Electron.WebContentsInternal, disposition: string,
this.on('-add-new-contents' as any, (event: any, webContents: Electron.WebContents, disposition: string,
userGesture: boolean, left: number, top: number, width: number, height: number, url: string, frameName: string,
referrer: string, rawFeatures: string, postData: string) => {
if ((disposition !== 'foreground-tab' && disposition !== 'new-window' &&

View file

@ -14,13 +14,11 @@ export const handleSync = function <T extends IPCHandler> (channel: string, hand
let nextId = 0;
export function invokeInWebContents<T> (sender: Electron.WebContentsInternal, sendToAll: boolean, command: string, ...args: any[]) {
export function invokeInWebContents<T> (sender: Electron.WebContents, sendToAll: boolean, command: string, ...args: any[]) {
return new Promise<T>((resolve, reject) => {
const requestId = ++nextId;
const channel = `${command}_RESPONSE_${requestId}`;
ipcMainInternal.on(channel, function handler (
event, error: Electron.SerializedError, result: any
) {
ipcMainInternal.on(channel, function handler (event, error: Error, result: any) {
if (event.sender !== sender) {
console.error(`Reply to ${command} sent by unexpected WebContents (${event.sender.id})`);
return;