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

@ -397,7 +397,6 @@ mate::WrappableBase* BrowserWindow::New(mate::Arguments* args) {
// static // static
void BrowserWindow::BuildPrototype(v8::Isolate* isolate, void BrowserWindow::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) { v8::Local<v8::FunctionTemplate> prototype) {
TopLevelWindow::BuildPrototype(isolate, prototype);
prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow")); prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("focusOnWebView", &BrowserWindow::FocusOnWebView) .SetMethod("focusOnWebView", &BrowserWindow::FocusOnWebView)

View file

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

View file

@ -1,9 +1,20 @@
'use strict' 'use strict'
const electron = require('electron')
const {EventEmitter} = require('events') const {EventEmitter} = require('events')
const {TopLevelWindow} = process.atomBinding('top_level_window') const {TopLevelWindow} = process.atomBinding('top_level_window')
const v8Util = process.atomBinding('v8_util')
Object.setPrototypeOf(TopLevelWindow.prototype, EventEmitter.prototype) Object.setPrototypeOf(TopLevelWindow.prototype, EventEmitter.prototype)
TopLevelWindow.prototype._init = function () {
// Avoid recursive require.
const {app} = electron
// Simulate the application menu on platforms other than macOS.
if (process.platform !== 'darwin') {
const menu = app.getApplicationMenu()
if (menu) this.setMenu(menu)
}
}
module.exports = TopLevelWindow module.exports = TopLevelWindow