💄 Use ES6; clean up CoffeeScript conversion
💄 Destructure app module
Address linting errors
This commit is contained in:
parent
bebf8eabca
commit
236810a923
1 changed files with 69 additions and 95 deletions
|
@ -1,28 +1,24 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const ipcMain = require('electron').ipcMain
|
const {ipcMain} = require('electron')
|
||||||
const EventEmitter = require('events').EventEmitter
|
const {EventEmitter} = require('events')
|
||||||
const {BrowserWindow} = process.atomBinding('window')
|
const {BrowserWindow} = process.atomBinding('window')
|
||||||
|
|
||||||
Object.setPrototypeOf(BrowserWindow.prototype, EventEmitter.prototype)
|
Object.setPrototypeOf(BrowserWindow.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
BrowserWindow.prototype._init = function () {
|
BrowserWindow.prototype._init = function () {
|
||||||
// avoid recursive require.
|
// Avoid recursive require.
|
||||||
var app, menu
|
const {app} = require('electron')
|
||||||
app = require('electron').app
|
|
||||||
|
|
||||||
// Simulate the application menu on platforms other than OS X.
|
// Simulate the application menu on platforms other than OS X.
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
menu = app.getApplicationMenu()
|
const menu = app.getApplicationMenu()
|
||||||
if (menu != null) {
|
if (menu) this.setMenu(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) => {
|
||||||
var options
|
const options = {
|
||||||
options = {
|
|
||||||
show: true,
|
show: true,
|
||||||
width: 800,
|
width: 800,
|
||||||
height: 600
|
height: 600
|
||||||
|
@ -54,12 +50,14 @@ BrowserWindow.prototype._init = function () {
|
||||||
if (!event.defaultPrevented) this.setTitle(title)
|
if (!event.defaultPrevented) this.setTitle(title)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Sometimes the webContents doesn't get focus when window is shown, so we have
|
// Sometimes the webContents doesn't get focus when window is shown, so we
|
||||||
// to force focusing on webContents in this case. The safest way is to focus it
|
// have to force focusing on webContents in this case. The safest way is to
|
||||||
// when we first start to load URL, if we do it earlier it won't have effect,
|
// focus it when we first start to load URL, if we do it earlier it won't
|
||||||
// if we do it later we might move focus in the page.
|
// have effect, if we do it later we might move focus in the page.
|
||||||
|
//
|
||||||
// Though this hack is only needed on OS X when the app is launched from
|
// Though this hack is only needed on OS X when the app is launched from
|
||||||
// Finder, we still do it on all platforms in case of other bugs we don't know.
|
// Finder, we still do it on all platforms in case of other bugs we don't
|
||||||
|
// know.
|
||||||
this.webContents.once('load-url', function () {
|
this.webContents.once('load-url', function () {
|
||||||
this.focus()
|
this.focus()
|
||||||
})
|
})
|
||||||
|
@ -74,18 +72,18 @@ BrowserWindow.prototype._init = function () {
|
||||||
|
|
||||||
// Subscribe to visibilityState changes and pass to renderer process.
|
// Subscribe to visibilityState changes and pass to renderer process.
|
||||||
let isVisible = this.isVisible() && !this.isMinimized()
|
let isVisible = this.isVisible() && !this.isMinimized()
|
||||||
let visibilityChanged = () => {
|
const visibilityChanged = () => {
|
||||||
let newState = this.isVisible() && !this.isMinimized()
|
const newState = this.isVisible() && !this.isMinimized()
|
||||||
if (isVisible !== newState) {
|
if (isVisible !== newState) {
|
||||||
isVisible = newState
|
isVisible = newState
|
||||||
this.webContents.send('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', isVisible ? 'visible' : 'hidden')
|
this.webContents.send('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', isVisible ? 'visible' : 'hidden')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.on('show', visibilityChanged)
|
|
||||||
this.on('hide', visibilityChanged)
|
const visibilityEvents = ['show', 'hide', 'minimize', 'maximize', 'restore']
|
||||||
this.on('minimize', visibilityChanged)
|
for (let event of visibilityEvents) {
|
||||||
this.on('restore', visibilityChanged)
|
this.on(event, visibilityChanged)
|
||||||
this.on('maximize', visibilityChanged)
|
}
|
||||||
|
|
||||||
// Notify the creation of the window.
|
// Notify the creation of the window.
|
||||||
app.emit('browser-window-created', {}, this)
|
app.emit('browser-window-created', {}, this)
|
||||||
|
@ -93,90 +91,66 @@ BrowserWindow.prototype._init = function () {
|
||||||
Object.defineProperty(this, 'devToolsWebContents', {
|
Object.defineProperty(this, 'devToolsWebContents', {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: false,
|
configurable: false,
|
||||||
get: function () {
|
get () {
|
||||||
return this.webContents.devToolsWebContents
|
return this.webContents.devToolsWebContents
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserWindow.getFocusedWindow = function () {
|
BrowserWindow.getFocusedWindow = () => {
|
||||||
var i, len, window, windows
|
for (let window of BrowserWindow.getAllWindows()) {
|
||||||
windows = BrowserWindow.getAllWindows()
|
if (window.isFocused()) return window
|
||||||
for (i = 0, len = windows.length; i < len; i++) {
|
|
||||||
window = windows[i]
|
|
||||||
if (window.isFocused()) {
|
|
||||||
return window
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
BrowserWindow.fromWebContents = function (webContents) {
|
|
||||||
var i, len, ref1, window, windows
|
|
||||||
windows = BrowserWindow.getAllWindows()
|
|
||||||
for (i = 0, len = windows.length; i < len; i++) {
|
|
||||||
window = windows[i]
|
|
||||||
if ((ref1 = window.webContents) != null ? ref1.equal(webContents) : void 0) {
|
|
||||||
return window
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserWindow.fromDevToolsWebContents = function (webContents) {
|
BrowserWindow.fromWebContents = (webContents) => {
|
||||||
var i, len, ref1, window, windows
|
for (let window of BrowserWindow.getAllWindows()) {
|
||||||
windows = BrowserWindow.getAllWindows()
|
if (window.webContents.equal(webContents)) return window
|
||||||
for (i = 0, len = windows.length; i < len; i++) {
|
|
||||||
window = windows[i]
|
|
||||||
if ((ref1 = window.devToolsWebContents) != null ? ref1.equal(webContents) : void 0) {
|
|
||||||
return window
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BrowserWindow.fromDevToolsWebContents = (webContents) => {
|
||||||
|
for (let window of BrowserWindow.getAllWindows()) {
|
||||||
|
if (window.devToolsWebContents.equal(webContents)) return window
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helpers.
|
// Helpers.
|
||||||
|
|
||||||
BrowserWindow.prototype.loadURL = function () {
|
Object.assign(BrowserWindow.prototype, {
|
||||||
|
loadURL () {
|
||||||
return this.webContents.loadURL.apply(this.webContents, arguments)
|
return this.webContents.loadURL.apply(this.webContents, arguments)
|
||||||
}
|
},
|
||||||
|
getURL () {
|
||||||
BrowserWindow.prototype.getURL = function () {
|
|
||||||
return this.webContents.getURL()
|
return this.webContents.getURL()
|
||||||
}
|
},
|
||||||
|
reload () {
|
||||||
BrowserWindow.prototype.reload = function () {
|
|
||||||
return this.webContents.reload.apply(this.webContents, arguments)
|
return this.webContents.reload.apply(this.webContents, arguments)
|
||||||
}
|
},
|
||||||
|
send () {
|
||||||
BrowserWindow.prototype.send = function () {
|
|
||||||
return this.webContents.send.apply(this.webContents, arguments)
|
return this.webContents.send.apply(this.webContents, arguments)
|
||||||
}
|
},
|
||||||
|
openDevTools () {
|
||||||
BrowserWindow.prototype.openDevTools = function () {
|
|
||||||
return this.webContents.openDevTools.apply(this.webContents, arguments)
|
return this.webContents.openDevTools.apply(this.webContents, arguments)
|
||||||
}
|
},
|
||||||
|
closeDevTools () {
|
||||||
BrowserWindow.prototype.closeDevTools = function () {
|
|
||||||
return this.webContents.closeDevTools()
|
return this.webContents.closeDevTools()
|
||||||
}
|
},
|
||||||
|
isDevToolsOpened () {
|
||||||
BrowserWindow.prototype.isDevToolsOpened = function () {
|
|
||||||
return this.webContents.isDevToolsOpened()
|
return this.webContents.isDevToolsOpened()
|
||||||
}
|
},
|
||||||
|
isDevToolsFocused () {
|
||||||
BrowserWindow.prototype.isDevToolsFocused = function () {
|
|
||||||
return this.webContents.isDevToolsFocused()
|
return this.webContents.isDevToolsFocused()
|
||||||
}
|
},
|
||||||
|
toggleDevTools () {
|
||||||
BrowserWindow.prototype.toggleDevTools = function () {
|
|
||||||
return this.webContents.toggleDevTools()
|
return this.webContents.toggleDevTools()
|
||||||
}
|
},
|
||||||
|
inspectElement () {
|
||||||
BrowserWindow.prototype.inspectElement = function () {
|
|
||||||
return this.webContents.inspectElement.apply(this.webContents, arguments)
|
return this.webContents.inspectElement.apply(this.webContents, arguments)
|
||||||
}
|
},
|
||||||
|
inspectServiceWorker () {
|
||||||
BrowserWindow.prototype.inspectServiceWorker = function () {
|
|
||||||
return this.webContents.inspectServiceWorker()
|
return this.webContents.inspectServiceWorker()
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = BrowserWindow
|
module.exports = BrowserWindow
|
||||||
|
|
Loading…
Reference in a new issue