2016-03-24 20:15:04 +00:00
|
|
|
'use strict'
|
2016-03-10 19:54:17 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
const deprecate = require('electron').deprecate
|
|
|
|
const session = require('electron').session
|
|
|
|
const Menu = require('electron').Menu
|
|
|
|
const EventEmitter = require('events').EventEmitter
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +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
|
|
|
|
2016-03-29 00:51:11 +00:00
|
|
|
Object.setPrototypeOf(app, EventEmitter.prototype)
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
app.setApplicationMenu = function (menu) {
|
|
|
|
return Menu.setApplicationMenu(menu)
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +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-03-24 20:15:04 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
app.dock = {
|
2016-03-24 20:15:04 +00:00
|
|
|
bounce: function (type) {
|
2016-01-12 02:40:23 +00:00
|
|
|
if (type == null) {
|
2016-03-24 20:15:04 +00:00
|
|
|
type = 'informational'
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:15:04 +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,
|
2016-01-23 23:30:14 +00:00
|
|
|
setMenu: bindings.dockSetMenu,
|
|
|
|
setIcon: bindings.dockSetIcon
|
2016-03-24 20:15:04 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
var appPath = null
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
app.setAppPath = function (path) {
|
2016-03-29 01:00:30 +00:00
|
|
|
appPath = path
|
2016-03-24 20:15:04 +00:00
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +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.
|
2016-03-24 20:15:04 +00:00
|
|
|
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++) {
|
2016-03-24 20:15:04 +00:00
|
|
|
fn(ref1[i])
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Deprecated.
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
app.getHomeDir = deprecate('app.getHomeDir', 'app.getPath', function () {
|
|
|
|
return this.getPath('home')
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
app.getDataPath = deprecate('app.getDataPath', 'app.getPath', function () {
|
|
|
|
return this.getPath('userData')
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
app.setDataPath = deprecate('app.setDataPath', 'app.setPath', function (path) {
|
|
|
|
return this.setPath('userData', path)
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
app.resolveProxy = deprecate('app.resolveProxy', 'session.defaultSession.resolveProxy', function (url, callback) {
|
|
|
|
return session.defaultSession.resolveProxy(url, callback)
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
deprecate.rename(app, 'terminate', 'quit')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
deprecate.event(app, 'finish-launching', 'ready', function () {
|
2016-01-14 18:35:29 +00:00
|
|
|
// give default app a chance to setup default menu.
|
2016-03-10 19:54:17 +00:00
|
|
|
setImmediate(() => {
|
2016-03-24 20:15:04 +00:00
|
|
|
this.emit('finish-launching')
|
|
|
|
})
|
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
deprecate.event(app, 'activate-with-no-open-windows', 'activate', function (event, hasVisibleWindows) {
|
2016-01-12 02:40:23 +00:00
|
|
|
if (!hasVisibleWindows) {
|
2016-03-24 20:15:04 +00:00
|
|
|
return this.emit('activate-with-no-open-windows', event)
|
2016-01-12 02:40:23 +00:00
|
|
|
}
|
2016-03-24 20:15:04 +00:00
|
|
|
})
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +00:00
|
|
|
deprecate.event(app, 'select-certificate', 'select-client-certificate')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Wrappers for native classes.
|
2016-03-24 20:15:04 +00:00
|
|
|
var wrapDownloadItem = function (downloadItem) {
|
2016-01-14 18:35:29 +00:00
|
|
|
// downloadItem is an EventEmitter.
|
2016-03-29 00:51:11 +00:00
|
|
|
Object.setPrototypeOf(downloadItem, EventEmitter.prototype)
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-01-14 18:35:29 +00:00
|
|
|
// Deprecated.
|
2016-03-24 20:15:04 +00:00
|
|
|
deprecate.property(downloadItem, 'url', 'getURL')
|
|
|
|
deprecate.property(downloadItem, 'filename', 'getFilename')
|
|
|
|
deprecate.property(downloadItem, 'mimeType', 'getMimeType')
|
|
|
|
return deprecate.rename(downloadItem, 'getUrl', 'getURL')
|
|
|
|
}
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2016-03-24 20:15:04 +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.
|
2016-03-24 20:15:04 +00:00
|
|
|
module.exports = app
|