Use arrow functions to replace old CoffeeScript => this wrappers

This commit is contained in:
Kevin Sawicki 2016-03-10 11:54:17 -08:00
parent 100ea975bd
commit a3f08c9b51
10 changed files with 176 additions and 212 deletions

View file

@ -1,3 +1,5 @@
'use strict';
const deprecate = require('electron').deprecate; const deprecate = require('electron').deprecate;
const session = require('electron').session; const session = require('electron').session;
const Menu = require('electron').Menu; const Menu = require('electron').Menu;
@ -89,11 +91,9 @@ deprecate.rename(app, 'terminate', 'quit');
deprecate.event(app, 'finish-launching', 'ready', function() { deprecate.event(app, 'finish-launching', 'ready', function() {
// give default app a chance to setup default menu. // give default app a chance to setup default menu.
return setImmediate((function(_this) { setImmediate(() => {
return function() { this.emit('finish-launching');
return _this.emit('finish-launching'); });
};
})(this));
}); });
deprecate.event(app, 'activate-with-no-open-windows', 'activate', function(event, hasVisibleWindows) { deprecate.event(app, 'activate-with-no-open-windows', 'activate', function(event, hasVisibleWindows) {

View file

@ -28,30 +28,28 @@ AutoUpdater.prototype.checkForUpdates = function() {
return this.emitError('Can not find Squirrel'); return this.emitError('Can not find Squirrel');
} }
this.emit('checking-for-update'); this.emit('checking-for-update');
return squirrelUpdate.download(this.updateURL, (function(_this) { squirrelUpdate.download(this.updateURL, (error, update) => {
return function(error, update) {
if (error != null) { if (error != null) {
return _this.emitError(error); return this.emitError(error);
} }
if (update == null) { if (update == null) {
return _this.emit('update-not-available'); return this.emit('update-not-available');
} }
_this.emit('update-available'); this.emit('update-available');
return squirrelUpdate.update(_this.updateURL, function(error) { squirrelUpdate.update(this.updateURL, (error) => {
var date, releaseNotes, version; var date, releaseNotes, version;
if (error != null) { if (error != null) {
return _this.emitError(error); return this.emitError(error);
} }
releaseNotes = update.releaseNotes, version = update.version; releaseNotes = update.releaseNotes, version = update.version;
// Following information is not available on Windows, so fake them. // Following information is not available on Windows, so fake them.
date = new Date; date = new Date;
return _this.emit('update-downloaded', {}, releaseNotes, version, date, _this.updateURL, function() { this.emit('update-downloaded', {}, releaseNotes, version, date, this.updateURL, () => {
return _this.quitAndInstall(); this.quitAndInstall();
});
}); });
}); });
};
})(this));
}; };
// Private: Emit both error object and message, this is to keep compatibility // Private: Emit both error object and message, this is to keep compatibility

View file

@ -1,3 +1,5 @@
'use strict';
const ipcMain = require('electron').ipcMain; const ipcMain = require('electron').ipcMain;
const deprecate = require('electron').deprecate; const deprecate = require('electron').deprecate;
const EventEmitter = require('events').EventEmitter; const EventEmitter = require('events').EventEmitter;
@ -33,19 +35,19 @@ BrowserWindow.prototype._init = function() {
// window.resizeTo(...) // window.resizeTo(...)
// window.moveTo(...) // window.moveTo(...)
this.webContents.on('move', (event, size) => { this.webContents.on('move', (event, size) => {
return this.setBounds(size); this.setBounds(size);
}); });
// Hide the auto-hide menu when webContents is focused. // Hide the auto-hide menu when webContents is focused.
this.webContents.on('activate', () => { this.webContents.on('activate', () => {
if (process.platform !== 'darwin' && this.isMenuBarAutoHide() && this.isMenuBarVisible()) { if (process.platform !== 'darwin' && this.isMenuBarAutoHide() && this.isMenuBarVisible()) {
return this.setMenuBarVisibility(false); this.setMenuBarVisibility(false);
} }
}); });
// Forward the crashed event. // Forward the crashed event.
this.webContents.on('crashed', () => { this.webContents.on('crashed', () => {
return this.emit('crashed'); this.emit('crashed');
}); });
// Change window title to page title. // Change window title to page title.

View file

@ -1,3 +1,5 @@
'use strict';
var MenuItem, methodInBrowserWindow, nextCommandId, rolesMap; var MenuItem, methodInBrowserWindow, nextCommandId, rolesMap;
nextCommandId = 0; nextCommandId = 0;
@ -51,28 +53,25 @@ MenuItem = (function() {
throw new Error("Unknown menu type " + this.type); throw new Error("Unknown menu type " + this.type);
} }
this.commandId = ++nextCommandId; this.commandId = ++nextCommandId;
this.click = (function(_this) { this.click = (focusedWindow) => {
return function(focusedWindow) {
// Manually flip the checked flags when clicked. // Manually flip the checked flags when clicked.
var methodName, ref1, ref2; var methodName, ref1, ref2;
if ((ref1 = _this.type) === 'checkbox' || ref1 === 'radio') { if ((ref1 = this.type) === 'checkbox' || ref1 === 'radio') {
_this.checked = !_this.checked; this.checked = !this.checked;
} }
if (_this.role && rolesMap[_this.role] && process.platform !== 'darwin' && (focusedWindow != null)) { if (this.role && rolesMap[this.role] && process.platform !== 'darwin' && (focusedWindow != null)) {
methodName = rolesMap[_this.role]; methodName = rolesMap[this.role];
if (methodInBrowserWindow[methodName]) { if (methodInBrowserWindow[methodName]) {
return focusedWindow[methodName](); return focusedWindow[methodName]();
} else { } else {
return (ref2 = focusedWindow.webContents) != null ? ref2[methodName]() : void 0; return (ref2 = focusedWindow.webContents) != null ? ref2[methodName]() : void 0;
} }
} else if (typeof click === 'function') { } else if (typeof click === 'function') {
return click(_this, focusedWindow); return click(this, focusedWindow);
} else if (typeof _this.selector === 'string' && process.platform === 'darwin') { } else if (typeof this.selector === 'string' && process.platform === 'darwin') {
return Menu.sendActionToFirstResponder(_this.selector); return Menu.sendActionToFirstResponder(this.selector);
} }
}; };
})(this);
} }
MenuItem.prototype.overrideProperty = function(name, defaultValue) { MenuItem.prototype.overrideProperty = function(name, defaultValue) {

View file

@ -1,3 +1,5 @@
'use strict';
const BrowserWindow = require('electron').BrowserWindow; const BrowserWindow = require('electron').BrowserWindow;
const MenuItem = require('electron').MenuItem; const MenuItem = require('electron').MenuItem;
const EventEmitter = require('events').EventEmitter; const EventEmitter = require('events').EventEmitter;
@ -92,48 +94,35 @@ Menu.prototype._init = function() {
this.groupsMap = {}; this.groupsMap = {};
this.items = []; this.items = [];
return this.delegate = { return this.delegate = {
isCommandIdChecked: (function(_this) { isCommandIdChecked: (commandId) => {
return function(commandId) { var command = this.commandsMap[commandId];
var ref1; return command != null ? command.checked : undefined;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.checked : void 0; },
}; isCommandIdEnabled: (commandId) => {
})(this), var command = this.commandsMap[commandId];
isCommandIdEnabled: (function(_this) { return command != null ? command.enabled : undefined;
return function(commandId) { },
var ref1; isCommandIdVisible: (commandId) => {
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.enabled : void 0; var command = this.commandsMap[commandId];
}; return command != null ? command.visible : undefined;
})(this), },
isCommandIdVisible: (function(_this) { getAcceleratorForCommandId: (commandId) => {
return function(commandId) { var command = this.commandsMap[commandId];
var ref1; return command != null ? command.accelerator : undefined;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.visible : void 0; },
}; getIconForCommandId: (commandId) => {
})(this), var command = this.commandsMap[commandId];
getAcceleratorForCommandId: (function(_this) { return command != null ? command.icon : void 0;
return function(commandId) { },
var ref1; executeCommand: (commandId) => {
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.accelerator : void 0; var command = this.commandsMap[commandId];
}; return command != null ? command.click(BrowserWindow.getFocusedWindow()) : undefined;
})(this), },
getIconForCommandId: (function(_this) { menuWillShow: () => {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.icon : void 0;
};
})(this),
executeCommand: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.click(BrowserWindow.getFocusedWindow()) : void 0;
};
})(this),
menuWillShow: (function(_this) {
return function() {
// Make sure radio groups have at least one menu item seleted. // Make sure radio groups have at least one menu item seleted.
var checked, group, id, j, len, radioItem, ref1; var checked, group, id, j, len, radioItem, ref1;
ref1 = _this.groupsMap; ref1 = this.groupsMap;
results = [];
for (id in ref1) { for (id in ref1) {
group = ref1[id]; group = ref1[id];
checked = false; checked = false;
@ -148,9 +137,8 @@ Menu.prototype._init = function() {
if (!checked) { if (!checked) {
v8Util.setHiddenValue(group[0], 'checked', true); v8Util.setHiddenValue(group[0], 'checked', true);
} }
}
}; };
})(this) }
}; };
}; };
@ -208,10 +196,9 @@ Menu.prototype.insert = function(pos, item) {
get: function() { get: function() {
return v8Util.getHiddenValue(item, 'checked'); return v8Util.getHiddenValue(item, 'checked');
}, },
set: (function(_this) { set: () => {
return function() {
var j, len, otherItem, ref1; var j, len, otherItem, ref1;
ref1 = _this.groupsMap[item.groupId]; ref1 = this.groupsMap[item.groupId];
for (j = 0, len = ref1.length; j < len; j++) { for (j = 0, len = ref1.length; j < len; j++) {
otherItem = ref1[j]; otherItem = ref1[j];
if (otherItem !== item) { if (otherItem !== item) {
@ -219,8 +206,7 @@ Menu.prototype.insert = function(pos, item) {
} }
} }
return v8Util.setHiddenValue(item, 'checked', true); return v8Util.setHiddenValue(item, 'checked', true);
}; }
})(this)
}); });
this.insertRadioItem(pos, item.commandId, item.label, item.groupId); this.insertRadioItem(pos, item.commandId, item.label, item.groupId);
} }

View file

@ -1,3 +1,5 @@
'use strict';
const ipcMain = require('electron').ipcMain; const ipcMain = require('electron').ipcMain;
var slice = [].slice; var slice = [].slice;
@ -30,40 +32,33 @@ var NavigationController = (function() {
this.currentIndex++; this.currentIndex++;
this.history.push(this.webContents._getURL()); this.history.push(this.webContents._getURL());
} }
this.webContents.on('navigation-entry-commited', (function(_this) { this.webContents.on('navigation-entry-commited', (event, url, inPage, replaceEntry) => {
return function(event, url, inPage, replaceEntry) {
var currentEntry; var currentEntry;
if (_this.inPageIndex > -1 && !inPage) { if (this.inPageIndex > -1 && !inPage) {
// Navigated to a new page, clear in-page mark. // Navigated to a new page, clear in-page mark.
_this.inPageIndex = -1; this.inPageIndex = -1;
} else if (_this.inPageIndex === -1 && inPage) { } else if (this.inPageIndex === -1 && inPage) {
// Started in-page navigations. // Started in-page navigations.
_this.inPageIndex = _this.currentIndex; this.inPageIndex = this.currentIndex;
} }
if (_this.pendingIndex >= 0) { if (this.pendingIndex >= 0) {
// Go to index. // Go to index.
_this.currentIndex = _this.pendingIndex; this.currentIndex = this.pendingIndex;
_this.pendingIndex = -1; this.pendingIndex = -1;
return _this.history[_this.currentIndex] = url; return this.history[this.currentIndex] = url;
} else if (replaceEntry) { } else if (replaceEntry) {
// Non-user initialized navigation. // Non-user initialized navigation.
return _this.history[_this.currentIndex] = url; return this.history[this.currentIndex] = url;
} else { } else {
// Normal navigation. Clear history. // Normal navigation. Clear history.
_this.history = _this.history.slice(0, _this.currentIndex + 1); this.history = this.history.slice(0, this.currentIndex + 1);
currentEntry = _this.history[_this.currentIndex]; currentEntry = this.history[this.currentIndex];
if ((currentEntry != null ? currentEntry.url : void 0) !== url) { if ((currentEntry != null ? currentEntry.url : void 0) !== url) {
_this.currentIndex++; this.currentIndex++;
return _this.history.push(url); return this.history.push(url);
} }
} }
}; });
})(this));
} }
NavigationController.prototype.loadURL = function(url, options) { NavigationController.prototype.loadURL = function(url, options) {

View file

@ -153,35 +153,28 @@ let wrapWebContents = function(webContents) {
// This error occurs when host could not be found. // This error occurs when host could not be found.
webContents.on('did-fail-provisional-load', function() { webContents.on('did-fail-provisional-load', function() {
var args; var args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
// Calling loadURL during this event might cause crash, so delay the event // Calling loadURL during this event might cause crash, so delay the event
// until next tick. // until next tick.
return setImmediate((function(_this) { setImmediate(() => {
return function() { this.emit.apply(this, ['did-fail-load'].concat(slice.call(args)));
return _this.emit.apply(_this, ['did-fail-load'].concat(slice.call(args))); });
};
})(this));
}); });
// Delays the page-title-updated event to next tick. // Delays the page-title-updated event to next tick.
webContents.on('-page-title-updated', function() { webContents.on('-page-title-updated', function() {
var args; var args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; setImmediate(() => {
return setImmediate((function(_this) { this.emit.apply(this, ['page-title-updated'].concat(slice.call(args)));
return function() { });
return _this.emit.apply(_this, ['page-title-updated'].concat(slice.call(args)));
};
})(this));
}); });
// Deprecated. // Deprecated.
deprecate.rename(webContents, 'loadUrl', 'loadURL'); deprecate.rename(webContents, 'loadUrl', 'loadURL');
deprecate.rename(webContents, 'getUrl', 'getURL'); deprecate.rename(webContents, 'getUrl', 'getURL');
deprecate.event(webContents, 'page-title-set', 'page-title-updated', function() { deprecate.event(webContents, 'page-title-set', 'page-title-updated', function() {
var args; var args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return this.emit.apply(this, ['page-title-set'].concat(slice.call(args))); return this.emit.apply(this, ['page-title-set'].concat(slice.call(args)));
}); });
return webContents.printToPDF = function(options, callback) { return webContents.printToPDF = function(options, callback) {

View file

@ -1,3 +1,5 @@
'use strict';
const os = require('os'); const os = require('os');
const path = require('path'); const path = require('path');
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
@ -52,11 +54,9 @@ var CrashReporter = (function() {
deprecate.log('submitURL is now a required option to crashReporter.start'); deprecate.log('submitURL is now a required option to crashReporter.start');
return; return;
} }
start = (function(_this) { start = () => {
return function() { binding.start(this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra);
return binding.start(_this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra);
}; };
})(this);
if (process.platform === 'win32') { if (process.platform === 'win32') {
args = ["--reporter-url=" + submitURL, "--application-name=" + this.productName, "--v=1"]; args = ["--reporter-url=" + submitURL, "--application-name=" + this.productName, "--v=1"];
env = { env = {

View file

@ -1,3 +1,5 @@
'use strict';
const ipcRenderer = require('electron').ipcRenderer; const ipcRenderer = require('electron').ipcRenderer;
const remote = require('electron').remote; const remote = require('electron').remote;
@ -37,12 +39,10 @@ var BrowserWindowProxy = (function() {
function BrowserWindowProxy(guestId1) { function BrowserWindowProxy(guestId1) {
this.guestId = guestId1; this.guestId = guestId1;
this.closed = false; this.closed = false;
ipcRenderer.once("ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_" + this.guestId, (function(_this) { ipcRenderer.once("ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_CLOSED_" + this.guestId, () => {
return function() { BrowserWindowProxy.remove(this.guestId);
BrowserWindowProxy.remove(_this.guestId); this.closed = true;
return (_this.closed = true); });
};
})(this));
} }
BrowserWindowProxy.prototype.close = function() { BrowserWindowProxy.prototype.close = function() {

View file

@ -86,25 +86,22 @@ var WebViewImpl = (function() {
WebViewImpl.prototype.setupFocusPropagation = function() { WebViewImpl.prototype.setupFocusPropagation = function() {
if (!this.webviewNode.hasAttribute('tabIndex')) { if (!this.webviewNode.hasAttribute('tabIndex')) {
// <webview> needs a tabIndex in order to be focusable. // <webview> needs a tabIndex in order to be focusable.
// TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute // TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute
// to allow <webview> to be focusable. // to allow <webview> to be focusable.
// See http://crbug.com/231664. // See http://crbug.com/231664.
this.webviewNode.setAttribute('tabIndex', -1); this.webviewNode.setAttribute('tabIndex', -1);
} }
this.webviewNode.addEventListener('focus', (function(_this) {
return function() {
// Focus the BrowserPlugin when the <webview> takes focus. // Focus the BrowserPlugin when the <webview> takes focus.
return _this.browserPluginNode.focus(); this.webviewNode.addEventListener('focus', () => {
}; this.browserPluginNode.focus();
})(this)); });
return this.webviewNode.addEventListener('blur', (function(_this) {
return function() {
// Blur the BrowserPlugin when the <webview> loses focus. // Blur the BrowserPlugin when the <webview> loses focus.
return _this.browserPluginNode.blur(); this.webviewNode.addEventListener('blur', () => {
}; this.browserPluginNode.blur();
})(this)); });
}; };
@ -178,11 +175,9 @@ var WebViewImpl = (function() {
}; };
WebViewImpl.prototype.createGuest = function() { WebViewImpl.prototype.createGuest = function() {
return guestViewInternal.createGuest(this.buildParams(), (function(_this) { return guestViewInternal.createGuest(this.buildParams(), (event, guestInstanceId) => {
return function(event, guestInstanceId) { this.attachWindow(guestInstanceId);
return _this.attachWindow(guestInstanceId); });
};
})(this));
}; };
WebViewImpl.prototype.dispatchEvent = function(webViewEvent) { WebViewImpl.prototype.dispatchEvent = function(webViewEvent) {
@ -195,22 +190,18 @@ var WebViewImpl = (function() {
var propertyName; var propertyName;
propertyName = 'on' + eventName.toLowerCase(); propertyName = 'on' + eventName.toLowerCase();
return Object.defineProperty(this.webviewNode, propertyName, { return Object.defineProperty(this.webviewNode, propertyName, {
get: (function(_this) { get: () => {
return function() { this.on[propertyName];
return _this.on[propertyName]; },
}; set: (value) => {
})(this), if (this.on[propertyName]) {
set: (function(_this) { this.webviewNode.removeEventListener(eventName, this.on[propertyName]);
return function(value) {
if (_this.on[propertyName]) {
_this.webviewNode.removeEventListener(eventName, _this.on[propertyName]);
} }
_this.on[propertyName] = value; this.on[propertyName] = value;
if (value) { if (value) {
return _this.webviewNode.addEventListener(eventName, value); return this.webviewNode.addEventListener(eventName, value);
} }
}; },
})(this),
enumerable: true enumerable: true
}); });
}; };