electron/lib/browser/api/app.js

118 lines
3.1 KiB
JavaScript
Raw Normal View History

'use strict'
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
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
// Deprecated.
2016-01-12 02:40:23 +00:00
app.getHomeDir = deprecate('app.getHomeDir', 'app.getPath', function () {
return this.getPath('home')
})
2016-01-12 02:40:23 +00:00
app.getDataPath = deprecate('app.getDataPath', 'app.getPath', function () {
return this.getPath('userData')
})
2016-01-12 02:40:23 +00:00
app.setDataPath = deprecate('app.setDataPath', 'app.setPath', function (path) {
return this.setPath('userData', path)
})
2016-01-12 02:40:23 +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
deprecate.rename(app, 'terminate', 'quit')
2016-01-12 02:40:23 +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.
setImmediate(() => {
this.emit('finish-launching')
})
})
2016-01-12 02:40:23 +00:00
deprecate.event(app, 'activate-with-no-open-windows', 'activate', function (event, hasVisibleWindows) {
2016-01-12 02:40:23 +00:00
if (!hasVisibleWindows) {
return this.emit('activate-with-no-open-windows', event)
2016-01-12 02:40:23 +00:00
}
})
2016-01-12 02:40:23 +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.
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
2016-01-14 18:35:29 +00:00
// Deprecated.
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
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