2016-03-24 20:15:04 +00:00
|
|
|
'use strict'
|
2016-03-10 19:54:17 +00:00
|
|
|
|
2016-06-22 22:21:45 +00:00
|
|
|
const bindings = process.atomBinding('app')
|
2018-05-08 06:15:31 +00:00
|
|
|
const path = require('path')
|
2016-08-02 11:38:35 +00:00
|
|
|
const {app, App} = bindings
|
2016-06-22 22:21:45 +00:00
|
|
|
|
|
|
|
// Only one app object permitted.
|
|
|
|
module.exports = app
|
|
|
|
|
2016-06-01 05:57:35 +00:00
|
|
|
const electron = require('electron')
|
|
|
|
const {deprecate, Menu} = electron
|
2016-05-14 15:17:46 +00:00
|
|
|
const {EventEmitter} = require('events')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2018-02-27 06:15:06 +00:00
|
|
|
let dockMenu = null
|
2018-04-20 07:09:23 +00:00
|
|
|
let readyPromise = null
|
2018-02-27 06:15:06 +00:00
|
|
|
|
2017-11-02 04:05:27 +00:00
|
|
|
// App is an EventEmitter.
|
2016-08-02 11:38:35 +00:00
|
|
|
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
|
2017-11-02 04:05:27 +00:00
|
|
|
EventEmitter.call(app)
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-05-14 15:17:46 +00:00
|
|
|
Object.assign(app, {
|
2018-04-20 07:09:23 +00:00
|
|
|
whenReady () {
|
|
|
|
if (readyPromise !== null) {
|
|
|
|
return readyPromise
|
|
|
|
}
|
|
|
|
|
|
|
|
if (app.isReady()) {
|
|
|
|
readyPromise = Promise.resolve()
|
|
|
|
} else {
|
|
|
|
readyPromise = new Promise(resolve => {
|
|
|
|
// XXX(alexeykuzmin): Explicitly ignore any data
|
|
|
|
// passed to the event handler to avoid memory leaks.
|
|
|
|
app.once('ready', () => resolve())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return readyPromise
|
|
|
|
},
|
2016-05-14 15:31:08 +00:00
|
|
|
setApplicationMenu (menu) {
|
2016-05-14 15:17:46 +00:00
|
|
|
return Menu.setApplicationMenu(menu)
|
|
|
|
},
|
2016-05-14 15:31:08 +00:00
|
|
|
getApplicationMenu () {
|
2016-05-14 15:17:46 +00:00
|
|
|
return Menu.getApplicationMenu()
|
|
|
|
},
|
|
|
|
commandLine: {
|
2016-09-16 18:43:48 +00:00
|
|
|
appendSwitch (...args) {
|
|
|
|
const castedArgs = args.map((arg) => {
|
2016-09-16 18:43:48 +00:00
|
|
|
return typeof arg !== 'string' ? `${arg}` : arg
|
|
|
|
})
|
2016-09-19 16:31:49 +00:00
|
|
|
return bindings.appendSwitch(...castedArgs)
|
2016-09-16 18:43:48 +00:00
|
|
|
},
|
2016-09-16 18:43:48 +00:00
|
|
|
appendArgument (...args) {
|
2016-09-19 16:31:49 +00:00
|
|
|
const castedArgs = args.map((arg) => {
|
2016-09-16 18:43:48 +00:00
|
|
|
return typeof arg !== 'string' ? `${arg}` : arg
|
|
|
|
})
|
2016-09-19 16:31:49 +00:00
|
|
|
return bindings.appendArgument(...castedArgs)
|
2016-09-16 18:43:48 +00:00
|
|
|
}
|
2016-05-14 15:17:46 +00:00
|
|
|
}
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2018-06-27 09:07:39 +00:00
|
|
|
const nativeFn = app.getAppMetrics
|
|
|
|
app.getAppMetrics = () => {
|
|
|
|
deprecate.removeProperty(nativeFn, 'privateBytes')
|
|
|
|
deprecate.removeProperty(nativeFn, 'sharedBytes')
|
|
|
|
return nativeFn.call(app)
|
|
|
|
}
|
|
|
|
|
2018-05-08 06:15:31 +00:00
|
|
|
app.isPackaged = (() => {
|
|
|
|
const execFile = path.basename(process.execPath).toLowerCase()
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
return execFile !== 'electron.exe'
|
|
|
|
}
|
|
|
|
return execFile !== 'electron'
|
|
|
|
})()
|
|
|
|
|
2016-01-12 02:40:23 +00:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
app.dock = {
|
2016-05-14 15:17:46 +00:00
|
|
|
bounce (type = 'informational') {
|
2016-03-24 20:15:04 +00:00
|
|
|
return bindings.dockBounce(type)
|
2016-01-12 02:40:23 +00:00
|
|
|
},
|
|
|
|
cancelBounce: bindings.dockCancelBounce,
|
2016-05-10 19:02:56 +00:00
|
|
|
downloadFinished: bindings.dockDownloadFinished,
|
2016-01-12 02:40:23 +00:00
|
|
|
setBadge: bindings.dockSetBadgeText,
|
|
|
|
getBadge: bindings.dockGetBadgeText,
|
|
|
|
hide: bindings.dockHide,
|
|
|
|
show: bindings.dockShow,
|
2016-08-01 22:22:37 +00:00
|
|
|
isVisible: bindings.dockIsVisible,
|
2018-02-27 06:15:06 +00:00
|
|
|
setMenu (menu) {
|
|
|
|
dockMenu = menu
|
|
|
|
bindings.dockSetMenu(menu)
|
|
|
|
},
|
|
|
|
getMenu () {
|
|
|
|
return dockMenu
|
|
|
|
},
|
2016-01-23 23:30:14 +00:00
|
|
|
setIcon: bindings.dockSetIcon
|
2016-03-24 20:15:04 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2016-06-26 09:48:58 +00:00
|
|
|
if (process.platform === 'linux') {
|
|
|
|
app.launcher = {
|
2016-06-25 23:55:24 +00:00
|
|
|
setBadgeCount: bindings.unityLauncherSetBadgeCount,
|
2016-06-26 09:48:58 +00:00
|
|
|
getBadgeCount: bindings.unityLauncherGetBadgeCount,
|
2016-06-29 17:23:56 +00:00
|
|
|
isCounterBadgeAvailable: bindings.unityLauncherAvailable,
|
|
|
|
isUnityRunning: bindings.unityLauncherAvailable
|
2016-06-26 00:00:41 +00:00
|
|
|
}
|
2016-06-25 23:55:24 +00:00
|
|
|
}
|
|
|
|
|
2016-05-23 05:29:55 +00:00
|
|
|
app.allowNTLMCredentialsForAllDomains = function (allow) {
|
|
|
|
if (!process.noDeprecations) {
|
|
|
|
deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains')
|
|
|
|
}
|
|
|
|
let domains = allow ? '*' : ''
|
|
|
|
if (!this.isReady()) {
|
|
|
|
this.commandLine.appendSwitch('auth-server-whitelist', domains)
|
|
|
|
} else {
|
2016-06-01 05:57:35 +00:00
|
|
|
electron.session.defaultSession.allowNTLMCredentialsForDomains(domains)
|
2016-05-23 05:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Routes the events to webContents.
|
2016-05-14 15:17:46 +00:00
|
|
|
const events = ['login', 'certificate-error', 'select-client-certificate']
|
|
|
|
for (let name of events) {
|
|
|
|
app.on(name, (event, webContents, ...args) => {
|
2016-12-01 22:37:03 +00:00
|
|
|
webContents.emit(name, event, ...args)
|
2016-03-24 20:15:04 +00:00
|
|
|
})
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2018-05-07 15:29:18 +00:00
|
|
|
// TODO(MarshallOfSound): Remove in 4.0
|
|
|
|
app.releaseSingleInstance = () => {
|
|
|
|
deprecate.warn('app.releaseSingleInstance(cb)', 'app.releaseSingleInstanceLock()')
|
|
|
|
app.releaseSingleInstanceLock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(MarshallOfSound): Remove in 4.0
|
|
|
|
app.makeSingleInstance = (oldStyleFn) => {
|
|
|
|
deprecate.warn('app.makeSingleInstance(cb)', 'app.requestSingleInstanceLock() and app.on(\'second-instance\', cb)')
|
|
|
|
if (oldStyleFn && typeof oldStyleFn === 'function') {
|
|
|
|
app.on('second-instance', (event, ...args) => oldStyleFn(...args))
|
|
|
|
}
|
|
|
|
return !app.requestSingleInstanceLock()
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Wrappers for native classes.
|
2016-08-02 11:38:35 +00:00
|
|
|
const {DownloadItem} = process.atomBinding('download_item')
|
|
|
|
Object.setPrototypeOf(DownloadItem.prototype, EventEmitter.prototype)
|