electron/lib/browser/api/app.js

124 lines
3.3 KiB
JavaScript
Raw Normal View History

'use strict';
2016-01-14 21:16:42 +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-01-14 21:16:42 +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-01-14 21:16:42 +00:00
var slice = [].slice;
2016-01-12 02:40:23 +00:00
app.__proto__ = EventEmitter.prototype;
app.setApplicationMenu = function(menu) {
return Menu.setApplicationMenu(menu);
};
app.getApplicationMenu = function() {
return Menu.getApplicationMenu();
};
app.commandLine = {
appendSwitch: bindings.appendSwitch,
appendArgument: bindings.appendArgument
};
if (process.platform === 'darwin') {
app.dock = {
bounce: function(type) {
if (type == null) {
type = 'informational';
}
return bindings.dockBounce(type);
},
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
};
}
2016-01-14 23:44:33 +00:00
var appPath = null;
2016-01-12 02:40:23 +00:00
app.setAppPath = function(path) {
return appPath = path;
};
app.getAppPath = function() {
return appPath;
};
2016-01-14 18:35:29 +00:00
// Routes the events to webContents.
2016-01-14 23:44:33 +00:00
var ref1 = ['login', 'certificate-error', 'select-client-certificate'];
var fn = function(name) {
2016-01-12 02:40:23 +00:00
return app.on(name, function() {
var args, event, webContents;
event = arguments[0], webContents = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
return webContents.emit.apply(webContents, [name, event].concat(slice.call(args)));
});
};
2016-01-19 22:49:40 +00:00
var i, len;
2016-01-12 02:40:23 +00:00
for (i = 0, len = ref1.length; i < len; i++) {
2016-01-15 02:07:29 +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
app.getHomeDir = deprecate('app.getHomeDir', 'app.getPath', function() {
return this.getPath('home');
});
app.getDataPath = deprecate('app.getDataPath', 'app.getPath', function() {
return this.getPath('userData');
});
app.setDataPath = deprecate('app.setDataPath', 'app.setPath', function(path) {
return this.setPath('userData', path);
});
app.resolveProxy = deprecate('app.resolveProxy', 'session.defaultSession.resolveProxy', function(url, callback) {
return session.defaultSession.resolveProxy(url, callback);
});
deprecate.rename(app, 'terminate', 'quit');
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) {
if (!hasVisibleWindows) {
return this.emit('activate-with-no-open-windows', event);
}
});
deprecate.event(app, 'select-certificate', 'select-client-certificate');
2016-01-14 18:35:29 +00:00
// Wrappers for native classes.
2016-01-14 23:44:33 +00:00
var wrapDownloadItem = function(downloadItem) {
2016-01-12 02:40:23 +00:00
2016-01-14 18:35:29 +00:00
// downloadItem is an EventEmitter.
2016-01-12 02:40:23 +00:00
downloadItem.__proto__ = EventEmitter.prototype;
2016-01-14 18:35:29 +00:00
// Deprecated.
2016-01-12 02:40:23 +00:00
deprecate.property(downloadItem, 'url', 'getURL');
deprecate.property(downloadItem, 'filename', 'getFilename');
deprecate.property(downloadItem, 'mimeType', 'getMimeType');
return deprecate.rename(downloadItem, 'getUrl', 'getURL');
};
downloadItemBindings._setWrapDownloadItem(wrapDownloadItem);
2016-01-14 18:35:29 +00:00
// Only one App object pemitted.
2016-01-12 02:40:23 +00:00
module.exports = app;