mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #529 from gordonwritescode/feature/copay-shell
WIP: Copay Shell Integration 2
This commit is contained in:
commit
30c6dcae6f
|
@ -259,9 +259,9 @@
|
|||
<div class="large-6 large-centered medium-6 medium-centered columns">
|
||||
<fieldset>
|
||||
<legend>Select which method want to use to restore</legend>
|
||||
<label for="backupFile" ng-click="choosefile=!choosefile" class="m10b">· Choose backup file from your computer <i class="fi-laptop"></i></label>
|
||||
<label for="backupFile" ng-click="openFileDialog()" class="m10b">· Choose backup file from your computer <i class="fi-laptop"></i></label>
|
||||
<input type="file" class="form-control" placeholder="Select a backup file" name="backupFile" ng-model="backupFile" ng-file-select ng-show="choosefile">
|
||||
<label for="backupText" ng-click="pastetext=!pastetext" class="m10b">· Paste backup plain text code <i class="fi-clipboard"></i></label>
|
||||
<label for="backupText" ng-click="openPasteArea()" class="m10b">· Paste backup plain text code <i class="fi-clipboard"></i></label>
|
||||
<textarea class="form-control" name="backupText" ng-model="backupText" rows="5" ng-show="pastetext"></textarea>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
@ -777,7 +777,7 @@ on supported browsers please check <a href="http://www.webrtc.org/">http://www.w
|
|||
|
||||
|
||||
<script src="config.js"></script>
|
||||
<!-- <script src="js/shell.js"></script> -->
|
||||
<script src="js/shell.js"></script>
|
||||
<script src="lib/angular/angular.min.js"></script>
|
||||
<script src="lib/moment/moment.js"></script>
|
||||
<script src="lib/angular-moment/angular-moment.js"></script>
|
||||
|
|
|
@ -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) {
|
||||
|
|
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…
Reference in New Issue