2014-06-02 14:00:24 -07:00
|
|
|
/*
|
2014-06-24 08:36:32 -07:00
|
|
|
** copay-shell integration
|
|
|
|
*/
|
2014-06-02 14:00:24 -07:00
|
|
|
(function() {
|
|
|
|
/*
|
2014-06-24 08:36:32 -07:00
|
|
|
** This is a monkey patch for when Copay is running from
|
|
|
|
** within Copay-Shell (atom-shell). Since the renderer (the frontend)
|
|
|
|
** receives context from Node.js, we get a `module.exports` contruct
|
|
|
|
** available to us. Because of this, some libs (specifically Moment.js)
|
|
|
|
** attempt to assume their CommonJS form and bind to this. This causes
|
|
|
|
** there to be no references in the window to these libs, so let's trick
|
|
|
|
** the renderer into thinking that we are _not_ in a CommonJS environment.
|
|
|
|
*/
|
|
|
|
if (typeof module !== 'undefined') module = {
|
2014-07-07 12:53:26 -07:00
|
|
|
exports: false
|
2014-06-24 08:36:32 -07:00
|
|
|
};
|
2014-06-02 14:00:24 -07:00
|
|
|
|
|
|
|
// are we running in copay shell?
|
2014-06-03 07:50:37 -07:00
|
|
|
if (window.process && process.type === 'renderer') {
|
|
|
|
window.cshell = initCopayShellBindings();
|
2014-06-24 08:36:32 -07:00
|
|
|
} else {
|
2014-06-03 09:55:40 -07:00
|
|
|
return;
|
|
|
|
}
|
2014-06-02 14:00:24 -07:00
|
|
|
|
|
|
|
function controller(name) {
|
|
|
|
return angular.element(
|
|
|
|
document.querySelectorAll(
|
|
|
|
'[ng-controller="' + name + '"], [data-ng-controller="' + name + '"]'
|
|
|
|
)
|
|
|
|
).scope();
|
|
|
|
};
|
|
|
|
|
2014-06-03 08:55:48 -07:00
|
|
|
function needsWalletLogin(ipc) {
|
|
|
|
ipc.send('alert', 'info', 'Please select a wallet.');
|
|
|
|
};
|
|
|
|
|
2014-06-02 14:00:24 -07:00
|
|
|
function initCopayShellBindings() {
|
|
|
|
|
2014-06-24 08:36:32 -07:00
|
|
|
var ipc = require('ipc');
|
2014-06-05 10:04:08 -07:00
|
|
|
var clipb = require('clipboard');
|
2014-06-02 14:00:24 -07:00
|
|
|
|
2014-06-10 07:39:13 -07:00
|
|
|
// atom shell forces to implement the clipboard (on osx) on our own - thanks obama.
|
2014-06-05 10:04:08 -07:00
|
|
|
|
2014-06-24 08:36:32 -07:00
|
|
|
Mousetrap.stopCallback = function() {
|
|
|
|
return false
|
|
|
|
};
|
2014-06-05 10:04:08 -07:00
|
|
|
|
|
|
|
Mousetrap.bind('command+c', function(e) {
|
|
|
|
clipb.writeText(window.getSelection().toString());
|
|
|
|
});
|
|
|
|
|
|
|
|
Mousetrap.bind('command+v', function(e) {
|
|
|
|
if (document.activeElement) {
|
|
|
|
document.activeElement.value = clipb.readText();
|
2014-06-10 07:39:13 -07:00
|
|
|
document.activeElement.dispatchEvent(new Event('change'));
|
2014-06-05 10:04:08 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// handle messages
|
2014-06-02 14:00:24 -07:00
|
|
|
ipc.on('address:create', function(data) {
|
2014-06-03 09:55:40 -07:00
|
|
|
location.href = '#/addresses';
|
2014-06-03 07:50:37 -07:00
|
|
|
var ctrl = controller('AddressesController');
|
2014-06-03 08:55:48 -07:00
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
|
|
|
ctrl.newAddr();
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('transactions:send', function(data) {
|
2014-06-03 09:55:40 -07:00
|
|
|
location.href = '#/send';
|
2014-06-03 08:55:48 -07:00
|
|
|
var ctrl = controller('SendController');
|
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('transactions:all', function(data) {
|
2014-06-03 09:55:40 -07:00
|
|
|
location.href = '#/transactions';
|
2014-06-03 07:50:37 -07:00
|
|
|
var ctrl = controller('TransactionsController');
|
2014-06-03 08:55:48 -07:00
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
|
|
|
ctrl.show();
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('transactions:pending', function(data) {
|
2014-06-03 09:55:40 -07:00
|
|
|
location.href = '#/transactions';
|
2014-06-03 07:50:37 -07:00
|
|
|
var ctrl = controller('TransactionsController');
|
2014-06-03 08:55:48 -07:00
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
|
|
|
ctrl.show(true);
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('backup:download', function(data) {
|
2014-06-03 09:55:40 -07:00
|
|
|
location.href = '#/backup';
|
2014-06-03 07:50:37 -07:00
|
|
|
var ctrl = controller('BackupController');
|
2014-06-03 08:55:48 -07:00
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
|
|
|
ctrl.download();
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('backup:email', function(data) {
|
2014-06-03 09:55:40 -07:00
|
|
|
location.href = '#/backup';
|
2014-06-03 07:50:37 -07:00
|
|
|
var ctrl = controller('BackupController');
|
2014-06-03 08:55:48 -07:00
|
|
|
if (!ctrl) return needsWalletLogin(ipc);
|
2014-06-03 13:51:44 -07:00
|
|
|
ctrl.openModal();
|
2014-06-02 14:00:24 -07:00
|
|
|
});
|
|
|
|
|
2014-06-03 13:51:44 -07:00
|
|
|
ipc.on('backup:import:data', function(data) {
|
2014-06-03 12:48:27 -07:00
|
|
|
location.href = '#/import';
|
|
|
|
var ctrl = controller('ImportController');
|
|
|
|
if (!ctrl) return;
|
|
|
|
ctrl.backupText = data;
|
|
|
|
ctrl.openPasteArea();
|
|
|
|
ctrl.$apply();
|
|
|
|
});
|
|
|
|
|
2014-06-03 13:51:44 -07:00
|
|
|
ipc.on('backup:import', function(data) {
|
|
|
|
location.href = '#/import';
|
|
|
|
});
|
|
|
|
|
2014-06-03 09:55:40 -07:00
|
|
|
// let the shell know when an error occurs
|
|
|
|
window.onerror = function(err) {
|
|
|
|
ipc.send('error', err);
|
|
|
|
};
|
|
|
|
|
2014-06-03 07:50:37 -07:00
|
|
|
return ipc;
|
2014-06-02 14:00:24 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|