本文整理汇总了TypeScript中electron.BrowserWindow.fromWebContents方法的典型用法代码示例。如果您正苦于以下问题:TypeScript BrowserWindow.fromWebContents方法的具体用法?TypeScript BrowserWindow.fromWebContents怎么用?TypeScript BrowserWindow.fromWebContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.BrowserWindow
的用法示例。
在下文中一共展示了BrowserWindow.fromWebContents方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: findMenuItemByID
(event: Electron.IpcMessageEvent, { id }: { id: string }) => {
const menuItem = findMenuItemByID(menu, id)
if (menuItem) {
const window = BrowserWindow.fromWebContents(event.sender)
const fakeEvent = { preventDefault: () => {}, sender: event.sender }
menuItem.click(fakeEvent, window, event.sender)
}
}
示例2: buildContextMenu
(event: Electron.IpcMessageEvent, items: ReadonlyArray<IMenuItem>) => {
const menu = buildContextMenu(items, ix =>
event.sender.send('contextual-menu-action', ix)
)
const window = BrowserWindow.fromWebContents(event.sender)
menu.popup({ window })
}
示例3: createMenu
ipcMain.on(CONTEXT_MENU_CHANNEL, (event: Event, contextMenuId: number, items: ISerializableContextMenuItem[], onClickChannel: string, options?: IPopupOptions) => {
const menu = createMenu(event, onClickChannel, items);
menu.popup({
window: BrowserWindow.fromWebContents(event.sender),
x: options ? options.x : void 0,
y: options ? options.y : void 0,
positioningItem: options ? options.positioningItem : void 0,
callback: () => {
event.sender.send(CONTEXT_MENU_CLOSE_CHANNEL, contextMenuId);
}
});
});
示例4: Menu
(event: Electron.IpcMessageEvent, items: ReadonlyArray<any>) => {
const menu = new Menu()
const menuItems = items.map((item, i) => {
return new MenuItem({
label: item.label,
click: () => event.sender.send('contextual-menu-action', i),
type: item.type,
enabled: item.enabled,
})
})
for (const item of menuItems) {
menu.append(item)
}
const window = BrowserWindow.fromWebContents(event.sender)
menu.popup(window, { async: true })
}
示例5: createMenu
ipcMain.on(CONTEXT_MENU_CHANNEL, (event: Event, contextMenuId: number, items: ISerializableContextMenuItem[], onClickChannel: string, options?: IPopupOptions) => {
const menu = createMenu(event, onClickChannel, items);
menu.popup({
window: BrowserWindow.fromWebContents(event.sender),
x: options ? options.x : undefined,
y: options ? options.y : undefined,
positioningItem: options ? options.positioningItem : undefined,
callback: () => {
// Workaround for https://github.com/Microsoft/vscode/issues/72447
// It turns out that the menu gets GC'ed if not referenced anymore
// As such we drag it into this scope so that it is not being GC'ed
if (menu) {
event.sender.send(CONTEXT_MENU_CLOSE_CHANNEL, contextMenuId);
}
}
});
});
示例6: Menu
(event: Electron.IpcMessageEvent, items: ReadonlyArray<any>) => {
const menu = new Menu()
const menuItems = items.map((item, i) => {
return new MenuItem({
label: item.label,
click: () => event.sender.send('contextual-menu-action', i),
type: item.type,
enabled: item.enabled,
})
})
for (const item of menuItems) {
menu.append(item)
}
const window = BrowserWindow.fromWebContents(event.sender)
// TODO: read https://github.com/desktop/desktop/issues/1003
// to clean up this sin against T Y P E S
const anyMenu: any = menu
anyMenu.popup(window, { async: true })
}