electron/lib/browser/api/app.js

76 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict'
const electron = require('electron')
2016-04-28 16:38:05 +00:00
const {session, Menu} = electron
const EventEmitter = require('events').EventEmitter
2016-01-12 02:40:23 +00:00
const bindings = process.atomBinding('app')
const downloadItemBindings = process.atomBinding('download_item')
const app = bindings.app
2016-01-12 02:40:23 +00:00
Object.setPrototypeOf(app, EventEmitter.prototype)
2016-01-12 02:40:23 +00:00
app.setApplicationMenu = function (menu) {
return Menu.setApplicationMenu(menu)
}
2016-01-12 02:40:23 +00:00
app.getApplicationMenu = function () {
return Menu.getApplicationMenu()
}
2016-01-12 02:40:23 +00:00
app.commandLine = {
appendSwitch: bindings.appendSwitch,
appendArgument: bindings.appendArgument
}
2016-01-12 02:40:23 +00:00
if (process.platform === 'darwin') {
app.dock = {
bounce: function (type) {
2016-01-12 02:40:23 +00:00
if (type == null) {
type = 'informational'
2016-01-12 02:40:23 +00:00
}
return bindings.dockBounce(type)
2016-01-12 02:40:23 +00:00
},
cancelBounce: bindings.dockCancelBounce,
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
}
var appPath = null
2016-01-12 02:40:23 +00:00
app.setAppPath = function (path) {
2016-03-29 01:00:30 +00:00
appPath = path
}
2016-01-12 02:40:23 +00:00
app.getAppPath = function () {
return appPath
}
2016-01-12 02:40:23 +00:00
2016-01-14 18:35:29 +00:00
// Routes the events to webContents.
var ref1 = ['login', 'certificate-error', 'select-client-certificate']
var fn = function (name) {
return app.on(name, function (event, webContents, ...args) {
return webContents.emit.apply(webContents, [name, event].concat(args))
})
}
var i, len
2016-01-12 02:40:23 +00:00
for (i = 0, len = ref1.length; i < len; i++) {
fn(ref1[i])
2016-01-12 02:40:23 +00:00
}
2016-01-14 18:35:29 +00:00
// Wrappers for native classes.
var wrapDownloadItem = function (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
downloadItemBindings._setWrapDownloadItem(wrapDownloadItem)
2016-01-12 02:40:23 +00:00
2016-01-14 18:35:29 +00:00
// Only one App object pemitted.
module.exports = app