Merge pull request #5440 from bitjson/bug/desktop-scanner

Improve scanner handling on all platforms
This commit is contained in:
Gustavo Maximiliano Cortez 2017-01-24 14:38:30 -03:00 committed by GitHub
commit cfb22c2acd
2 changed files with 15 additions and 12 deletions

View file

@ -57,8 +57,10 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
$scope.$on("$ionicView.afterEnter", function() { $scope.$on("$ionicView.afterEnter", function() {
// try initializing and refreshing status any time the view is entered // try initializing and refreshing status any time the view is entered
scannerService.gentleInitialize(); if(!scannerService.isInitialized()){
scannerService.resumePreview(); scannerService.gentleInitialize();
}
activate();
}); });
function activate(){ function activate(){
@ -79,6 +81,8 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
handleSuccessfulScan(contents); handleSuccessfulScan(contents);
} }
}); });
// resume preview if paused
scannerService.resumePreview();
}); });
}); });
} }
@ -101,7 +105,6 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
} }
$rootScope.$on('incomingDataMenu.menuHidden', function() { $rootScope.$on('incomingDataMenu.menuHidden', function() {
scannerService.resumePreview();
activate(); activate();
}); });

View file

@ -8,8 +8,9 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
var backCamera = true; // the plugin defaults to the back camera var backCamera = true; // the plugin defaults to the back camera
// Initalize known capabilities // Initalize known capabilities
var isAvailable = isDesktop? false: true; // assume camera exists on mobile // Assume camera is available. If init fails, we'll set this to false.
var hasPermission = isDesktop? true: false; // assume desktop has permission var isAvailable = true;
var hasPermission = false;
var isDenied = false; var isDenied = false;
var isRestricted = false; var isRestricted = false;
var canEnableLight = false; var canEnableLight = false;
@ -67,7 +68,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
* The `status` of QRScanner is returned to the callback. * The `status` of QRScanner is returned to the callback.
*/ */
this.gentleInitialize = function(callback) { this.gentleInitialize = function(callback) {
if(initializeStarted){ if(initializeStarted && !isDesktop){
QRScanner.getStatus(function(status){ QRScanner.getStatus(function(status){
_completeInitialization(status, callback); _completeInitialization(status, callback);
}); });
@ -87,8 +88,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
} }
}); });
} else { } else {
$log.debug('Camera permission assumed on desktop.'); $log.debug('To avoid flashing the privacy light, we do not pre-initialize the camera on desktop.');
initialize(callback);
} }
}; };
@ -96,14 +96,13 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
$log.debug('Initializing scanner...'); $log.debug('Initializing scanner...');
QRScanner.prepare(function(err, status){ QRScanner.prepare(function(err, status){
if(err){ if(err){
isAvailable = false;
$log.error(err); $log.error(err);
// does not return `status` if there is an error // does not return `status` if there is an error
QRScanner.getStatus(function(status){ QRScanner.getStatus(function(status){
_completeInitialization(status, callback); _completeInitialization(status, callback);
}); });
} else { } else {
isAvailable = true;
_completeInitialization(status, callback); _completeInitialization(status, callback);
} }
}); });
@ -130,8 +129,8 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
var nextHide = null; var nextHide = null;
var nextDestroy = null; var nextDestroy = null;
var hideAfterSeconds = 10; var hideAfterSeconds = 5;
var destroyAfterSeconds = 5 * 60; var destroyAfterSeconds = 60;
/** /**
* (Re)activate the QRScanner, and cancel the timeouts if present. * (Re)activate the QRScanner, and cancel the timeouts if present.
@ -142,6 +141,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
this.activate = function(callback) { this.activate = function(callback) {
$log.debug('Activating scanner...'); $log.debug('Activating scanner...');
QRScanner.show(function(status){ QRScanner.show(function(status){
initializeCompleted = true;
_checkCapabilities(status); _checkCapabilities(status);
if(typeof callback === "function"){ if(typeof callback === "function"){
callback(status); callback(status);