Convert all source files to JavaScript

This commit is contained in:
Kevin Sawicki 2016-01-11 18:40:23 -08:00
parent 403870a27e
commit 1f9691ae13
144 changed files with 11211 additions and 7301 deletions

View file

@ -1,73 +0,0 @@
{deprecate, session, Menu} = require 'electron'
{EventEmitter} = require 'events'
bindings = process.atomBinding 'app'
downloadItemBindings = process.atomBinding 'download_item'
app = bindings.app
app.__proto__ = EventEmitter.prototype
app.setApplicationMenu = (menu) ->
Menu.setApplicationMenu menu
app.getApplicationMenu = ->
Menu.getApplicationMenu()
app.commandLine =
appendSwitch: bindings.appendSwitch,
appendArgument: bindings.appendArgument
if process.platform is 'darwin'
app.dock =
bounce: (type='informational') -> bindings.dockBounce type
cancelBounce: bindings.dockCancelBounce
setBadge: bindings.dockSetBadgeText
getBadge: bindings.dockGetBadgeText
hide: bindings.dockHide
show: bindings.dockShow
setMenu: bindings.dockSetMenu
appPath = null
app.setAppPath = (path) ->
appPath = path
app.getAppPath = ->
appPath
### Routes the events to webContents. ###
for name in ['login', 'certificate-error', 'select-client-certificate']
do (name) ->
app.on name, (event, webContents, args...) ->
webContents.emit name, event, args...
### Deprecated. ###
app.getHomeDir = deprecate 'app.getHomeDir', 'app.getPath', ->
@getPath 'home'
app.getDataPath = deprecate 'app.getDataPath', 'app.getPath', ->
@getPath 'userData'
app.setDataPath = deprecate 'app.setDataPath', 'app.setPath', (path) ->
@setPath 'userData', path
app.resolveProxy = deprecate 'app.resolveProxy', 'session.defaultSession.resolveProxy', (url, callback) ->
session.defaultSession.resolveProxy url, callback
deprecate.rename app, 'terminate', 'quit'
deprecate.event app, 'finish-launching', 'ready', ->
### give default app a chance to setup default menu. ###
setImmediate =>
@emit 'finish-launching'
deprecate.event app, 'activate-with-no-open-windows', 'activate', (event, hasVisibleWindows) ->
@emit 'activate-with-no-open-windows', event if not hasVisibleWindows
deprecate.event app, 'select-certificate', 'select-client-certificate'
### Wrappers for native classes. ###
wrapDownloadItem = (downloadItem) ->
### downloadItem is an EventEmitter. ###
downloadItem.__proto__ = EventEmitter.prototype
### Deprecated. ###
deprecate.property downloadItem, 'url', 'getURL'
deprecate.property downloadItem, 'filename', 'getFilename'
deprecate.property downloadItem, 'mimeType', 'getMimeType'
deprecate.rename downloadItem, 'getUrl', 'getURL'
downloadItemBindings._setWrapDownloadItem wrapDownloadItem
### Only one App object pemitted. ###
module.exports = app

131
atom/browser/api/lib/app.js Normal file
View file

@ -0,0 +1,131 @@
var EventEmitter, Menu, app, appPath, bindings, deprecate, downloadItemBindings, fn, i, len, name, ref, ref1, session, wrapDownloadItem,
slice = [].slice;
ref = require('electron'), deprecate = ref.deprecate, session = ref.session, Menu = ref.Menu;
EventEmitter = require('events').EventEmitter;
bindings = process.atomBinding('app');
downloadItemBindings = process.atomBinding('download_item');
app = bindings.app;
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
};
}
appPath = null;
app.setAppPath = function(path) {
return appPath = path;
};
app.getAppPath = function() {
return appPath;
};
/* Routes the events to webContents. */
ref1 = ['login', 'certificate-error', 'select-client-certificate'];
fn = function(name) {
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)));
});
};
for (i = 0, len = ref1.length; i < len; i++) {
name = ref1[i];
fn(name);
}
/* Deprecated. */
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() {
/* give default app a chance to setup default menu. */
return setImmediate((function(_this) {
return function() {
return _this.emit('finish-launching');
};
})(this));
});
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');
/* Wrappers for native classes. */
wrapDownloadItem = function(downloadItem) {
/* downloadItem is an EventEmitter. */
downloadItem.__proto__ = EventEmitter.prototype;
/* Deprecated. */
deprecate.property(downloadItem, 'url', 'getURL');
deprecate.property(downloadItem, 'filename', 'getFilename');
deprecate.property(downloadItem, 'mimeType', 'getMimeType');
return deprecate.rename(downloadItem, 'getUrl', 'getURL');
};
downloadItemBindings._setWrapDownloadItem(wrapDownloadItem);
/* Only one App object pemitted. */
module.exports = app;

View file

@ -1,12 +0,0 @@
{deprecate} = require 'electron'
autoUpdater =
if process.platform is 'win32'
require './auto-updater/auto-updater-win'
else
require './auto-updater/auto-updater-native'
### Deprecated. ###
deprecate.rename autoUpdater, 'setFeedUrl', 'setFeedURL'
module.exports = autoUpdater

View file

@ -0,0 +1,12 @@
var autoUpdater, deprecate;
deprecate = require('electron').deprecate;
autoUpdater = process.platform === 'win32' ? require('./auto-updater/auto-updater-win') : require('./auto-updater/auto-updater-native');
/* Deprecated. */
deprecate.rename(autoUpdater, 'setFeedUrl', 'setFeedURL');
module.exports = autoUpdater;

View file

@ -1,6 +0,0 @@
{EventEmitter} = require 'events'
{autoUpdater} = process.atomBinding 'auto_updater'
autoUpdater.__proto__ = EventEmitter.prototype
module.exports = autoUpdater

View file

@ -0,0 +1,9 @@
var EventEmitter, autoUpdater;
EventEmitter = require('events').EventEmitter;
autoUpdater = process.atomBinding('auto_updater').autoUpdater;
autoUpdater.__proto__ = EventEmitter.prototype;
module.exports = autoUpdater;

View file

@ -1,44 +0,0 @@
{app} = require 'electron'
{EventEmitter} = require 'events'
url = require 'url'
squirrelUpdate = require './squirrel-update-win'
class AutoUpdater extends EventEmitter
quitAndInstall: ->
squirrelUpdate.processStart()
app.quit()
setFeedURL: (updateURL) ->
@updateURL = updateURL
checkForUpdates: ->
return @emitError 'Update URL is not set' unless @updateURL
return @emitError 'Can not find Squirrel' unless squirrelUpdate.supported()
@emit 'checking-for-update'
squirrelUpdate.download @updateURL, (error, update) =>
return @emitError error if error?
return @emit 'update-not-available' unless update?
@emit 'update-available'
squirrelUpdate.update @updateURL, (error) =>
return @emitError error if error?
{releaseNotes, version} = update
### Following information is not available on Windows, so fake them. ###
date = new Date
url = @updateURL
@emit 'update-downloaded', {}, releaseNotes, version, date, url, => @quitAndInstall()
###
Private: Emit both error object and message, this is to keep compatibility
with Old APIs.
###
emitError: (message) ->
@emit 'error', new Error(message), message
module.exports = new AutoUpdater

View file

@ -0,0 +1,78 @@
var AutoUpdater, EventEmitter, app, squirrelUpdate, url,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
app = require('electron').app;
EventEmitter = require('events').EventEmitter;
url = require('url');
squirrelUpdate = require('./squirrel-update-win');
AutoUpdater = (function(superClass) {
extend(AutoUpdater, superClass);
function AutoUpdater() {
return AutoUpdater.__super__.constructor.apply(this, arguments);
}
AutoUpdater.prototype.quitAndInstall = function() {
squirrelUpdate.processStart();
return app.quit();
};
AutoUpdater.prototype.setFeedURL = function(updateURL) {
return this.updateURL = updateURL;
};
AutoUpdater.prototype.checkForUpdates = function() {
if (!this.updateURL) {
return this.emitError('Update URL is not set');
}
if (!squirrelUpdate.supported()) {
return this.emitError('Can not find Squirrel');
}
this.emit('checking-for-update');
return squirrelUpdate.download(this.updateURL, (function(_this) {
return function(error, update) {
if (error != null) {
return _this.emitError(error);
}
if (update == null) {
return _this.emit('update-not-available');
}
_this.emit('update-available');
return squirrelUpdate.update(_this.updateURL, function(error) {
var date, releaseNotes, version;
if (error != null) {
return _this.emitError(error);
}
releaseNotes = update.releaseNotes, version = update.version;
/* Following information is not available on Windows, so fake them. */
date = new Date;
url = _this.updateURL;
return _this.emit('update-downloaded', {}, releaseNotes, version, date, url, function() {
return _this.quitAndInstall();
});
});
};
})(this));
};
/*
Private: Emit both error object and message, this is to keep compatibility
with Old APIs.
*/
AutoUpdater.prototype.emitError = function(message) {
return this.emit('error', new Error(message), message);
};
return AutoUpdater;
})(EventEmitter);
module.exports = new AutoUpdater;

View file

@ -1,71 +0,0 @@
fs = require 'fs'
path = require 'path'
{spawn} = require 'child_process'
### i.e. my-app/app-0.1.13/ ###
appFolder = path.dirname process.execPath
### i.e. my-app/Update.exe ###
updateExe = path.resolve appFolder, '..', 'Update.exe'
exeName = path.basename process.execPath
###
Spawn a command and invoke the callback when it completes with an error
and the output from standard out.
###
spawnUpdate = (args, detached, callback) ->
try
spawnedProcess = spawn updateExe, args, {detached}
catch error
### Shouldn't happen, but still guard it. ###
process.nextTick -> callback error
return
stdout = ''
stderr = ''
spawnedProcess.stdout.on 'data', (data) -> stdout += data
spawnedProcess.stderr.on 'data', (data) -> stderr += data
errorEmitted = false
spawnedProcess.on 'error', (error) ->
errorEmitted = true
callback error
spawnedProcess.on 'exit', (code, signal) ->
### We may have already emitted an error. ###
return if errorEmitted
### Process terminated with error. ###
if code isnt 0
return callback "Command failed: #{signal ? code}\n#{stderr}"
### Success. ###
callback null, stdout
### Start an instance of the installed app. ###
exports.processStart = (callback) ->
spawnUpdate ['--processStart', exeName], true, ->
### Download the releases specified by the URL and write new results to stdout. ###
exports.download = (updateURL, callback) ->
spawnUpdate ['--download', updateURL], false, (error, stdout) ->
return callback(error) if error?
try
### Last line of output is the JSON details about the releases ###
json = stdout.trim().split('\n').pop()
update = JSON.parse(json)?.releasesToApply?.pop?()
catch
return callback "Invalid result:\n#{stdout}"
callback null, update
### Update the application to the latest remote version specified by URL. ###
exports.update = (updateURL, callback) ->
spawnUpdate ['--update', updateURL], false, callback
### Is the Update.exe installed with the current application? ###
exports.supported = ->
try
fs.accessSync updateExe, fs.R_OK
return true
catch
return false

View file

@ -0,0 +1,118 @@
var appFolder, exeName, fs, path, spawn, spawnUpdate, updateExe;
fs = require('fs');
path = require('path');
spawn = require('child_process').spawn;
/* i.e. my-app/app-0.1.13/ */
appFolder = path.dirname(process.execPath);
/* i.e. my-app/Update.exe */
updateExe = path.resolve(appFolder, '..', 'Update.exe');
exeName = path.basename(process.execPath);
/*
Spawn a command and invoke the callback when it completes with an error
and the output from standard out.
*/
spawnUpdate = function(args, detached, callback) {
var error, error1, errorEmitted, spawnedProcess, stderr, stdout;
try {
spawnedProcess = spawn(updateExe, args, {
detached: detached
});
} catch (error1) {
error = error1;
/* Shouldn't happen, but still guard it. */
process.nextTick(function() {
return callback(error);
});
return;
}
stdout = '';
stderr = '';
spawnedProcess.stdout.on('data', function(data) {
return stdout += data;
});
spawnedProcess.stderr.on('data', function(data) {
return stderr += data;
});
errorEmitted = false;
spawnedProcess.on('error', function(error) {
errorEmitted = true;
return callback(error);
});
return spawnedProcess.on('exit', function(code, signal) {
/* We may have already emitted an error. */
if (errorEmitted) {
return;
}
/* Process terminated with error. */
if (code !== 0) {
return callback("Command failed: " + (signal != null ? signal : code) + "\n" + stderr);
}
/* Success. */
return callback(null, stdout);
});
};
/* Start an instance of the installed app. */
exports.processStart = function(callback) {
return spawnUpdate(['--processStart', exeName], true, function() {});
};
/* Download the releases specified by the URL and write new results to stdout. */
exports.download = function(updateURL, callback) {
return spawnUpdate(['--download', updateURL], false, function(error, stdout) {
var error1, json, ref, ref1, update;
if (error != null) {
return callback(error);
}
try {
/* Last line of output is the JSON details about the releases */
json = stdout.trim().split('\n').pop();
update = (ref = JSON.parse(json)) != null ? (ref1 = ref.releasesToApply) != null ? typeof ref1.pop === "function" ? ref1.pop() : void 0 : void 0 : void 0;
} catch (error1) {
return callback("Invalid result:\n" + stdout);
}
return callback(null, update);
});
};
/* Update the application to the latest remote version specified by URL. */
exports.update = function(updateURL, callback) {
return spawnUpdate(['--update', updateURL], false, callback);
};
/* Is the Update.exe installed with the current application? */
exports.supported = function() {
var error1;
try {
fs.accessSync(updateExe, fs.R_OK);
return true;
} catch (error1) {
return false;
}
};

View file

@ -1,119 +0,0 @@
{ipcMain, deprecate} = require 'electron'
{EventEmitter} = require 'events'
{BrowserWindow} = process.atomBinding 'window'
BrowserWindow::__proto__ = EventEmitter.prototype
BrowserWindow::_init = ->
### avoid recursive require. ###
{app} = require 'electron'
### Simulate the application menu on platforms other than OS X. ###
if process.platform isnt 'darwin'
menu = app.getApplicationMenu()
@setMenu menu if menu?
### Make new windows requested by links behave like "window.open" ###
@webContents.on '-new-window', (event, url, frameName) ->
options = show: true, width: 800, height: 600
ipcMain.emit 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, options
###
window.resizeTo(...)
window.moveTo(...)
###
@webContents.on 'move', (event, size) =>
@setBounds size
### Hide the auto-hide menu when webContents is focused. ###
@webContents.on 'activate', =>
if process.platform isnt 'darwin' and @isMenuBarAutoHide() and @isMenuBarVisible()
@setMenuBarVisibility false
### Forward the crashed event. ###
@webContents.on 'crashed', =>
@emit 'crashed'
### Change window title to page title. ###
@webContents.on 'page-title-updated', (event, title, explicitSet) =>
@emit 'page-title-updated', event, title
@setTitle title unless event.defaultPrevented
###
Sometimes the webContents doesn't get focus when window is shown, so we have
to force focusing on webContents in this case. The safest way is to focus it
when we first start to load URL, if we do it earlier it won't have effect,
if we do it later we might move focus in the page.
Though this hack is only needed on OS X when the app is launched from
Finder, we still do it on all platforms in case of other bugs we don't know.
###
@webContents.once 'load-url', ->
@focus()
### Redirect focus/blur event to app instance too. ###
@on 'blur', (event) =>
app.emit 'browser-window-blur', event, this
@on 'focus', (event) =>
app.emit 'browser-window-focus', event, this
### Notify the creation of the window. ###
app.emit 'browser-window-created', {}, this
### Be compatible with old APIs. ###
@webContents.on 'devtools-focused', => @emit 'devtools-focused'
@webContents.on 'devtools-opened', => @emit 'devtools-opened'
@webContents.on 'devtools-closed', => @emit 'devtools-closed'
Object.defineProperty this, 'devToolsWebContents',
enumerable: true,
configurable: false,
get: -> @webContents.devToolsWebContents
BrowserWindow.getFocusedWindow = ->
windows = BrowserWindow.getAllWindows()
return window for window in windows when window.isFocused()
null
BrowserWindow.fromWebContents = (webContents) ->
windows = BrowserWindow.getAllWindows()
return window for window in windows when window.webContents?.equal webContents
BrowserWindow.fromDevToolsWebContents = (webContents) ->
windows = BrowserWindow.getAllWindows()
return window for window in windows when window.devToolsWebContents?.equal webContents
### Helpers. ###
BrowserWindow::loadURL = -> @webContents.loadURL.apply @webContents, arguments
BrowserWindow::getURL = -> @webContents.getURL()
BrowserWindow::reload = -> @webContents.reload.apply @webContents, arguments
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
BrowserWindow::openDevTools = -> @webContents.openDevTools.apply @webContents, arguments
BrowserWindow::closeDevTools = -> @webContents.closeDevTools()
BrowserWindow::isDevToolsOpened = -> @webContents.isDevToolsOpened()
BrowserWindow::isDevToolsFocused = -> @webContents.isDevToolsFocused()
BrowserWindow::toggleDevTools = -> @webContents.toggleDevTools()
BrowserWindow::inspectElement = -> @webContents.inspectElement.apply @webContents, arguments
BrowserWindow::inspectServiceWorker = -> @webContents.inspectServiceWorker()
### Deprecated. ###
deprecate.member BrowserWindow, 'undo', 'webContents'
deprecate.member BrowserWindow, 'redo', 'webContents'
deprecate.member BrowserWindow, 'cut', 'webContents'
deprecate.member BrowserWindow, 'copy', 'webContents'
deprecate.member BrowserWindow, 'paste', 'webContents'
deprecate.member BrowserWindow, 'selectAll', 'webContents'
deprecate.member BrowserWindow, 'reloadIgnoringCache', 'webContents'
deprecate.member BrowserWindow, 'isLoading', 'webContents'
deprecate.member BrowserWindow, 'isWaitingForResponse', 'webContents'
deprecate.member BrowserWindow, 'stop', 'webContents'
deprecate.member BrowserWindow, 'isCrashed', 'webContents'
deprecate.member BrowserWindow, 'print', 'webContents'
deprecate.member BrowserWindow, 'printToPDF', 'webContents'
deprecate.rename BrowserWindow, 'restart', 'reload'
deprecate.rename BrowserWindow, 'loadUrl', 'loadURL'
deprecate.rename BrowserWindow, 'getUrl', 'getURL'
BrowserWindow::executeJavaScriptInDevTools = deprecate 'executeJavaScriptInDevTools', 'devToolsWebContents.executeJavaScript', (code) ->
@devToolsWebContents?.executeJavaScript code
BrowserWindow::getPageTitle = deprecate 'getPageTitle', 'webContents.getTitle', ->
@webContents?.getTitle()
module.exports = BrowserWindow

View file

@ -0,0 +1,250 @@
var BrowserWindow, EventEmitter, deprecate, ipcMain, ref;
ref = require('electron'), ipcMain = ref.ipcMain, deprecate = ref.deprecate;
EventEmitter = require('events').EventEmitter;
BrowserWindow = process.atomBinding('window').BrowserWindow;
BrowserWindow.prototype.__proto__ = EventEmitter.prototype;
BrowserWindow.prototype._init = function() {
/* avoid recursive require. */
var app, menu;
app = require('electron').app;
/* Simulate the application menu on platforms other than OS X. */
if (process.platform !== 'darwin') {
menu = app.getApplicationMenu();
if (menu != null) {
this.setMenu(menu);
}
}
/* Make new windows requested by links behave like "window.open" */
this.webContents.on('-new-window', function(event, url, frameName) {
var options;
options = {
show: true,
width: 800,
height: 600
};
return ipcMain.emit('ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, options);
});
/*
window.resizeTo(...)
window.moveTo(...)
*/
this.webContents.on('move', (function(_this) {
return function(event, size) {
return _this.setBounds(size);
};
})(this));
/* Hide the auto-hide menu when webContents is focused. */
this.webContents.on('activate', (function(_this) {
return function() {
if (process.platform !== 'darwin' && _this.isMenuBarAutoHide() && _this.isMenuBarVisible()) {
return _this.setMenuBarVisibility(false);
}
};
})(this));
/* Forward the crashed event. */
this.webContents.on('crashed', (function(_this) {
return function() {
return _this.emit('crashed');
};
})(this));
/* Change window title to page title. */
this.webContents.on('page-title-updated', (function(_this) {
return function(event, title, explicitSet) {
_this.emit('page-title-updated', event, title);
if (!event.defaultPrevented) {
return _this.setTitle(title);
}
};
})(this));
/*
Sometimes the webContents doesn't get focus when window is shown, so we have
to force focusing on webContents in this case. The safest way is to focus it
when we first start to load URL, if we do it earlier it won't have effect,
if we do it later we might move focus in the page.
Though this hack is only needed on OS X when the app is launched from
Finder, we still do it on all platforms in case of other bugs we don't know.
*/
this.webContents.once('load-url', function() {
return this.focus();
});
/* Redirect focus/blur event to app instance too. */
this.on('blur', (function(_this) {
return function(event) {
return app.emit('browser-window-blur', event, _this);
};
})(this));
this.on('focus', (function(_this) {
return function(event) {
return app.emit('browser-window-focus', event, _this);
};
})(this));
/* Notify the creation of the window. */
app.emit('browser-window-created', {}, this);
/* Be compatible with old APIs. */
this.webContents.on('devtools-focused', (function(_this) {
return function() {
return _this.emit('devtools-focused');
};
})(this));
this.webContents.on('devtools-opened', (function(_this) {
return function() {
return _this.emit('devtools-opened');
};
})(this));
this.webContents.on('devtools-closed', (function(_this) {
return function() {
return _this.emit('devtools-closed');
};
})(this));
return Object.defineProperty(this, 'devToolsWebContents', {
enumerable: true,
configurable: false,
get: function() {
return this.webContents.devToolsWebContents;
}
});
};
BrowserWindow.getFocusedWindow = function() {
var i, len, window, windows;
windows = BrowserWindow.getAllWindows();
for (i = 0, len = windows.length; i < len; i++) {
window = windows[i];
if (window.isFocused()) {
return window;
}
}
return null;
};
BrowserWindow.fromWebContents = function(webContents) {
var i, len, ref1, window, windows;
windows = BrowserWindow.getAllWindows();
for (i = 0, len = windows.length; i < len; i++) {
window = windows[i];
if ((ref1 = window.webContents) != null ? ref1.equal(webContents) : void 0) {
return window;
}
}
};
BrowserWindow.fromDevToolsWebContents = function(webContents) {
var i, len, ref1, window, windows;
windows = BrowserWindow.getAllWindows();
for (i = 0, len = windows.length; i < len; i++) {
window = windows[i];
if ((ref1 = window.devToolsWebContents) != null ? ref1.equal(webContents) : void 0) {
return window;
}
}
};
/* Helpers. */
BrowserWindow.prototype.loadURL = function() {
return this.webContents.loadURL.apply(this.webContents, arguments);
};
BrowserWindow.prototype.getURL = function() {
return this.webContents.getURL();
};
BrowserWindow.prototype.reload = function() {
return this.webContents.reload.apply(this.webContents, arguments);
};
BrowserWindow.prototype.send = function() {
return this.webContents.send.apply(this.webContents, arguments);
};
BrowserWindow.prototype.openDevTools = function() {
return this.webContents.openDevTools.apply(this.webContents, arguments);
};
BrowserWindow.prototype.closeDevTools = function() {
return this.webContents.closeDevTools();
};
BrowserWindow.prototype.isDevToolsOpened = function() {
return this.webContents.isDevToolsOpened();
};
BrowserWindow.prototype.isDevToolsFocused = function() {
return this.webContents.isDevToolsFocused();
};
BrowserWindow.prototype.toggleDevTools = function() {
return this.webContents.toggleDevTools();
};
BrowserWindow.prototype.inspectElement = function() {
return this.webContents.inspectElement.apply(this.webContents, arguments);
};
BrowserWindow.prototype.inspectServiceWorker = function() {
return this.webContents.inspectServiceWorker();
};
/* Deprecated. */
deprecate.member(BrowserWindow, 'undo', 'webContents');
deprecate.member(BrowserWindow, 'redo', 'webContents');
deprecate.member(BrowserWindow, 'cut', 'webContents');
deprecate.member(BrowserWindow, 'copy', 'webContents');
deprecate.member(BrowserWindow, 'paste', 'webContents');
deprecate.member(BrowserWindow, 'selectAll', 'webContents');
deprecate.member(BrowserWindow, 'reloadIgnoringCache', 'webContents');
deprecate.member(BrowserWindow, 'isLoading', 'webContents');
deprecate.member(BrowserWindow, 'isWaitingForResponse', 'webContents');
deprecate.member(BrowserWindow, 'stop', 'webContents');
deprecate.member(BrowserWindow, 'isCrashed', 'webContents');
deprecate.member(BrowserWindow, 'print', 'webContents');
deprecate.member(BrowserWindow, 'printToPDF', 'webContents');
deprecate.rename(BrowserWindow, 'restart', 'reload');
deprecate.rename(BrowserWindow, 'loadUrl', 'loadURL');
deprecate.rename(BrowserWindow, 'getUrl', 'getURL');
BrowserWindow.prototype.executeJavaScriptInDevTools = deprecate('executeJavaScriptInDevTools', 'devToolsWebContents.executeJavaScript', function(code) {
var ref1;
return (ref1 = this.devToolsWebContents) != null ? ref1.executeJavaScript(code) : void 0;
});
BrowserWindow.prototype.getPageTitle = deprecate('getPageTitle', 'webContents.getTitle', function() {
var ref1;
return (ref1 = this.webContents) != null ? ref1.getTitle() : void 0;
});
module.exports = BrowserWindow;

View file

@ -1 +0,0 @@
module.exports = process.atomBinding 'content_tracing'

View file

@ -0,0 +1 @@
module.exports = process.atomBinding('content_tracing');

View file

@ -1,127 +0,0 @@
{app, BrowserWindow} = require 'electron'
binding = process.atomBinding 'dialog'
v8Util = process.atomBinding 'v8_util'
fileDialogProperties =
openFile: 1 << 0
openDirectory: 1 << 1
multiSelections: 1 << 2
createDirectory: 1 << 3
messageBoxTypes = ['none', 'info', 'warning', 'error', 'question']
messageBoxOptions =
noLink: 1 << 0
parseArgs = (window, options, callback) ->
unless window is null or window?.constructor is BrowserWindow
### Shift. ###
callback = options
options = window
window = null
if not callback? and typeof options is 'function'
### Shift. ###
callback = options
options = null
[window, options, callback]
checkAppInitialized = ->
throw new Error('dialog module can only be used after app is ready') unless app.isReady()
module.exports =
showOpenDialog: (args...) ->
checkAppInitialized()
[window, options, callback] = parseArgs args...
options ?= title: 'Open', properties: ['openFile']
options.properties ?= ['openFile']
throw new TypeError('Properties need to be array') unless Array.isArray options.properties
properties = 0
for prop, value of fileDialogProperties
properties |= value if prop in options.properties
options.title ?= ''
options.defaultPath ?= ''
options.filters ?= []
wrappedCallback =
if typeof callback is 'function'
(success, result) -> callback(if success then result)
else
null
binding.showOpenDialog String(options.title),
String(options.defaultPath),
options.filters
properties,
window,
wrappedCallback
showSaveDialog: (args...) ->
checkAppInitialized()
[window, options, callback] = parseArgs args...
options ?= title: 'Save'
options.title ?= ''
options.defaultPath ?= ''
options.filters ?= []
wrappedCallback =
if typeof callback is 'function'
(success, result) -> callback(if success then result)
else
null
binding.showSaveDialog String(options.title),
String(options.defaultPath),
options.filters
window,
wrappedCallback
showMessageBox: (args...) ->
checkAppInitialized()
[window, options, callback] = parseArgs args...
options ?= type: 'none'
options.type ?= 'none'
messageBoxType = messageBoxTypes.indexOf options.type
throw new TypeError('Invalid message box type') unless messageBoxType > -1
throw new TypeError('Buttons need to be array') unless Array.isArray options.buttons
options.title ?= ''
options.message ?= ''
options.detail ?= ''
options.icon ?= null
options.defaultId ?= -1
### Choose a default button to get selected when dialog is cancelled. ###
unless options.cancelId?
options.cancelId = 0
for text, i in options.buttons
if text.toLowerCase() in ['cancel', 'no']
options.cancelId = i
break
flags = if options.noLink then messageBoxOptions.noLink else 0
binding.showMessageBox messageBoxType,
options.buttons,
options.defaultId,
options.cancelId,
flags,
options.title,
options.message,
options.detail,
options.icon,
window,
callback
showErrorBox: (args...) ->
binding.showErrorBox args...
### Mark standard asynchronous functions. ###
for api in ['showMessageBox', 'showOpenDialog', 'showSaveDialog']
v8Util.setHiddenValue module.exports[api], 'asynchronous', true

View file

@ -0,0 +1,175 @@
var BrowserWindow, api, app, binding, checkAppInitialized, fileDialogProperties, j, len, messageBoxOptions, messageBoxTypes, parseArgs, ref, ref1, v8Util,
slice = [].slice,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
ref = require('electron'), app = ref.app, BrowserWindow = ref.BrowserWindow;
binding = process.atomBinding('dialog');
v8Util = process.atomBinding('v8_util');
fileDialogProperties = {
openFile: 1 << 0,
openDirectory: 1 << 1,
multiSelections: 1 << 2,
createDirectory: 1 << 3
};
messageBoxTypes = ['none', 'info', 'warning', 'error', 'question'];
messageBoxOptions = {
noLink: 1 << 0
};
parseArgs = function(window, options, callback) {
if (!(window === null || (window != null ? window.constructor : void 0) === BrowserWindow)) {
/* Shift. */
callback = options;
options = window;
window = null;
}
if ((callback == null) && typeof options === 'function') {
/* Shift. */
callback = options;
options = null;
}
return [window, options, callback];
};
checkAppInitialized = function() {
if (!app.isReady()) {
throw new Error('dialog module can only be used after app is ready');
}
};
module.exports = {
showOpenDialog: function() {
var args, callback, options, prop, properties, ref1, value, window, wrappedCallback;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2];
if (options == null) {
options = {
title: 'Open',
properties: ['openFile']
};
}
if (options.properties == null) {
options.properties = ['openFile'];
}
if (!Array.isArray(options.properties)) {
throw new TypeError('Properties need to be array');
}
properties = 0;
for (prop in fileDialogProperties) {
value = fileDialogProperties[prop];
if (indexOf.call(options.properties, prop) >= 0) {
properties |= value;
}
}
if (options.title == null) {
options.title = '';
}
if (options.defaultPath == null) {
options.defaultPath = '';
}
if (options.filters == null) {
options.filters = [];
}
wrappedCallback = typeof callback === 'function' ? function(success, result) {
return callback(success ? result : void 0);
} : null;
return binding.showOpenDialog(String(options.title), String(options.defaultPath), options.filters, properties, window, wrappedCallback);
},
showSaveDialog: function() {
var args, callback, options, ref1, window, wrappedCallback;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2];
if (options == null) {
options = {
title: 'Save'
};
}
if (options.title == null) {
options.title = '';
}
if (options.defaultPath == null) {
options.defaultPath = '';
}
if (options.filters == null) {
options.filters = [];
}
wrappedCallback = typeof callback === 'function' ? function(success, result) {
return callback(success ? result : void 0);
} : null;
return binding.showSaveDialog(String(options.title), String(options.defaultPath), options.filters, window, wrappedCallback);
},
showMessageBox: function() {
var args, callback, flags, i, j, len, messageBoxType, options, ref1, ref2, ref3, text, window;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
checkAppInitialized();
ref1 = parseArgs.apply(null, args), window = ref1[0], options = ref1[1], callback = ref1[2];
if (options == null) {
options = {
type: 'none'
};
}
if (options.type == null) {
options.type = 'none';
}
messageBoxType = messageBoxTypes.indexOf(options.type);
if (!(messageBoxType > -1)) {
throw new TypeError('Invalid message box type');
}
if (!Array.isArray(options.buttons)) {
throw new TypeError('Buttons need to be array');
}
if (options.title == null) {
options.title = '';
}
if (options.message == null) {
options.message = '';
}
if (options.detail == null) {
options.detail = '';
}
if (options.icon == null) {
options.icon = null;
}
if (options.defaultId == null) {
options.defaultId = -1;
}
/* Choose a default button to get selected when dialog is cancelled. */
if (options.cancelId == null) {
options.cancelId = 0;
ref2 = options.buttons;
for (i = j = 0, len = ref2.length; j < len; i = ++j) {
text = ref2[i];
if ((ref3 = text.toLowerCase()) === 'cancel' || ref3 === 'no') {
options.cancelId = i;
break;
}
}
}
flags = options.noLink ? messageBoxOptions.noLink : 0;
return binding.showMessageBox(messageBoxType, options.buttons, options.defaultId, options.cancelId, flags, options.title, options.message, options.detail, options.icon, window, callback);
},
showErrorBox: function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return binding.showErrorBox.apply(binding, args);
}
};
/* Mark standard asynchronous functions. */
ref1 = ['showMessageBox', 'showOpenDialog', 'showSaveDialog'];
for (j = 0, len = ref1.length; j < len; j++) {
api = ref1[j];
v8Util.setHiddenValue(module.exports[api], 'asynchronous', true);
}

View file

@ -1,57 +0,0 @@
common = require '../../../../common/api/lib/exports/electron'
### Import common modules. ###
common.defineProperties exports
Object.defineProperties exports,
### Browser side modules, please sort with alphabet order. ###
app:
enumerable: true
get: -> require '../app'
autoUpdater:
enumerable: true
get: -> require '../auto-updater'
BrowserWindow:
enumerable: true
get: -> require '../browser-window'
contentTracing:
enumerable: true
get: -> require '../content-tracing'
dialog:
enumerable: true
get: -> require '../dialog'
ipcMain:
enumerable: true
get: -> require '../ipc-main'
globalShortcut:
enumerable: true
get: -> require '../global-shortcut'
Menu:
enumerable: true
get: -> require '../menu'
MenuItem:
enumerable: true
get: -> require '../menu-item'
powerMonitor:
enumerable: true
get: -> require '../power-monitor'
powerSaveBlocker:
enumerable: true
get: -> require '../power-save-blocker'
protocol:
enumerable: true
get: -> require '../protocol'
screen:
enumerable: true
get: -> require '../screen'
session:
enumerable: true
get: -> require '../session'
Tray:
enumerable: true
get: -> require '../tray'
### The internal modules, invisible unless you know their names. ###
NavigationController:
get: -> require '../navigation-controller'
webContents:
get: -> require '../web-contents'

View file

@ -0,0 +1,115 @@
var common;
common = require('../../../../common/api/lib/exports/electron');
/* Import common modules. */
common.defineProperties(exports);
Object.defineProperties(exports, {
/* Browser side modules, please sort with alphabet order. */
app: {
enumerable: true,
get: function() {
return require('../app');
}
},
autoUpdater: {
enumerable: true,
get: function() {
return require('../auto-updater');
}
},
BrowserWindow: {
enumerable: true,
get: function() {
return require('../browser-window');
}
},
contentTracing: {
enumerable: true,
get: function() {
return require('../content-tracing');
}
},
dialog: {
enumerable: true,
get: function() {
return require('../dialog');
}
},
ipcMain: {
enumerable: true,
get: function() {
return require('../ipc-main');
}
},
globalShortcut: {
enumerable: true,
get: function() {
return require('../global-shortcut');
}
},
Menu: {
enumerable: true,
get: function() {
return require('../menu');
}
},
MenuItem: {
enumerable: true,
get: function() {
return require('../menu-item');
}
},
powerMonitor: {
enumerable: true,
get: function() {
return require('../power-monitor');
}
},
powerSaveBlocker: {
enumerable: true,
get: function() {
return require('../power-save-blocker');
}
},
protocol: {
enumerable: true,
get: function() {
return require('../protocol');
}
},
screen: {
enumerable: true,
get: function() {
return require('../screen');
}
},
session: {
enumerable: true,
get: function() {
return require('../session');
}
},
Tray: {
enumerable: true,
get: function() {
return require('../tray');
}
},
/* The internal modules, invisible unless you know their names. */
NavigationController: {
get: function() {
return require('../navigation-controller');
}
},
webContents: {
get: function() {
return require('../web-contents');
}
}
});

View file

@ -1,3 +0,0 @@
{globalShortcut} = process.atomBinding 'global_shortcut'
module.exports = globalShortcut

View file

@ -0,0 +1,5 @@
var globalShortcut;
globalShortcut = process.atomBinding('global_shortcut').globalShortcut;
module.exports = globalShortcut;

View file

@ -1,3 +0,0 @@
{EventEmitter} = require 'events'
module.exports = new EventEmitter

View file

@ -0,0 +1,5 @@
var EventEmitter;
EventEmitter = require('events').EventEmitter;
module.exports = new EventEmitter;

View file

@ -1,6 +0,0 @@
{deprecate, ipcMain} = require 'electron'
### This module is deprecated, we mirror everything from ipcMain. ###
deprecate.warn 'ipc module', 'require("electron").ipcMain'
module.exports = ipcMain

View file

@ -0,0 +1,10 @@
var deprecate, ipcMain, ref;
ref = require('electron'), deprecate = ref.deprecate, ipcMain = ref.ipcMain;
/* This module is deprecated, we mirror everything from ipcMain. */
deprecate.warn('ipc module', 'require("electron").ipcMain');
module.exports = ipcMain;

View file

@ -1,73 +0,0 @@
v8Util = process.atomBinding 'v8_util'
nextCommandId = 0
### Maps role to methods of webContents ###
rolesMap =
undo: 'undo'
redo: 'redo'
cut: 'cut'
copy: 'copy'
paste: 'paste'
selectall: 'selectAll'
minimize: 'minimize'
close: 'close'
### Maps methods that should be called directly on the BrowserWindow instance ###
methodInBrowserWindow =
minimize: true
close: true
class MenuItem
@types = ['normal', 'separator', 'submenu', 'checkbox', 'radio']
constructor: (options) ->
{Menu} = require 'electron'
{click, @selector, @type, @role, @label, @sublabel, @accelerator, @icon, @enabled, @visible, @checked, @submenu} = options
if @submenu? and @submenu.constructor isnt Menu
@submenu = Menu.buildFromTemplate @submenu
@type = 'submenu' if not @type? and @submenu?
throw new Error('Invalid submenu') if @type is 'submenu' and @submenu?.constructor isnt Menu
@overrideReadOnlyProperty 'type', 'normal'
@overrideReadOnlyProperty 'role'
@overrideReadOnlyProperty 'accelerator'
@overrideReadOnlyProperty 'icon'
@overrideReadOnlyProperty 'submenu'
@overrideProperty 'label', ''
@overrideProperty 'sublabel', ''
@overrideProperty 'enabled', true
@overrideProperty 'visible', true
@overrideProperty 'checked', false
throw new Error("Unknown menu type #{@type}") if MenuItem.types.indexOf(@type) is -1
@commandId = ++nextCommandId
@click = (focusedWindow) =>
### Manually flip the checked flags when clicked. ###
@checked = !@checked if @type in ['checkbox', 'radio']
if @role and rolesMap[@role] and process.platform isnt 'darwin' and focusedWindow?
methodName = rolesMap[@role]
if methodInBrowserWindow[methodName]
focusedWindow[methodName]()
else
focusedWindow.webContents?[methodName]()
else if typeof click is 'function'
click this, focusedWindow
else if typeof @selector is 'string'
Menu.sendActionToFirstResponder @selector
overrideProperty: (name, defaultValue=null) ->
this[name] ?= defaultValue
overrideReadOnlyProperty: (name, defaultValue=null) ->
this[name] ?= defaultValue
Object.defineProperty this, name,
enumerable: true
writable: false
value: this[name]
module.exports = MenuItem

View file

@ -0,0 +1,108 @@
var MenuItem, methodInBrowserWindow, nextCommandId, rolesMap, v8Util;
v8Util = process.atomBinding('v8_util');
nextCommandId = 0;
/* Maps role to methods of webContents */
rolesMap = {
undo: 'undo',
redo: 'redo',
cut: 'cut',
copy: 'copy',
paste: 'paste',
selectall: 'selectAll',
minimize: 'minimize',
close: 'close'
};
/* Maps methods that should be called directly on the BrowserWindow instance */
methodInBrowserWindow = {
minimize: true,
close: true
};
MenuItem = (function() {
MenuItem.types = ['normal', 'separator', 'submenu', 'checkbox', 'radio'];
function MenuItem(options) {
var Menu, click, ref;
Menu = require('electron').Menu;
click = options.click, this.selector = options.selector, this.type = options.type, this.role = options.role, this.label = options.label, this.sublabel = options.sublabel, this.accelerator = options.accelerator, this.icon = options.icon, this.enabled = options.enabled, this.visible = options.visible, this.checked = options.checked, this.submenu = options.submenu;
if ((this.submenu != null) && this.submenu.constructor !== Menu) {
this.submenu = Menu.buildFromTemplate(this.submenu);
}
if ((this.type == null) && (this.submenu != null)) {
this.type = 'submenu';
}
if (this.type === 'submenu' && ((ref = this.submenu) != null ? ref.constructor : void 0) !== Menu) {
throw new Error('Invalid submenu');
}
this.overrideReadOnlyProperty('type', 'normal');
this.overrideReadOnlyProperty('role');
this.overrideReadOnlyProperty('accelerator');
this.overrideReadOnlyProperty('icon');
this.overrideReadOnlyProperty('submenu');
this.overrideProperty('label', '');
this.overrideProperty('sublabel', '');
this.overrideProperty('enabled', true);
this.overrideProperty('visible', true);
this.overrideProperty('checked', false);
if (MenuItem.types.indexOf(this.type) === -1) {
throw new Error("Unknown menu type " + this.type);
}
this.commandId = ++nextCommandId;
this.click = (function(_this) {
return function(focusedWindow) {
/* Manually flip the checked flags when clicked. */
var methodName, ref1, ref2;
if ((ref1 = _this.type) === 'checkbox' || ref1 === 'radio') {
_this.checked = !_this.checked;
}
if (_this.role && rolesMap[_this.role] && process.platform !== 'darwin' && (focusedWindow != null)) {
methodName = rolesMap[_this.role];
if (methodInBrowserWindow[methodName]) {
return focusedWindow[methodName]();
} else {
return (ref2 = focusedWindow.webContents) != null ? ref2[methodName]() : void 0;
}
} else if (typeof click === 'function') {
return click(_this, focusedWindow);
} else if (typeof _this.selector === 'string') {
return Menu.sendActionToFirstResponder(_this.selector);
}
};
})(this);
}
MenuItem.prototype.overrideProperty = function(name, defaultValue) {
if (defaultValue == null) {
defaultValue = null;
}
return this[name] != null ? this[name] : this[name] = defaultValue;
};
MenuItem.prototype.overrideReadOnlyProperty = function(name, defaultValue) {
if (defaultValue == null) {
defaultValue = null;
}
if (this[name] == null) {
this[name] = defaultValue;
}
return Object.defineProperty(this, name, {
enumerable: true,
writable: false,
value: this[name]
});
};
return MenuItem;
})();
module.exports = MenuItem;

View file

@ -1,179 +0,0 @@
{BrowserWindow, MenuItem} = require 'electron'
{EventEmitter} = require 'events'
v8Util = process.atomBinding 'v8_util'
bindings = process.atomBinding 'menu'
### Automatically generated radio menu item's group id. ###
nextGroupId = 0
### Search between seperators to find a radio menu item and return its group id, ###
### otherwise generate a group id. ###
generateGroupId = (items, pos) ->
if pos > 0
for i in [pos - 1..0]
item = items[i]
return item.groupId if item.type is 'radio'
break if item.type is 'separator'
else if pos < items.length
for i in [pos..items.length - 1]
item = items[i]
return item.groupId if item.type is 'radio'
break if item.type is 'separator'
++nextGroupId
### Returns the index of item according to |id|. ###
indexOfItemById = (items, id) ->
return i for item, i in items when item.id is id
-1
### Returns the index of where to insert the item according to |position|. ###
indexToInsertByPosition = (items, position) ->
return items.length unless position
[query, id] = position.split '='
insertIndex = indexOfItemById items, id
if insertIndex is -1 and query isnt 'endof'
console.warn "Item with id '#{id}' is not found"
return items.length
switch query
when 'after'
insertIndex++
when 'endof'
### If the |id| doesn't exist, then create a new group with the |id|. ###
if insertIndex is -1
items.push id: id, type: 'separator'
insertIndex = items.length - 1
### Find the end of the group. ###
insertIndex++
while insertIndex < items.length and items[insertIndex].type isnt 'separator'
insertIndex++
insertIndex
Menu = bindings.Menu
Menu::__proto__ = EventEmitter.prototype
Menu::_init = ->
@commandsMap = {}
@groupsMap = {}
@items = []
@delegate =
isCommandIdChecked: (commandId) => @commandsMap[commandId]?.checked
isCommandIdEnabled: (commandId) => @commandsMap[commandId]?.enabled
isCommandIdVisible: (commandId) => @commandsMap[commandId]?.visible
getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator
getIconForCommandId: (commandId) => @commandsMap[commandId]?.icon
executeCommand: (commandId) =>
@commandsMap[commandId]?.click BrowserWindow.getFocusedWindow()
menuWillShow: =>
### Make sure radio groups have at least one menu item seleted. ###
for id, group of @groupsMap
checked = false
for radioItem in group when radioItem.checked
checked = true
break
v8Util.setHiddenValue group[0], 'checked', true unless checked
Menu::popup = (window, x, y) ->
unless window?.constructor is BrowserWindow
### Shift. ###
y = x
x = window
window = BrowserWindow.getFocusedWindow()
if x? and y?
@_popupAt(window, x, y)
else
@_popup window
Menu::append = (item) ->
@insert @getItemCount(), item
Menu::insert = (pos, item) ->
throw new TypeError('Invalid item') unless item?.constructor is MenuItem
switch item.type
when 'normal' then @insertItem pos, item.commandId, item.label
when 'checkbox' then @insertCheckItem pos, item.commandId, item.label
when 'separator' then @insertSeparator pos
when 'submenu' then @insertSubMenu pos, item.commandId, item.label, item.submenu
when 'radio'
### Grouping radio menu items. ###
item.overrideReadOnlyProperty 'groupId', generateGroupId(@items, pos)
@groupsMap[item.groupId] ?= []
@groupsMap[item.groupId].push item
### Setting a radio menu item should flip other items in the group. ###
v8Util.setHiddenValue item, 'checked', item.checked
Object.defineProperty item, 'checked',
enumerable: true
get: -> v8Util.getHiddenValue item, 'checked'
set: (val) =>
for otherItem in @groupsMap[item.groupId] when otherItem isnt item
v8Util.setHiddenValue otherItem, 'checked', false
v8Util.setHiddenValue item, 'checked', true
@insertRadioItem pos, item.commandId, item.label, item.groupId
@setSublabel pos, item.sublabel if item.sublabel?
@setIcon pos, item.icon if item.icon?
@setRole pos, item.role if item.role?
### Make menu accessable to items. ###
item.overrideReadOnlyProperty 'menu', this
### Remember the items. ###
@items.splice pos, 0, item
@commandsMap[item.commandId] = item
### Force menuWillShow to be called ###
Menu::_callMenuWillShow = ->
@delegate?.menuWillShow()
item.submenu._callMenuWillShow() for item in @items when item.submenu?
applicationMenu = null
Menu.setApplicationMenu = (menu) ->
throw new TypeError('Invalid menu') unless menu is null or menu.constructor is Menu
### Keep a reference. ###
applicationMenu = menu
if process.platform is 'darwin'
return if menu is null
menu._callMenuWillShow()
bindings.setApplicationMenu menu
else
windows = BrowserWindow.getAllWindows()
w.setMenu menu for w in windows
Menu.getApplicationMenu = -> applicationMenu
Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder
Menu.buildFromTemplate = (template) ->
throw new TypeError('Invalid template for Menu') unless Array.isArray template
positionedTemplate = []
insertIndex = 0
for item in template
if item.position
insertIndex = indexToInsertByPosition positionedTemplate, item.position
else
### If no |position| is specified, insert after last item. ###
insertIndex++
positionedTemplate.splice insertIndex, 0, item
menu = new Menu
for item in positionedTemplate
throw new TypeError('Invalid template for MenuItem') unless typeof item is 'object'
menuItem = new MenuItem(item)
menuItem[key] ?= value for key, value of item
menu.append menuItem
menu
module.exports = Menu

View file

@ -0,0 +1,350 @@
var BrowserWindow, EventEmitter, Menu, MenuItem, applicationMenu, bindings, generateGroupId, indexOfItemById, indexToInsertByPosition, nextGroupId, ref, v8Util;
ref = require('electron'), BrowserWindow = ref.BrowserWindow, MenuItem = ref.MenuItem;
EventEmitter = require('events').EventEmitter;
v8Util = process.atomBinding('v8_util');
bindings = process.atomBinding('menu');
/* Automatically generated radio menu item's group id. */
nextGroupId = 0;
/* Search between seperators to find a radio menu item and return its group id, */
/* otherwise generate a group id. */
generateGroupId = function(items, pos) {
var i, item, j, k, ref1, ref2, ref3;
if (pos > 0) {
for (i = j = ref1 = pos - 1; ref1 <= 0 ? j <= 0 : j >= 0; i = ref1 <= 0 ? ++j : --j) {
item = items[i];
if (item.type === 'radio') {
return item.groupId;
}
if (item.type === 'separator') {
break;
}
}
} else if (pos < items.length) {
for (i = k = ref2 = pos, ref3 = items.length - 1; ref2 <= ref3 ? k <= ref3 : k >= ref3; i = ref2 <= ref3 ? ++k : --k) {
item = items[i];
if (item.type === 'radio') {
return item.groupId;
}
if (item.type === 'separator') {
break;
}
}
}
return ++nextGroupId;
};
/* Returns the index of item according to |id|. */
indexOfItemById = function(items, id) {
var i, item, j, len;
for (i = j = 0, len = items.length; j < len; i = ++j) {
item = items[i];
if (item.id === id) {
return i;
}
}
return -1;
};
/* Returns the index of where to insert the item according to |position|. */
indexToInsertByPosition = function(items, position) {
var id, insertIndex, query, ref1;
if (!position) {
return items.length;
}
ref1 = position.split('='), query = ref1[0], id = ref1[1];
insertIndex = indexOfItemById(items, id);
if (insertIndex === -1 && query !== 'endof') {
console.warn("Item with id '" + id + "' is not found");
return items.length;
}
switch (query) {
case 'after':
insertIndex++;
break;
case 'endof':
/* If the |id| doesn't exist, then create a new group with the |id|. */
if (insertIndex === -1) {
items.push({
id: id,
type: 'separator'
});
insertIndex = items.length - 1;
}
/* Find the end of the group. */
insertIndex++;
while (insertIndex < items.length && items[insertIndex].type !== 'separator') {
insertIndex++;
}
}
return insertIndex;
};
Menu = bindings.Menu;
Menu.prototype.__proto__ = EventEmitter.prototype;
Menu.prototype._init = function() {
this.commandsMap = {};
this.groupsMap = {};
this.items = [];
return this.delegate = {
isCommandIdChecked: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.checked : void 0;
};
})(this),
isCommandIdEnabled: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.enabled : void 0;
};
})(this),
isCommandIdVisible: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.visible : void 0;
};
})(this),
getAcceleratorForCommandId: (function(_this) {
return function(commandId) {
var ref1;
return (ref1 = _this.commandsMap[commandId]) != null ? ref1.accelerator : void 0;
};
})(this),
getIconForCommandId: (function(_this) {
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. */
var checked, group, id, j, len, radioItem, ref1, results;
ref1 = _this.groupsMap;
results = [];
for (id in ref1) {
group = ref1[id];
checked = false;
for (j = 0, len = group.length; j < len; j++) {
radioItem = group[j];
if (!radioItem.checked) {
continue;
}
checked = true;
break;
}
if (!checked) {
results.push(v8Util.setHiddenValue(group[0], 'checked', true));
} else {
results.push(void 0);
}
}
return results;
};
})(this)
};
};
Menu.prototype.popup = function(window, x, y) {
if ((window != null ? window.constructor : void 0) !== BrowserWindow) {
/* Shift. */
y = x;
x = window;
window = BrowserWindow.getFocusedWindow();
}
if ((x != null) && (y != null)) {
return this._popupAt(window, x, y);
} else {
return this._popup(window);
}
};
Menu.prototype.append = function(item) {
return this.insert(this.getItemCount(), item);
};
Menu.prototype.insert = function(pos, item) {
var base, name;
if ((item != null ? item.constructor : void 0) !== MenuItem) {
throw new TypeError('Invalid item');
}
switch (item.type) {
case 'normal':
this.insertItem(pos, item.commandId, item.label);
break;
case 'checkbox':
this.insertCheckItem(pos, item.commandId, item.label);
break;
case 'separator':
this.insertSeparator(pos);
break;
case 'submenu':
this.insertSubMenu(pos, item.commandId, item.label, item.submenu);
break;
case 'radio':
/* Grouping radio menu items. */
item.overrideReadOnlyProperty('groupId', generateGroupId(this.items, pos));
if ((base = this.groupsMap)[name = item.groupId] == null) {
base[name] = [];
}
this.groupsMap[item.groupId].push(item);
/* Setting a radio menu item should flip other items in the group. */
v8Util.setHiddenValue(item, 'checked', item.checked);
Object.defineProperty(item, 'checked', {
enumerable: true,
get: function() {
return v8Util.getHiddenValue(item, 'checked');
},
set: (function(_this) {
return function(val) {
var j, len, otherItem, ref1;
ref1 = _this.groupsMap[item.groupId];
for (j = 0, len = ref1.length; j < len; j++) {
otherItem = ref1[j];
if (otherItem !== item) {
v8Util.setHiddenValue(otherItem, 'checked', false);
}
}
return v8Util.setHiddenValue(item, 'checked', true);
};
})(this)
});
this.insertRadioItem(pos, item.commandId, item.label, item.groupId);
}
if (item.sublabel != null) {
this.setSublabel(pos, item.sublabel);
}
if (item.icon != null) {
this.setIcon(pos, item.icon);
}
if (item.role != null) {
this.setRole(pos, item.role);
}
/* Make menu accessable to items. */
item.overrideReadOnlyProperty('menu', this);
/* Remember the items. */
this.items.splice(pos, 0, item);
return this.commandsMap[item.commandId] = item;
};
/* Force menuWillShow to be called */
Menu.prototype._callMenuWillShow = function() {
var item, j, len, ref1, ref2, results;
if ((ref1 = this.delegate) != null) {
ref1.menuWillShow();
}
ref2 = this.items;
results = [];
for (j = 0, len = ref2.length; j < len; j++) {
item = ref2[j];
if (item.submenu != null) {
results.push(item.submenu._callMenuWillShow());
}
}
return results;
};
applicationMenu = null;
Menu.setApplicationMenu = function(menu) {
var j, len, results, w, windows;
if (!(menu === null || menu.constructor === Menu)) {
throw new TypeError('Invalid menu');
}
/* Keep a reference. */
applicationMenu = menu;
if (process.platform === 'darwin') {
if (menu === null) {
return;
}
menu._callMenuWillShow();
return bindings.setApplicationMenu(menu);
} else {
windows = BrowserWindow.getAllWindows();
results = [];
for (j = 0, len = windows.length; j < len; j++) {
w = windows[j];
results.push(w.setMenu(menu));
}
return results;
}
};
Menu.getApplicationMenu = function() {
return applicationMenu;
};
Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder;
Menu.buildFromTemplate = function(template) {
var insertIndex, item, j, k, key, len, len1, menu, menuItem, positionedTemplate, value;
if (!Array.isArray(template)) {
throw new TypeError('Invalid template for Menu');
}
positionedTemplate = [];
insertIndex = 0;
for (j = 0, len = template.length; j < len; j++) {
item = template[j];
if (item.position) {
insertIndex = indexToInsertByPosition(positionedTemplate, item.position);
} else {
/* If no |position| is specified, insert after last item. */
insertIndex++;
}
positionedTemplate.splice(insertIndex, 0, item);
}
menu = new Menu;
for (k = 0, len1 = positionedTemplate.length; k < len1; k++) {
item = positionedTemplate[k];
if (typeof item !== 'object') {
throw new TypeError('Invalid template for MenuItem');
}
menuItem = new MenuItem(item);
for (key in item) {
value = item[key];
if (menuItem[key] == null) {
menuItem[key] = value;
}
}
menu.append(menuItem);
}
return menu;
};
module.exports = Menu;

View file

@ -1,127 +0,0 @@
{ipcMain} = require 'electron'
### The history operation in renderer is redirected to browser. ###
ipcMain.on 'ATOM_SHELL_NAVIGATION_CONTROLLER', (event, method, args...) ->
event.sender[method] args...
ipcMain.on 'ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', (event, method, args...) ->
event.returnValue = event.sender[method] args...
###
JavaScript implementation of Chromium's NavigationController.
Instead of relying on Chromium for history control, we compeletely do history
control on user land, and only rely on WebContents.loadURL for navigation.
This helps us avoid Chromium's various optimizations so we can ensure renderer
process is restarted everytime.
###
class NavigationController
constructor: (@webContents) ->
@clearHistory()
### webContents may have already navigated to a page. ###
if @webContents._getURL()
@currentIndex++
@history.push @webContents._getURL()
@webContents.on 'navigation-entry-commited', (event, url, inPage, replaceEntry) =>
if @inPageIndex > -1 and not inPage
### Navigated to a new page, clear in-page mark. ###
@inPageIndex = -1
else if @inPageIndex is -1 and inPage
### Started in-page navigations. ###
@inPageIndex = @currentIndex
if @pendingIndex >= 0
### Go to index. ###
@currentIndex = @pendingIndex
@pendingIndex = -1
@history[@currentIndex] = url
else if replaceEntry
### Non-user initialized navigation. ###
@history[@currentIndex] = url
else
### Normal navigation. Clear history. ###
@history = @history.slice 0, @currentIndex + 1
currentEntry = @history[@currentIndex]
if currentEntry?.url isnt url
@currentIndex++
@history.push url
loadURL: (url, options={}) ->
@pendingIndex = -1
@webContents._loadURL url, options
@webContents.emit 'load-url', url, options
getURL: ->
if @currentIndex is -1
''
else
@history[@currentIndex]
stop: ->
@pendingIndex = -1
@webContents._stop()
reload: ->
@pendingIndex = @currentIndex
@webContents._loadURL @getURL(), {}
reloadIgnoringCache: ->
@pendingIndex = @currentIndex
@webContents._loadURL @getURL(), {extraHeaders: "pragma: no-cache\n"}
canGoBack: ->
@getActiveIndex() > 0
canGoForward: ->
@getActiveIndex() < @history.length - 1
canGoToIndex: (index) ->
index >=0 and index < @history.length
canGoToOffset: (offset) ->
@canGoToIndex @currentIndex + offset
clearHistory: ->
@history = []
@currentIndex = -1
@pendingIndex = -1
@inPageIndex = -1
goBack: ->
return unless @canGoBack()
@pendingIndex = @getActiveIndex() - 1
if @inPageIndex > -1 and @pendingIndex >= @inPageIndex
@webContents._goBack()
else
@webContents._loadURL @history[@pendingIndex], {}
goForward: ->
return unless @canGoForward()
@pendingIndex = @getActiveIndex() + 1
if @inPageIndex > -1 and @pendingIndex >= @inPageIndex
@webContents._goForward()
else
@webContents._loadURL @history[@pendingIndex], {}
goToIndex: (index) ->
return unless @canGoToIndex index
@pendingIndex = index
@webContents._loadURL @history[@pendingIndex], {}
goToOffset: (offset) ->
return unless @canGoToOffset offset
pendingIndex = @currentIndex + offset
if @inPageIndex > -1 and pendingIndex >= @inPageIndex
@pendingIndex = pendingIndex
@webContents._goToOffset offset
else
@goToIndex pendingIndex
getActiveIndex: ->
if @pendingIndex is -1 then @currentIndex else @pendingIndex
length: ->
@history.length
module.exports = NavigationController

View file

@ -0,0 +1,195 @@
var NavigationController, ipcMain,
slice = [].slice;
ipcMain = require('electron').ipcMain;
/* The history operation in renderer is redirected to browser. */
ipcMain.on('ATOM_SHELL_NAVIGATION_CONTROLLER', function() {
var args, event, method, ref;
event = arguments[0], method = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
return (ref = event.sender)[method].apply(ref, args);
});
ipcMain.on('ATOM_SHELL_SYNC_NAVIGATION_CONTROLLER', function() {
var args, event, method, ref;
event = arguments[0], method = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
return event.returnValue = (ref = event.sender)[method].apply(ref, args);
});
/*
JavaScript implementation of Chromium's NavigationController.
Instead of relying on Chromium for history control, we compeletely do history
control on user land, and only rely on WebContents.loadURL for navigation.
This helps us avoid Chromium's various optimizations so we can ensure renderer
process is restarted everytime.
*/
NavigationController = (function() {
function NavigationController(webContents) {
this.webContents = webContents;
this.clearHistory();
/* webContents may have already navigated to a page. */
if (this.webContents._getURL()) {
this.currentIndex++;
this.history.push(this.webContents._getURL());
}
this.webContents.on('navigation-entry-commited', (function(_this) {
return function(event, url, inPage, replaceEntry) {
var currentEntry;
if (_this.inPageIndex > -1 && !inPage) {
/* Navigated to a new page, clear in-page mark. */
_this.inPageIndex = -1;
} else if (_this.inPageIndex === -1 && inPage) {
/* Started in-page navigations. */
_this.inPageIndex = _this.currentIndex;
}
if (_this.pendingIndex >= 0) {
/* Go to index. */
_this.currentIndex = _this.pendingIndex;
_this.pendingIndex = -1;
return _this.history[_this.currentIndex] = url;
} else if (replaceEntry) {
/* Non-user initialized navigation. */
return _this.history[_this.currentIndex] = url;
} else {
/* Normal navigation. Clear history. */
_this.history = _this.history.slice(0, _this.currentIndex + 1);
currentEntry = _this.history[_this.currentIndex];
if ((currentEntry != null ? currentEntry.url : void 0) !== url) {
_this.currentIndex++;
return _this.history.push(url);
}
}
};
})(this));
}
NavigationController.prototype.loadURL = function(url, options) {
if (options == null) {
options = {};
}
this.pendingIndex = -1;
this.webContents._loadURL(url, options);
return this.webContents.emit('load-url', url, options);
};
NavigationController.prototype.getURL = function() {
if (this.currentIndex === -1) {
return '';
} else {
return this.history[this.currentIndex];
}
};
NavigationController.prototype.stop = function() {
this.pendingIndex = -1;
return this.webContents._stop();
};
NavigationController.prototype.reload = function() {
this.pendingIndex = this.currentIndex;
return this.webContents._loadURL(this.getURL(), {});
};
NavigationController.prototype.reloadIgnoringCache = function() {
this.pendingIndex = this.currentIndex;
return this.webContents._loadURL(this.getURL(), {
extraHeaders: "pragma: no-cache\n"
});
};
NavigationController.prototype.canGoBack = function() {
return this.getActiveIndex() > 0;
};
NavigationController.prototype.canGoForward = function() {
return this.getActiveIndex() < this.history.length - 1;
};
NavigationController.prototype.canGoToIndex = function(index) {
return index >= 0 && index < this.history.length;
};
NavigationController.prototype.canGoToOffset = function(offset) {
return this.canGoToIndex(this.currentIndex + offset);
};
NavigationController.prototype.clearHistory = function() {
this.history = [];
this.currentIndex = -1;
this.pendingIndex = -1;
return this.inPageIndex = -1;
};
NavigationController.prototype.goBack = function() {
if (!this.canGoBack()) {
return;
}
this.pendingIndex = this.getActiveIndex() - 1;
if (this.inPageIndex > -1 && this.pendingIndex >= this.inPageIndex) {
return this.webContents._goBack();
} else {
return this.webContents._loadURL(this.history[this.pendingIndex], {});
}
};
NavigationController.prototype.goForward = function() {
if (!this.canGoForward()) {
return;
}
this.pendingIndex = this.getActiveIndex() + 1;
if (this.inPageIndex > -1 && this.pendingIndex >= this.inPageIndex) {
return this.webContents._goForward();
} else {
return this.webContents._loadURL(this.history[this.pendingIndex], {});
}
};
NavigationController.prototype.goToIndex = function(index) {
if (!this.canGoToIndex(index)) {
return;
}
this.pendingIndex = index;
return this.webContents._loadURL(this.history[this.pendingIndex], {});
};
NavigationController.prototype.goToOffset = function(offset) {
var pendingIndex;
if (!this.canGoToOffset(offset)) {
return;
}
pendingIndex = this.currentIndex + offset;
if (this.inPageIndex > -1 && pendingIndex >= this.inPageIndex) {
this.pendingIndex = pendingIndex;
return this.webContents._goToOffset(offset);
} else {
return this.goToIndex(pendingIndex);
}
};
NavigationController.prototype.getActiveIndex = function() {
if (this.pendingIndex === -1) {
return this.currentIndex;
} else {
return this.pendingIndex;
}
};
NavigationController.prototype.length = function() {
return this.history.length;
};
return NavigationController;
})();
module.exports = NavigationController;

View file

@ -1,7 +0,0 @@
{EventEmitter} = require 'events'
{powerMonitor} = process.atomBinding 'power_monitor'
powerMonitor.__proto__ = EventEmitter.prototype
module.exports = powerMonitor

View file

@ -0,0 +1,9 @@
var EventEmitter, powerMonitor;
EventEmitter = require('events').EventEmitter;
powerMonitor = process.atomBinding('power_monitor').powerMonitor;
powerMonitor.__proto__ = EventEmitter.prototype;
module.exports = powerMonitor;

View file

@ -1,3 +0,0 @@
{powerSaveBlocker} = process.atomBinding 'power_save_blocker'
module.exports = powerSaveBlocker

View file

@ -0,0 +1,5 @@
var powerSaveBlocker;
powerSaveBlocker = process.atomBinding('power_save_blocker').powerSaveBlocker;
module.exports = powerSaveBlocker;

View file

@ -1,25 +0,0 @@
{app} = require 'electron'
throw new Error('Can not initialize protocol module before app is ready') unless app.isReady()
{protocol} = process.atomBinding 'protocol'
### Warn about removed APIs. ###
logAndThrow = (callback, message) ->
console.error message
if callback then callback(new Error(message)) else throw new Error(message)
protocol.registerProtocol = (scheme, handler, callback) ->
logAndThrow callback,
'registerProtocol API has been replaced by the
register[File/Http/Buffer/String]Protocol API family, please
switch to the new APIs.'
protocol.isHandledProtocol = (scheme, callback) ->
logAndThrow callback,
'isHandledProtocol API has been replaced by isProtocolHandled.'
protocol.interceptProtocol = (scheme, handler, callback) ->
logAndThrow callback,
'interceptProtocol API has been replaced by the
intercept[File/Http/Buffer/String]Protocol API family, please
switch to the new APIs.'
module.exports = protocol

View file

@ -0,0 +1,35 @@
var app, logAndThrow, protocol;
app = require('electron').app;
if (!app.isReady()) {
throw new Error('Can not initialize protocol module before app is ready');
}
protocol = process.atomBinding('protocol').protocol;
/* Warn about removed APIs. */
logAndThrow = function(callback, message) {
console.error(message);
if (callback) {
return callback(new Error(message));
} else {
throw new Error(message);
}
};
protocol.registerProtocol = function(scheme, handler, callback) {
return logAndThrow(callback, 'registerProtocol API has been replaced by the register[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.');
};
protocol.isHandledProtocol = function(scheme, callback) {
return logAndThrow(callback, 'isHandledProtocol API has been replaced by isProtocolHandled.');
};
protocol.interceptProtocol = function(scheme, handler, callback) {
return logAndThrow(callback, 'interceptProtocol API has been replaced by the intercept[File/Http/Buffer/String]Protocol API family, please switch to the new APIs.');
};
module.exports = protocol;

View file

@ -1,6 +0,0 @@
{EventEmitter} = require 'events'
{screen} = process.atomBinding 'screen'
screen.__proto__ = EventEmitter.prototype
module.exports = screen

View file

@ -0,0 +1,9 @@
var EventEmitter, screen;
EventEmitter = require('events').EventEmitter;
screen = process.atomBinding('screen').screen;
screen.__proto__ = EventEmitter.prototype;
module.exports = screen;

View file

@ -1,24 +0,0 @@
{EventEmitter} = require 'events'
bindings = process.atomBinding 'session'
PERSIST_PERFIX = 'persist:'
### Returns the Session from |partition| string. ###
exports.fromPartition = (partition='') ->
return exports.defaultSession if partition is ''
if partition.startsWith PERSIST_PERFIX
bindings.fromPartition partition.substr(PERSIST_PERFIX.length), false
else
bindings.fromPartition partition, true
### Returns the default session. ###
Object.defineProperty exports, 'defaultSession',
enumerable: true
get: -> bindings.fromPartition '', false
wrapSession = (session) ->
### session is an EventEmitter. ###
session.__proto__ = EventEmitter.prototype
bindings._setWrapSession wrapSession

View file

@ -0,0 +1,42 @@
var EventEmitter, PERSIST_PERFIX, bindings, wrapSession;
EventEmitter = require('events').EventEmitter;
bindings = process.atomBinding('session');
PERSIST_PERFIX = 'persist:';
/* Returns the Session from |partition| string. */
exports.fromPartition = function(partition) {
if (partition == null) {
partition = '';
}
if (partition === '') {
return exports.defaultSession;
}
if (partition.startsWith(PERSIST_PERFIX)) {
return bindings.fromPartition(partition.substr(PERSIST_PERFIX.length), false);
} else {
return bindings.fromPartition(partition, true);
}
};
/* Returns the default session. */
Object.defineProperty(exports, 'defaultSession', {
enumerable: true,
get: function() {
return bindings.fromPartition('', false);
}
});
wrapSession = function(session) {
/* session is an EventEmitter. */
return session.__proto__ = EventEmitter.prototype;
};
bindings._setWrapSession(wrapSession);

View file

@ -1,20 +0,0 @@
{deprecate} = require 'electron'
{EventEmitter} = require 'events'
{Tray} = process.atomBinding 'tray'
Tray::__proto__ = EventEmitter.prototype
Tray::_init = ->
### Deprecated. ###
deprecate.rename this, 'popContextMenu', 'popUpContextMenu'
deprecate.event this, 'clicked', 'click'
deprecate.event this, 'double-clicked', 'double-click'
deprecate.event this, 'right-clicked', 'right-click'
deprecate.event this, 'balloon-clicked', 'balloon-click'
Tray::setContextMenu = (menu) ->
@_setContextMenu menu
### Keep a strong reference of menu. ###
@menu = menu
module.exports = Tray

View file

@ -0,0 +1,28 @@
var EventEmitter, Tray, deprecate;
deprecate = require('electron').deprecate;
EventEmitter = require('events').EventEmitter;
Tray = process.atomBinding('tray').Tray;
Tray.prototype.__proto__ = EventEmitter.prototype;
Tray.prototype._init = function() {
/* Deprecated. */
deprecate.rename(this, 'popContextMenu', 'popUpContextMenu');
deprecate.event(this, 'clicked', 'click');
deprecate.event(this, 'double-clicked', 'double-click');
deprecate.event(this, 'right-clicked', 'right-click');
return deprecate.event(this, 'balloon-clicked', 'balloon-click');
};
Tray.prototype.setContextMenu = function(menu) {
this._setContextMenu(menu);
/* Keep a strong reference of menu. */
return this.menu = menu;
};
module.exports = Tray;

View file

@ -1,141 +0,0 @@
{EventEmitter} = require 'events'
{deprecate, ipcMain, session, NavigationController, Menu} = require 'electron'
binding = process.atomBinding 'web_contents'
nextId = 0
getNextId = -> ++nextId
PDFPageSize =
A5:
custom_display_name: "A5"
height_microns: 210000
name: "ISO_A5"
width_microns: 148000
A4:
custom_display_name: "A4"
height_microns: 297000
name: "ISO_A4"
is_default: "true"
width_microns: 210000
A3:
custom_display_name: "A3"
height_microns: 420000
name: "ISO_A3"
width_microns: 297000
Legal:
custom_display_name: "Legal"
height_microns: 355600
name: "NA_LEGAL"
width_microns: 215900
Letter:
custom_display_name: "Letter"
height_microns: 279400
name: "NA_LETTER"
width_microns: 215900
Tabloid:
height_microns: 431800
name: "NA_LEDGER"
width_microns: 279400
custom_display_name: "Tabloid"
wrapWebContents = (webContents) ->
### webContents is an EventEmitter. ###
webContents.__proto__ = EventEmitter.prototype
### WebContents::send(channel, args..) ###
webContents.send = (channel, args...) ->
@_send channel, [args...]
###
Make sure webContents.executeJavaScript would run the code only when the
web contents has been loaded.
###
webContents.executeJavaScript = (code, hasUserGesture=false) ->
if @getURL() and not @isLoading()
@_executeJavaScript code, hasUserGesture
else
webContents.once 'did-finish-load', @_executeJavaScript.bind(this, code, hasUserGesture)
### The navigation controller. ###
controller = new NavigationController(webContents)
for name, method of NavigationController.prototype when method instanceof Function
do (name, method) ->
webContents[name] = -> method.apply controller, arguments
### Dispatch IPC messages to the ipc module. ###
webContents.on 'ipc-message', (event, packed) ->
[channel, args...] = packed
ipcMain.emit channel, event, args...
webContents.on 'ipc-message-sync', (event, packed) ->
[channel, args...] = packed
Object.defineProperty event, 'returnValue', set: (value) -> event.sendReply JSON.stringify(value)
ipcMain.emit channel, event, args...
### Handle context menu action request from pepper plugin. ###
webContents.on 'pepper-context-menu', (event, params) ->
menu = Menu.buildFromTemplate params.menu
menu.popup params.x, params.y
### This error occurs when host could not be found. ###
webContents.on 'did-fail-provisional-load', (args...) ->
###
Calling loadURL during this event might cause crash, so delay the event
until next tick.
###
setImmediate => @emit 'did-fail-load', args...
### Delays the page-title-updated event to next tick. ###
webContents.on '-page-title-updated', (args...) ->
setImmediate => @emit 'page-title-updated', args...
### Deprecated. ###
deprecate.rename webContents, 'loadUrl', 'loadURL'
deprecate.rename webContents, 'getUrl', 'getURL'
deprecate.event webContents, 'page-title-set', 'page-title-updated', (args...) ->
@emit 'page-title-set', args...
webContents.printToPDF = (options, callback) ->
printingSetting =
pageRage: []
mediaSize: {}
landscape: false
color: 2
headerFooterEnabled: false
marginsType: 0
isFirstRequest: false
requestID: getNextId()
previewModifiable: true
printToPDF: true
printWithCloudPrint: false
printWithPrivet: false
printWithExtension: false
deviceName: "Save as PDF"
generateDraftData: true
fitToPageEnabled: false
duplex: 0
copies: 1
collate: true
shouldPrintBackgrounds: false
shouldPrintSelectionOnly: false
if options.landscape
printingSetting.landscape = options.landscape
if options.marginsType
printingSetting.marginsType = options.marginsType
if options.printSelectionOnly
printingSetting.shouldPrintSelectionOnly = options.printSelectionOnly
if options.printBackground
printingSetting.shouldPrintBackgrounds = options.printBackground
if options.pageSize and PDFPageSize[options.pageSize]
printingSetting.mediaSize = PDFPageSize[options.pageSize]
else
printingSetting.mediaSize = PDFPageSize['A4']
@_printToPDF printingSetting, callback
binding._setWrapWebContents wrapWebContents
module.exports.create = (options={}) ->
binding.create(options)

View file

@ -0,0 +1,210 @@
var EventEmitter, Menu, NavigationController, PDFPageSize, binding, deprecate, getNextId, ipcMain, nextId, ref, session, wrapWebContents,
slice = [].slice;
EventEmitter = require('events').EventEmitter;
ref = require('electron'), deprecate = ref.deprecate, ipcMain = ref.ipcMain, session = ref.session, NavigationController = ref.NavigationController, Menu = ref.Menu;
binding = process.atomBinding('web_contents');
nextId = 0;
getNextId = function() {
return ++nextId;
};
PDFPageSize = {
A5: {
custom_display_name: "A5",
height_microns: 210000,
name: "ISO_A5",
width_microns: 148000
},
A4: {
custom_display_name: "A4",
height_microns: 297000,
name: "ISO_A4",
is_default: "true",
width_microns: 210000
},
A3: {
custom_display_name: "A3",
height_microns: 420000,
name: "ISO_A3",
width_microns: 297000
},
Legal: {
custom_display_name: "Legal",
height_microns: 355600,
name: "NA_LEGAL",
width_microns: 215900
},
Letter: {
custom_display_name: "Letter",
height_microns: 279400,
name: "NA_LETTER",
width_microns: 215900
},
Tabloid: {
height_microns: 431800,
name: "NA_LEDGER",
width_microns: 279400,
custom_display_name: "Tabloid"
}
};
wrapWebContents = function(webContents) {
/* webContents is an EventEmitter. */
var controller, method, name, ref1;
webContents.__proto__ = EventEmitter.prototype;
/* WebContents::send(channel, args..) */
webContents.send = function() {
var args, channel;
channel = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
return this._send(channel, slice.call(args));
};
/*
Make sure webContents.executeJavaScript would run the code only when the
web contents has been loaded.
*/
webContents.executeJavaScript = function(code, hasUserGesture) {
if (hasUserGesture == null) {
hasUserGesture = false;
}
if (this.getURL() && !this.isLoading()) {
return this._executeJavaScript(code, hasUserGesture);
} else {
return webContents.once('did-finish-load', this._executeJavaScript.bind(this, code, hasUserGesture));
}
};
/* The navigation controller. */
controller = new NavigationController(webContents);
ref1 = NavigationController.prototype;
for (name in ref1) {
method = ref1[name];
if (method instanceof Function) {
(function(name, method) {
return webContents[name] = function() {
return method.apply(controller, arguments);
};
})(name, method);
}
}
/* Dispatch IPC messages to the ipc module. */
webContents.on('ipc-message', function(event, packed) {
var args, channel;
channel = packed[0], args = 2 <= packed.length ? slice.call(packed, 1) : [];
return ipcMain.emit.apply(ipcMain, [channel, event].concat(slice.call(args)));
});
webContents.on('ipc-message-sync', function(event, packed) {
var args, channel;
channel = packed[0], args = 2 <= packed.length ? slice.call(packed, 1) : [];
Object.defineProperty(event, 'returnValue', {
set: function(value) {
return event.sendReply(JSON.stringify(value));
}
});
return ipcMain.emit.apply(ipcMain, [channel, event].concat(slice.call(args)));
});
/* Handle context menu action request from pepper plugin. */
webContents.on('pepper-context-menu', function(event, params) {
var menu;
menu = Menu.buildFromTemplate(params.menu);
return menu.popup(params.x, params.y);
});
/* This error occurs when host could not be found. */
webContents.on('did-fail-provisional-load', function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
/*
Calling loadURL during this event might cause crash, so delay the event
until next tick.
*/
return setImmediate((function(_this) {
return function() {
return _this.emit.apply(_this, ['did-fail-load'].concat(slice.call(args)));
};
})(this));
});
/* Delays the page-title-updated event to next tick. */
webContents.on('-page-title-updated', function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return setImmediate((function(_this) {
return function() {
return _this.emit.apply(_this, ['page-title-updated'].concat(slice.call(args)));
};
})(this));
});
/* Deprecated. */
deprecate.rename(webContents, 'loadUrl', 'loadURL');
deprecate.rename(webContents, 'getUrl', 'getURL');
deprecate.event(webContents, 'page-title-set', 'page-title-updated', function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return this.emit.apply(this, ['page-title-set'].concat(slice.call(args)));
});
return webContents.printToPDF = function(options, callback) {
var printingSetting;
printingSetting = {
pageRage: [],
mediaSize: {},
landscape: false,
color: 2,
headerFooterEnabled: false,
marginsType: 0,
isFirstRequest: false,
requestID: getNextId(),
previewModifiable: true,
printToPDF: true,
printWithCloudPrint: false,
printWithPrivet: false,
printWithExtension: false,
deviceName: "Save as PDF",
generateDraftData: true,
fitToPageEnabled: false,
duplex: 0,
copies: 1,
collate: true,
shouldPrintBackgrounds: false,
shouldPrintSelectionOnly: false
};
if (options.landscape) {
printingSetting.landscape = options.landscape;
}
if (options.marginsType) {
printingSetting.marginsType = options.marginsType;
}
if (options.printSelectionOnly) {
printingSetting.shouldPrintSelectionOnly = options.printSelectionOnly;
}
if (options.printBackground) {
printingSetting.shouldPrintBackgrounds = options.printBackground;
}
if (options.pageSize && PDFPageSize[options.pageSize]) {
printingSetting.mediaSize = PDFPageSize[options.pageSize];
} else {
printingSetting.mediaSize = PDFPageSize['A4'];
}
return this._printToPDF(printingSetting, callback);
};
};
binding._setWrapWebContents(wrapWebContents);
module.exports.create = function(options) {
if (options == null) {
options = {};
}
return binding.create(options);
};