Export app before requiring modules

This commit is contained in:
Kevin Sawicki 2016-06-22 15:21:45 -07:00
parent 4dbdcad05e
commit be642612c0
2 changed files with 8 additions and 10 deletions

View file

@ -1,12 +1,15 @@
'use strict' 'use strict'
const bindings = process.atomBinding('app')
const {app} = bindings
// Only one app object permitted.
module.exports = app
const electron = require('electron') const electron = require('electron')
const {deprecate, Menu} = electron const {deprecate, Menu} = electron
const {EventEmitter} = require('events') const {EventEmitter} = require('events')
const bindings = process.atomBinding('app')
const {app} = bindings
Object.setPrototypeOf(app, EventEmitter.prototype) Object.setPrototypeOf(app, EventEmitter.prototype)
let appPath = null let appPath = null
@ -67,6 +70,3 @@ process.atomBinding('download_item')._setWrapDownloadItem((downloadItem) => {
// downloadItem is an EventEmitter. // downloadItem is an EventEmitter.
Object.setPrototypeOf(downloadItem, EventEmitter.prototype) Object.setPrototypeOf(downloadItem, EventEmitter.prototype)
}) })
// Only one App object pemitted.
module.exports = app

View file

@ -1,7 +1,8 @@
const {app} = require('electron')
const roles = { const roles = {
about: { about: {
get label () { get label () {
const {app} = require('electron')
return `About ${app.getName()}` return `About ${app.getName()}`
} }
}, },
@ -33,7 +34,6 @@ const roles = {
}, },
hide: { hide: {
get label () { get label () {
const {app} = require('electron')
return `Hide ${app.getName()}` return `Hide ${app.getName()}`
}, },
accelerator: 'Command+H' accelerator: 'Command+H'
@ -59,7 +59,6 @@ const roles = {
}, },
quit: { quit: {
get label () { get label () {
const {app} = require('electron')
return process.platform === 'win32' ? 'Exit' : `Quit ${app.getName()}` return process.platform === 'win32' ? 'Exit' : `Quit ${app.getName()}`
}, },
accelerator: process.platform === 'win32' ? null : 'Command+Q', accelerator: process.platform === 'win32' ? null : 'Command+Q',
@ -120,7 +119,6 @@ exports.execute = function (role, focusedWindow) {
const {appMethod, webContentsMethod, windowMethod} = roles[role] const {appMethod, webContentsMethod, windowMethod} = roles[role]
if (appMethod) { if (appMethod) {
const {app} = require('electron')
app[appMethod]() app[appMethod]()
return true return true
} }