electron/lib/browser/api/app.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

'use strict'
2016-04-28 18:07:34 +00:00
const {Menu} = require('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
}
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) => {
return 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