diff --git a/src/js/controllers/deadview.js b/src/js/controllers/deadview.js new file mode 100644 index 000000000..41b7b6ce4 --- /dev/null +++ b/src/js/controllers/deadview.js @@ -0,0 +1,13 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('deadviewController', function($state, $scope, $ionicHistory, fingerprintService) { + + $scope.requestFingerprint = function() { + fingerprintService.check('unlockingApp', function(err) { + if (err) return; + $state.transitionTo('tabs.home').then(function() { + $ionicHistory.clearHistory(); + }); + }); + }; +}); diff --git a/src/js/controllers/lockapp.js b/src/js/controllers/lockapp.js index 02f68921c..f7ea02b2f 100644 --- a/src/js/controllers/lockapp.js +++ b/src/js/controllers/lockapp.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('lockappController', function($state, $scope, $log, configService, popupService, gettextCatalog, appConfigService) { +angular.module('copayApp.controllers').controller('lockappController', function($state, $scope, $timeout, $log, configService, popupService, gettextCatalog, appConfigService) { $scope.$on("$ionicView.beforeEnter", function(event) { var config = configService.getSync(); @@ -34,6 +34,9 @@ angular.module('copayApp.controllers').controller('lockappController', function( $scope.useFingerprint = { enabled: false }; + $timeout(function() { + $scope.$apply(); + }); return; } saveConfig(); @@ -45,6 +48,9 @@ angular.module('copayApp.controllers').controller('lockappController', function( $scope.usePincode = { enabled: false }; + $timeout(function() { + $scope.$apply(); + }); var opts = { lockapp: { pincode: { diff --git a/src/js/routes.js b/src/js/routes.js index 48ce91c04..9f8aecbb4 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -131,6 +131,18 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr templateUrl: 'views/pincode.html', }) + /* + * + * Dead state - locked + * + */ + + .state('deadview', { + url: '/deadview/', + controller: 'deadviewController', + templateUrl: 'views/deadview.html', + }) + /* * * URI @@ -1122,7 +1134,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); }) - .run(function($rootScope, $state, $location, $log, $timeout, startupService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, /* plugins START HERE => */ coinbaseService, glideraService, amazonService, bitpayCardService) { + .run(function($rootScope, $state, $location, $log, $timeout, startupService, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, /* plugins START HERE => */ coinbaseService, glideraService, amazonService, bitpayCardService) { uxLanguage.init(); @@ -1185,9 +1197,22 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr $ionicPlatform.on('resume', function() { configService.whenAvailable(function(config) { - if (platformInfo.isCordova && config.pincode && config.pincode.enabled) { - $state.go('pincode'); - } + var nextView; + var lockapp = config.lockapp; + if (fingerprintService.isAvailable() && lockapp.fingerprint && lockapp.fingerprint.enabled) { + fingerprintService.check('unlockingApp', function(err) { + if (err) nextView = 'deadview'; + else nextView = $ionicHistory.currentStateName(); + goTo(nextView); + }); + } else if (platformInfo.isCordova && lockapp.pincode && lockapp.pincode.enabled) { + goTo('pincode'); + } else + goTo('tabs.home'); + + function goTo(nextView) { + $state.go(nextView); + }; }); }); @@ -1232,16 +1257,23 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr historyRoot: true }); configService.whenAvailable(function(config) { + var lockapp = config.lockapp; startupService.ready(); - if (platformInfo.isCordova && config.lockapp.pincode && config.lockapp.pincode.enabled) { - $state.transitionTo('pincode').then(function() { + if (fingerprintService.isAvailable() && lockapp.fingerprint && lockapp.fingerprint.enabled) { + fingerprintService.check('unlockingApp', function(err) { + if (err) goTo('deadview'); + else goTo('tabs.home'); + }); + } else if (platformInfo.isCordova && lockapp.pincode && lockapp.pincode.enabled) { + goTo('pincode'); + } else + goTo('tabs.home'); + + function goTo(nextView) { + $state.transitionTo(nextView).then(function() { $ionicHistory.clearHistory(); }); - } else { - $state.transitionTo('tabs.home').then(function() { - $ionicHistory.clearHistory(); - }); - } + }; }); }); } diff --git a/src/js/services/fingerprintService.js b/src/js/services/fingerprintService.js index 39e937360..86488a96a 100644 --- a/src/js/services/fingerprintService.js +++ b/src/js/services/fingerprintService.js @@ -14,7 +14,7 @@ angular.module('copayApp.services').factory('fingerprintService', function($log, function(msg) { FingerprintAuth.isAvailable(function(result) { - if (result.isAvailable) + if (result.isAvailable) _isAvailable = 'ANDROID'; }, function() { @@ -71,6 +71,7 @@ angular.module('copayApp.services').factory('fingerprintService', function($log, var isNeeded = function(client) { if (!_isAvailable) return false; + if (client === 'unlockingApp') return true; var config = configService.getSync(); config.touchIdFor = config.touchIdFor || {}; @@ -84,7 +85,7 @@ angular.module('copayApp.services').factory('fingerprintService', function($log, root.check = function(client, cb) { if (isNeeded(client)) { - $log.debug('FingerPrint Service:', _isAvailable); + $log.debug('FingerPrint Service:', _isAvailable); if (_isAvailable == 'IOS') return requestTouchId(cb); else diff --git a/www/views/deadview.html b/www/views/deadview.html new file mode 100644 index 000000000..f68ddce16 --- /dev/null +++ b/www/views/deadview.html @@ -0,0 +1,14 @@ + + + {{'App Locked' | translate}} + + + +
+ APP LOCKED +
+
+ Request Fingerprint Authentication +
+
+