diff --git a/index.html b/index.html index 78e789e05..1f86ca8ac 100644 --- a/index.html +++ b/index.html @@ -259,9 +259,9 @@
Select which method want to use to restore - + - +
@@ -342,7 +342,7 @@ - +
Go back @@ -777,7 +777,7 @@ on supported browsers please check http://www.w - + diff --git a/js/controllers/backup.js b/js/controllers/backup.js index f23a44f5d..92cc40f9b 100644 --- a/js/controllers/backup.js +++ b/js/controllers/backup.js @@ -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) { diff --git a/js/controllers/import.js b/js/controllers/import.js index f0959ac20..80292075a 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -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); } diff --git a/js/shell.js b/js/shell.js index d92a3139c..2e888719f 100644 --- a/js/shell.js +++ b/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; }; })();