electron/lib/browser/api/app.js

113 lines
3 KiB
JavaScript
Raw Normal View History

'use strict'
2016-06-22 22:21:45 +00:00
const bindings = process.atomBinding('app')
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
const electron = require('electron')
const {deprecate, Menu} = electron
const {EventEmitter} = require('events')
2016-01-12 02:40:23 +00:00
let dockMenu = null
// App is an EventEmitter.
2016-08-02 11:38:35 +00:00
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
EventEmitter.call(app)
2016-01-12 02:40:23 +00:00
Object.assign(app, {
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
const nativeFn = app.getAppMetrics
app.getAppMetrics = () => {
deprecate.removeProperty(nativeFn, 'privateBytes')
deprecate.removeProperty(nativeFn, 'sharedBytes')
return nativeFn.call(app)
}
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 = {
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 (menu) {
dockMenu = menu
bindings.dockSetMenu(menu)
},
getMenu () {
return dockMenu
},
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) => {
webContents.emit(name, event, ...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)