Make BrowserWindow inheirt TopLevelWindow in JS

This commit is contained in:
Cheng Zhao 2018-04-17 16:46:32 +09:00
parent 71ebd99dfa
commit e38f511737
3 changed files with 18 additions and 12 deletions

View file

@ -1,22 +1,18 @@
'use strict'
const electron = require('electron')
const {ipcMain} = electron
const {EventEmitter} = require('events')
const {ipcMain, TopLevelWindow} = electron
const {BrowserWindow} = process.atomBinding('window')
const v8Util = process.atomBinding('v8_util')
Object.setPrototypeOf(BrowserWindow.prototype, EventEmitter.prototype)
Object.setPrototypeOf(BrowserWindow.prototype, TopLevelWindow.prototype)
BrowserWindow.prototype._init = function () {
// Avoid recursive require.
const {app} = require('electron')
// Call parent class's _init.
TopLevelWindow.prototype._init.call(this)
// Simulate the application menu on platforms other than macOS.
if (process.platform !== 'darwin') {
const menu = app.getApplicationMenu()
if (menu) this.setMenu(menu)
}
// Avoid recursive require.
const {app} = electron
// Make new windows requested by links behave like "window.open"
this.webContents.on('-new-window', (event, url, frameName, disposition,