electron/lib/browser/api/app.js

91 lines
2.6 KiB
JavaScript
Raw Normal View History

'use strict'
2016-06-22 22:21:45 +00:00
const bindings = process.atomBinding('app')
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
const electron = require('electron')
const {deprecate, Menu} = electron
const {EventEmitter} = require('events')
2016-01-12 02:40:23 +00:00
2016-08-02 11:38:35 +00:00
Object.setPrototypeOf(App.prototype, 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 (...args) {
const castedArgs = args.map((arg) => {
return typeof arg !== 'string' ? `${arg}` : arg
})
2016-09-19 16:31:49 +00:00
return bindings.appendSwitch(...castedArgs)
},
appendArgument (...args) {
2016-09-19 16:31:49 +00:00
const castedArgs = args.map((arg) => {
return typeof arg !== 'string' ? `${arg}` : arg
})
2016-09-19 16:31:49 +00:00
return bindings.appendArgument(...castedArgs)
}
}
})
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,
2016-08-01 22:22:37 +00:00
isVisible: bindings.dockIsVisible,
setMenu: bindings.dockSetMenu,
setIcon: bindings.dockSetIcon
}
2016-01-12 02:40:23 +00:00
}
if (process.platform === 'linux') {
app.launcher = {
setBadgeCount: bindings.unityLauncherSetBadgeCount,
getBadgeCount: bindings.unityLauncherGetBadgeCount,
isCounterBadgeAvailable: bindings.unityLauncherAvailable,
isUnityRunning: bindings.unityLauncherAvailable
2016-06-26 00:00:41 +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-08-02 11:38:35 +00:00
const {DownloadItem} = process.atomBinding('download_item')
Object.setPrototypeOf(DownloadItem.prototype, EventEmitter.prototype)