refactor: Split 'Event' docs/types into more specific Event types (#17038)
* Event = Base event type (with preventDefault) * IpcMainEvent = Event that ipcMain emits (with sender, reply, etc.) * IpcRendererEvent = Event that ipcRenderer emits (with sender, senderId, etc.) * KeyboardEvent = Event that we emit with keyboard flags (ctrlKey, altKey, etc.) This will dramatically improve peoples TS experience with IPC events
This commit is contained in:
parent
ef2e7d95fe
commit
3b74837020
22 changed files with 515 additions and 285 deletions
|
@ -84,7 +84,7 @@ const injectContentScript = function (extensionId: string, script: Electron.Cont
|
|||
|
||||
// Handle the request of chrome.tabs.executeJavaScript.
|
||||
ipcRendererInternal.on('CHROME_TABS_EXECUTESCRIPT', function (
|
||||
event: Electron.Event,
|
||||
event,
|
||||
senderWebContentsId: number,
|
||||
requestId: number,
|
||||
extensionId: string,
|
||||
|
|
|
@ -7,7 +7,7 @@ export function invoke<T> (command: string, ...args: any[]) {
|
|||
return new Promise<T>((resolve, reject) => {
|
||||
const requestId = ++nextId
|
||||
ipcRendererInternal.once(`${command}_RESPONSE_${requestId}`, (
|
||||
_event: Electron.Event, error: Electron.SerializedError, result: any
|
||||
_event, error: Electron.SerializedError, result: any
|
||||
) => {
|
||||
if (error) {
|
||||
reject(errorUtils.deserialize(error))
|
||||
|
|
|
@ -11,7 +11,7 @@ type WebFrameMethod = {
|
|||
export const webFrameInit = () => {
|
||||
// Call webFrame method
|
||||
ipcRendererInternal.on('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', (
|
||||
_event: Electron.Event, method: keyof WebFrameMethod, args: any[]
|
||||
_event, method: keyof WebFrameMethod, args: any[]
|
||||
) => {
|
||||
// The TypeScript compiler cannot handle the sheer number of
|
||||
// call signatures here and simply gives up. Incorrect invocations
|
||||
|
@ -20,7 +20,7 @@ export const webFrameInit = () => {
|
|||
})
|
||||
|
||||
ipcRendererInternal.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (
|
||||
event: Electron.Event, requestId: number, method: keyof WebFrameMethod, args: any[]
|
||||
event, requestId: number, method: keyof WebFrameMethod, args: any[]
|
||||
) => {
|
||||
new Promise(resolve =>
|
||||
// The TypeScript compiler cannot handle the sheer number of
|
||||
|
|
|
@ -206,7 +206,7 @@ export const windowSetup = (
|
|||
}
|
||||
|
||||
ipcRendererInternal.on('ELECTRON_GUEST_WINDOW_POSTMESSAGE', function (
|
||||
_event: Electron.Event, sourceId: number, message: any, sourceOrigin: string
|
||||
_event, sourceId: number, message: any, sourceOrigin: string
|
||||
) {
|
||||
// Manually dispatch event instead of using postMessage because we also need to
|
||||
// set event.source.
|
||||
|
@ -253,7 +253,7 @@ export const windowSetup = (
|
|||
let cachedVisibilityState = isHiddenPage ? 'hidden' : 'visible'
|
||||
|
||||
// Subscribe to visibilityState changes.
|
||||
ipcRendererInternal.on('ELECTRON_GUEST_INSTANCE_VISIBILITY_CHANGE', function (_event: Electron.Event, visibilityState: VisibilityState) {
|
||||
ipcRendererInternal.on('ELECTRON_GUEST_INSTANCE_VISIBILITY_CHANGE', function (_event, visibilityState: VisibilityState) {
|
||||
if (cachedVisibilityState !== visibilityState) {
|
||||
cachedVisibilityState = visibilityState
|
||||
document.dispatchEvent(new Event('visibilitychange'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue