From 20c7d7fe62b1bfd15975f6b0ce58da598f5f8195 Mon Sep 17 00:00:00 2001 From: Gordon Hall Date: Tue, 3 Jun 2014 10:35:24 -0400 Subject: [PATCH 1/6] fixed ref error in shell.js --- index.html | 2 +- js/shell.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index e4df15843..132da9e46 100644 --- a/index.html +++ b/index.html @@ -736,7 +736,7 @@ on supported browsers please check http://www.w - + diff --git a/js/shell.js b/js/shell.js index d92a3139c..de3ce38fc 100644 --- a/js/shell.js +++ b/js/shell.js @@ -14,7 +14,7 @@ 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') initCopayShellBindings(); function controller(name) { return angular.element( From 6143dd4066a08473484704cf9fb0e90dd948024f Mon Sep 17 00:00:00 2001 From: Gordon Hall Date: Tue, 3 Jun 2014 10:50:37 -0400 Subject: [PATCH 2/6] add better handling of native menu actions, add handlers for backup --- js/shell.js | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/js/shell.js b/js/shell.js index de3ce38fc..c57678671 100644 --- a/js/shell.js +++ b/js/shell.js @@ -14,7 +14,9 @@ if (typeof module !== 'undefined') module = { exports: null }; // are we running in copay shell? - if (window.process && process.type === 'renderer') initCopayShellBindings(); + if (window.process && process.type === 'renderer') { + window.cshell = initCopayShellBindings(); + } function controller(name) { return angular.element( @@ -29,8 +31,11 @@ var ipc = require('ipc'); ipc.on('address:create', function(data) { - location.href = '#/addresses'; - controller('AddressesController').newAddr(); + var ctrl = controller('AddressesController'); + if (ctrl) { + location.href = '#/addresses'; + ctrl.newAddr(); + } }); ipc.on('transactions:send', function(data) { @@ -38,23 +43,39 @@ }); ipc.on('transactions:all', function(data) { - location.href = '#/transactions'; - controller('TransactionsController').show(); + var ctrl = controller('TransactionsController'); + if (ctrl) { + location.href = '#/transactions'; + ctrl.show(); + } }); ipc.on('transactions:pending', function(data) { - location.href = '#/transactions'; - controller('TransactionsController').show(true); + var ctrl = controller('TransactionsController'); + if (ctrl) { + location.href = '#/transactions'; + ctrl.show(true); + } }); ipc.on('backup:download', function(data) { - + var ctrl = controller('BackupController'); + if (ctrl) { + location.href = '#/backup'; + ctrl.download(); + } }); ipc.on('backup:email', function(data) { - + var ctrl = controller('BackupController'); + if (ctrl) { + location.href = '#/backup'; + ctrl.email(); + } }); + return ipc; + }; })(); From 2818ff6d60f3e2cebe6b2b510d1010387bfc12f7 Mon Sep 17 00:00:00 2001 From: Gordon Hall Date: Tue, 3 Jun 2014 11:55:48 -0400 Subject: [PATCH 3/6] now sending alert message to shell when menu action can't be handled --- js/shell.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/js/shell.js b/js/shell.js index c57678671..4067eadf7 100644 --- a/js/shell.js +++ b/js/shell.js @@ -26,52 +26,53 @@ ).scope(); }; + function needsWalletLogin(ipc) { + ipc.send('alert', 'info', 'Please select a wallet.'); + }; + function initCopayShellBindings() { var ipc = require('ipc'); ipc.on('address:create', function(data) { var ctrl = controller('AddressesController'); - if (ctrl) { - location.href = '#/addresses'; - ctrl.newAddr(); - } + if (!ctrl) return needsWalletLogin(ipc); + location.href = '#/addresses'; + ctrl.newAddr(); }); ipc.on('transactions:send', function(data) { + var ctrl = controller('SendController'); + if (!ctrl) return needsWalletLogin(ipc); location.href = '#/send'; }); ipc.on('transactions:all', function(data) { var ctrl = controller('TransactionsController'); - if (ctrl) { - location.href = '#/transactions'; - ctrl.show(); - } + if (!ctrl) return needsWalletLogin(ipc); + location.href = '#/transactions'; + ctrl.show(); }); ipc.on('transactions:pending', function(data) { var ctrl = controller('TransactionsController'); - if (ctrl) { - location.href = '#/transactions'; - ctrl.show(true); - } + if (!ctrl) return needsWalletLogin(ipc); + location.href = '#/transactions'; + ctrl.show(true); }); ipc.on('backup:download', function(data) { var ctrl = controller('BackupController'); - if (ctrl) { - location.href = '#/backup'; - ctrl.download(); - } + if (!ctrl) return needsWalletLogin(ipc); + location.href = '#/backup'; + ctrl.download(); }); ipc.on('backup:email', function(data) { var ctrl = controller('BackupController'); - if (ctrl) { - location.href = '#/backup'; - ctrl.email(); - } + if (!ctrl) return needsWalletLogin(ipc); + location.href = '#/backup'; + ctrl.email(); }); return ipc; From ceafc3bb4f79eea0cb8e9afdba4bc9b7486c5f39 Mon Sep 17 00:00:00 2001 From: Gordon Hall Date: Tue, 3 Jun 2014 12:55:40 -0400 Subject: [PATCH 4/6] added message for backup to file for when instide copay shell --- js/controllers/backup.js | 13 +++++++++++-- js/shell.js | 20 ++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/js/controllers/backup.js b/js/controllers/backup.js index df0bd5219..60c83187e 100644 --- a/js/controllers/backup.js +++ b/js/controllers/backup.js @@ -15,6 +15,15 @@ angular.module('copay.backup').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); }; @@ -27,7 +36,7 @@ angular.module('copay.backup').controller('BackupController', alert('Enter a valid email address'); } else { var body = _getEncryptedWallet(); - var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id; + var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id; var href = 'mailto:' + email + '?' + 'subject=[Copay Backup] ' + subject + '&' + 'body=' + body; @@ -42,5 +51,5 @@ angular.module('copay.backup').controller('BackupController', } } }; - + }); diff --git a/js/shell.js b/js/shell.js index 4067eadf7..fe5722015 100644 --- a/js/shell.js +++ b/js/shell.js @@ -17,6 +17,9 @@ if (window.process && process.type === 'renderer') { window.cshell = initCopayShellBindings(); } + else { + return; + } function controller(name) { return angular.element( @@ -35,46 +38,51 @@ var ipc = require('ipc'); ipc.on('address:create', function(data) { + location.href = '#/addresses'; var ctrl = controller('AddressesController'); if (!ctrl) return needsWalletLogin(ipc); - location.href = '#/addresses'; ctrl.newAddr(); }); ipc.on('transactions:send', function(data) { + location.href = '#/send'; var ctrl = controller('SendController'); if (!ctrl) return needsWalletLogin(ipc); - location.href = '#/send'; }); ipc.on('transactions:all', function(data) { + location.href = '#/transactions'; var ctrl = controller('TransactionsController'); if (!ctrl) return needsWalletLogin(ipc); - location.href = '#/transactions'; ctrl.show(); }); ipc.on('transactions:pending', function(data) { + location.href = '#/transactions'; var ctrl = controller('TransactionsController'); if (!ctrl) return needsWalletLogin(ipc); - location.href = '#/transactions'; ctrl.show(true); }); ipc.on('backup:download', function(data) { + location.href = '#/backup'; var ctrl = controller('BackupController'); if (!ctrl) return needsWalletLogin(ipc); - location.href = '#/backup'; ctrl.download(); }); ipc.on('backup:email', function(data) { + location.href = '#/backup'; var ctrl = controller('BackupController'); if (!ctrl) return needsWalletLogin(ipc); - location.href = '#/backup'; ctrl.email(); }); + // let the shell know when an error occurs + window.onerror = function(err) { + ipc.send('error', err); + }; + return ipc; }; From 11c1157f9e4aaf2772e56c86a444d82a70d393c9 Mon Sep 17 00:00:00 2001 From: Gordon Hall Date: Tue, 3 Jun 2014 15:48:27 -0400 Subject: [PATCH 5/6] added handling of importing a backup --- index.html | 6 +++--- js/controllers/import.js | 13 ++++++++++++- js/shell.js | 9 +++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index ebedb216f..4b18d7bf3 100644 --- a/index.html +++ b/index.html @@ -249,9 +249,9 @@
Select which method want to use to restore - + - +
@@ -332,7 +332,7 @@ - +
Go back diff --git a/js/controllers/import.js b/js/controllers/import.js index c2328e0ae..c1e594114 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -19,6 +19,17 @@ angular.module('copay.import').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) { @@ -48,7 +59,7 @@ angular.module('copay.import').controller('ImportController', } $scope.loading = true; - + if (backupFile) { reader.readAsBinaryString(backupFile); } diff --git a/js/shell.js b/js/shell.js index fe5722015..4fde3b0fd 100644 --- a/js/shell.js +++ b/js/shell.js @@ -78,6 +78,15 @@ ctrl.email(); }); + ipc.on('backup:import', function(data) { + location.href = '#/import'; + var ctrl = controller('ImportController'); + if (!ctrl) return; + ctrl.backupText = data; + ctrl.openPasteArea(); + ctrl.$apply(); + }); + // let the shell know when an error occurs window.onerror = function(err) { ipc.send('error', err); From 00dd3daf11108513b7e593f665cccbc5367b185a Mon Sep 17 00:00:00 2001 From: Gordon Hall Date: Tue, 3 Jun 2014 17:49:59 -0400 Subject: [PATCH 6/6] remove whitespace --- js/shell.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/shell.js b/js/shell.js index eacbe9a37..2e888719f 100644 --- a/js/shell.js +++ b/js/shell.js @@ -97,7 +97,6 @@ }; return ipc; - }; })();