electron/lib/browser/api/app.js

73 lines
2 KiB
JavaScript
Raw Normal View History

'use strict'
const electron = require('electron')
const {deprecate, Menu} = electron
const {EventEmitter} = require('events')
2016-01-12 02:40:23 +00:00
const bindings = process.atomBinding('app')
const {app} = bindings
2016-01-12 02:40:23 +00:00
Object.setPrototypeOf(app, EventEmitter.prototype)
2016-01-12 02:40:23 +00:00
let appPath = null
Object.assign(app, {
getAppPath () { return appPath },
setAppPath (path) { appPath = path },
setApplicationMenu (menu) {
return Menu.setApplicationMenu(menu)
},
getApplicationMenu () {
return Menu.getApplicationMenu()
},
commandLine: {
appendSwitch: bindings.appendSwitch,
appendArgument: bindings.appendArgument
}
})
2016-01-12 02:40:23 +00:00
if (process.platform === 'darwin') {
app.dock = {
bounce (type = 'informational') {
return bindings.dockBounce(type)
2016-01-12 02:40:23 +00:00
},
cancelBounce: bindings.dockCancelBounce,
downloadFinished: bindings.dockDownloadFinished,
2016-01-12 02:40:23 +00:00
setBadge: bindings.dockSetBadgeText,
getBadge: bindings.dockGetBadgeText,
hide: bindings.dockHide,
show: bindings.dockShow,
setMenu: bindings.dockSetMenu,
setIcon: bindings.dockSetIcon
}
2016-01-12 02:40:23 +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 {
electron.session.defaultSession.allowNTLMCredentialsForDomains(domains)
}
}
2016-01-14 18:35:29 +00:00
// Routes the events to webContents.
const events = ['login', 'certificate-error', 'select-client-certificate']
for (let name of events) {
app.on(name, (event, webContents, ...args) => {
2016-05-19 22:28:08 +00:00
webContents.emit.apply(webContents, [name, event].concat(args))
})
}
2016-01-12 02:40:23 +00:00
2016-01-14 18:35:29 +00:00
// Wrappers for native classes.
2016-05-14 23:43:30 +00:00
process.atomBinding('download_item')._setWrapDownloadItem((downloadItem) => {
2016-01-14 18:35:29 +00:00
// downloadItem is an EventEmitter.
Object.setPrototypeOf(downloadItem, EventEmitter.prototype)
})
2016-01-12 02:40:23 +00:00
2016-01-14 18:35:29 +00:00
// Only one App object pemitted.
module.exports = app