Merge pull request #529 from gordonwritescode/feature/copay-shell
WIP: Copay Shell Integration 2
This commit is contained in:
commit
30c6dcae6f
4 changed files with 76 additions and 11 deletions
|
|
@ -15,10 +15,18 @@ angular.module('copayApp.controllers').controller('BackupController',
|
|||
var filename = walletName + '-' + timestamp + '.json.aes';
|
||||
var wallet = _getEncryptedWallet();
|
||||
var blob = new Blob([wallet], {type: 'text/plain;charset=utf-8'});
|
||||
// show a native save dialog if we are in the shell
|
||||
// and pass the wallet to the shell to convert to node Buffer
|
||||
if (window.cshell) {
|
||||
return window.cshell.send('backup:download', {
|
||||
name: walletName,
|
||||
wallet: wallet
|
||||
});
|
||||
}
|
||||
// otherwise lean on the browser implementation
|
||||
saveAs(blob, filename);
|
||||
};
|
||||
|
||||
|
||||
$scope.openModal = function () {
|
||||
var modalInstance = $modal.open({
|
||||
templateUrl: 'backupModal.html',
|
||||
|
|
@ -35,6 +43,10 @@ angular.module('copayApp.controllers').controller('BackupController',
|
|||
+ 'subject=[Copay Backup] ' + subject + '&'
|
||||
+ 'body=' + body;
|
||||
|
||||
if (window.cshell) {
|
||||
return window.cshell.send('backup:email', href);
|
||||
}
|
||||
|
||||
var newWin = $window.open(href, '_blank', 'scrollbars=yes,resizable=yes,width=10,height=10');
|
||||
|
||||
if (newWin) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,17 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
});
|
||||
};
|
||||
|
||||
$scope.openFileDialog = function() {
|
||||
if (window.cshell) {
|
||||
return cshell.send('backup:import');
|
||||
}
|
||||
$scope.choosefile = !$scope.choosefile;
|
||||
};
|
||||
|
||||
$scope.openPasteArea = function() {
|
||||
$scope.pastetext = !$scope.pastetext;
|
||||
};
|
||||
|
||||
$scope.getFile = function() {
|
||||
// If we use onloadend, we need to check the readyState.
|
||||
reader.onloadend = function(evt) {
|
||||
|
|
@ -53,7 +64,7 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
}
|
||||
|
||||
$scope.loading = true;
|
||||
|
||||
|
||||
if (backupFile) {
|
||||
reader.readAsBinaryString(backupFile);
|
||||
}
|
||||
|
|
|
|||
54
js/shell.js
54
js/shell.js
|
|
@ -14,7 +14,12 @@
|
|||
if (typeof module !== 'undefined') module = { exports: null };
|
||||
|
||||
// are we running in copay shell?
|
||||
if (process && process.type === 'renderer') initCopayShellBindings();
|
||||
if (window.process && process.type === 'renderer') {
|
||||
window.cshell = initCopayShellBindings();
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
function controller(name) {
|
||||
return angular.element(
|
||||
|
|
@ -24,37 +29,74 @@
|
|||
).scope();
|
||||
};
|
||||
|
||||
function needsWalletLogin(ipc) {
|
||||
ipc.send('alert', 'info', 'Please select a wallet.');
|
||||
};
|
||||
|
||||
function initCopayShellBindings() {
|
||||
|
||||
var ipc = require('ipc');
|
||||
|
||||
ipc.on('address:create', function(data) {
|
||||
location.href = '#/addresses';
|
||||
controller('AddressesController').newAddr();
|
||||
var ctrl = controller('AddressesController');
|
||||
if (!ctrl) return needsWalletLogin(ipc);
|
||||
ctrl.newAddr();
|
||||
});
|
||||
|
||||
ipc.on('transactions:send', function(data) {
|
||||
location.href = '#/send';
|
||||
var ctrl = controller('SendController');
|
||||
if (!ctrl) return needsWalletLogin(ipc);
|
||||
});
|
||||
|
||||
ipc.on('transactions:all', function(data) {
|
||||
location.href = '#/transactions';
|
||||
controller('TransactionsController').show();
|
||||
var ctrl = controller('TransactionsController');
|
||||
if (!ctrl) return needsWalletLogin(ipc);
|
||||
ctrl.show();
|
||||
});
|
||||
|
||||
ipc.on('transactions:pending', function(data) {
|
||||
location.href = '#/transactions';
|
||||
controller('TransactionsController').show(true);
|
||||
var ctrl = controller('TransactionsController');
|
||||
if (!ctrl) return needsWalletLogin(ipc);
|
||||
ctrl.show(true);
|
||||
});
|
||||
|
||||
ipc.on('backup:download', function(data) {
|
||||
|
||||
location.href = '#/backup';
|
||||
var ctrl = controller('BackupController');
|
||||
if (!ctrl) return needsWalletLogin(ipc);
|
||||
ctrl.download();
|
||||
});
|
||||
|
||||
ipc.on('backup:email', function(data) {
|
||||
|
||||
location.href = '#/backup';
|
||||
var ctrl = controller('BackupController');
|
||||
if (!ctrl) return needsWalletLogin(ipc);
|
||||
ctrl.openModal();
|
||||
});
|
||||
|
||||
ipc.on('backup:import:data', function(data) {
|
||||
location.href = '#/import';
|
||||
var ctrl = controller('ImportController');
|
||||
if (!ctrl) return;
|
||||
ctrl.backupText = data;
|
||||
ctrl.openPasteArea();
|
||||
ctrl.$apply();
|
||||
});
|
||||
|
||||
ipc.on('backup:import', function(data) {
|
||||
location.href = '#/import';
|
||||
});
|
||||
|
||||
// let the shell know when an error occurs
|
||||
window.onerror = function(err) {
|
||||
ipc.send('error', err);
|
||||
};
|
||||
|
||||
return ipc;
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue