Skip to content

Commit

Permalink
Add WebContents to browserWindow TypeScript type (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffflorian authored Feb 1, 2020
1 parent 5b36497 commit 1410532
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
11 changes: 6 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
WebviewTag,
ContextMenuParams,
MenuItemConstructorOptions,
Event as ElectronEvent
Event as ElectronEvent,
WebContents
} from 'electron';

declare namespace contextMenu {
Expand Down Expand Up @@ -95,7 +96,7 @@ declare namespace contextMenu {
Window or WebView to add the context menu to.
When not specified, the context menu will be added to all existing and new windows.
*/
readonly window?: BrowserWindow | WebviewTag;
readonly window?: BrowserWindow | WebviewTag | WebContents;

/**
Should return an array of [menu items](https://electronjs.org/docs/api/menu-item) to be prepended to the context menu.
Expand All @@ -105,7 +106,7 @@ declare namespace contextMenu {
readonly prepend?: (
defaultActions: Actions,
params: ContextMenuParams,
browserWindow: BrowserWindow | WebviewTag
browserWindow: BrowserWindow | WebviewTag | WebContents
) => MenuItemConstructorOptions[];

/**
Expand All @@ -116,7 +117,7 @@ declare namespace contextMenu {
readonly append?: (
defaultActions: Actions,
param: ContextMenuParams,
browserWindow: BrowserWindow | WebviewTag
browserWindow: BrowserWindow | WebviewTag | WebContents
) => MenuItemConstructorOptions[];

/**
Expand Down Expand Up @@ -220,7 +221,7 @@ declare namespace contextMenu {
readonly menu?: (
defaultActions: Actions,
params: ContextMenuParams,
browserWindow: BrowserWindow | WebviewTag
browserWindow: BrowserWindow | WebviewTag | WebContents
) => MenuItemConstructorOptions[];
}
}
Expand Down
11 changes: 11 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {expectType} from 'tsd';
import {app, BrowserWindow, shell} from 'electron';
import contextMenu = require('.');

expectType<void>(contextMenu());
Expand All @@ -11,3 +12,13 @@ contextMenu({
}
]
});

app.on('web-contents-created', (event, webContents) => {
contextMenu({
prepend: (defaultActions, params) => [{
label: 'Rainbow',
visible: params.mediaType === 'image'
}],
window: webContents
});
})
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Type: `object`

#### window

Type: `BrowserWindow | WebView`
Type: `BrowserWindow | WebViewTag | WebContents`

Window or WebView to add the context menu to.

Expand Down

0 comments on commit 1410532

Please sign in to comment.