electron/lib/browser/api/app.js

114 lines
3.3 KiB
JavaScript
Raw Normal View History

'use strict'
2016-06-22 22:21:45 +00:00
const bindings = process.atomBinding('app')
const commandLine = process.atomBinding('command_line')
const path = require('path')
2018-09-13 16:10:51 +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')
2018-09-13 16:10:51 +00:00
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: {
hasSwitch: (...args) => commandLine.hasSwitch(...args.map(String)),
getSwitchValue: (...args) => commandLine.getSwitchValue(...args.map(String)),
appendSwitch: (...args) => commandLine.appendSwitch(...args.map(String)),
appendArgument: (...args) => commandLine.appendArgument(...args.map(String))
},
enableMixedSandbox () {
deprecate.log(`'enableMixedSandbox' is deprecated. Mixed-sandbox mode is now enabled by default. You can safely remove the call to enableMixedSandbox().`)
}
})
2016-01-12 02:40:23 +00:00
app.getFileIcon = deprecate.promisify(app.getFileIcon)
const nativeAppMetrics = app.getAppMetrics
app.getAppMetrics = () => {
const metrics = nativeAppMetrics.call(app)
for (const metric of metrics) {
if ('memory' in metric) {
deprecate.removeProperty(metric, 'memory')
}
}
return metrics
}
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) {
deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains')
const 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 (const 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.
2018-09-13 16:10:51 +00:00
const { DownloadItem } = process.atomBinding('download_item')
2016-08-02 11:38:35 +00:00
Object.setPrototypeOf(DownloadItem.prototype, EventEmitter.prototype)