build: enable JS semicolons (#22783)
This commit is contained in:
parent
24e21467b9
commit
5d657dece4
354 changed files with 21512 additions and 21510 deletions
|
@ -1,44 +1,44 @@
|
|||
import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal'
|
||||
import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal';
|
||||
|
||||
type IPCHandler = (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any
|
||||
|
||||
export const handleSync = function <T extends IPCHandler> (channel: string, handler: T) {
|
||||
ipcMainInternal.on(channel, async (event, ...args) => {
|
||||
try {
|
||||
event.returnValue = [null, await handler(event, ...args)]
|
||||
event.returnValue = [null, await handler(event, ...args)];
|
||||
} catch (error) {
|
||||
event.returnValue = [error]
|
||||
event.returnValue = [error];
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let nextId = 0
|
||||
let nextId = 0;
|
||||
|
||||
export function invokeInWebContents<T> (sender: Electron.WebContentsInternal, sendToAll: boolean, command: string, ...args: any[]) {
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
const requestId = ++nextId
|
||||
const channel = `${command}_RESPONSE_${requestId}`
|
||||
const requestId = ++nextId;
|
||||
const channel = `${command}_RESPONSE_${requestId}`;
|
||||
ipcMainInternal.on(channel, function handler (
|
||||
event, error: Electron.SerializedError, result: any
|
||||
) {
|
||||
if (event.sender !== sender) {
|
||||
console.error(`Reply to ${command} sent by unexpected WebContents (${event.sender.id})`)
|
||||
return
|
||||
console.error(`Reply to ${command} sent by unexpected WebContents (${event.sender.id})`);
|
||||
return;
|
||||
}
|
||||
|
||||
ipcMainInternal.removeListener(channel, handler)
|
||||
ipcMainInternal.removeListener(channel, handler);
|
||||
|
||||
if (error) {
|
||||
reject(error)
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(result)
|
||||
resolve(result);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
if (sendToAll) {
|
||||
sender._sendInternalToAll(command, requestId, ...args)
|
||||
sender._sendInternalToAll(command, requestId, ...args);
|
||||
} else {
|
||||
sender._sendInternal(command, requestId, ...args)
|
||||
sender._sendInternal(command, requestId, ...args);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue