Merge pull request #3758 from cmgustavo/feat/speedup-qr-code-scanner

Speed up QR code scanner for iOS
This commit is contained in:
Matias Alejo Garcia 2016-01-12 11:45:21 -03:00
commit 72b7ca7fb9
5 changed files with 43 additions and 31 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService) {
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService) {
var self = this;
window.ignoreMobilePause = false;
@ -25,7 +25,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.blockUx = false;
this.isRateAvailable = false;
this.showScanner = false;
this.isMobile = isMobile.any();
this.addr = {};
this.lockedCurrentFeePerKb = null;

View file

@ -1,36 +1,40 @@
'use strict';
angular.module('copayApp.directives')
.directive('qrScanner', ['$rootScope', '$timeout', '$modal', 'isCordova', 'gettextCatalog',
function($rootScope, $timeout, $modal, isCordova, gettextCatalog) {
.directive('qrScanner', ['$rootScope', '$timeout', '$modal', 'isCordova', 'gettextCatalog', 'isMobile',
function($rootScope, $timeout, $modal, isCordova, gettextCatalog, isMobile) {
var controller = function($scope) {
var onSuccess = function(result) {
$timeout(function() {
window.plugins.spinnerDialog.hide();
window.ignoreMobilePause = false;
}, 100);
if (isMobile.Windows() && result.cancelled) return;
$timeout(function() {
var data = isMobile.Windows() ? result.text : result;
$scope.onScan({ data: data });
}, 1000);
};
var onError = function(error) {
$timeout(function() {
window.ignoreMobilePause = false;
window.plugins.spinnerDialog.hide();
}, 100);
};
$scope.cordovaOpenScanner = function() {
window.ignoreMobilePause = true;
window.plugins.spinnerDialog.show(null, gettextCatalog.getString('Preparing camera...'), true);
$timeout(function() {
cordova.plugins.barcodeScanner.scan(
function onSuccess(result) {
$timeout(function() {
window.plugins.spinnerDialog.hide();
window.ignoreMobilePause = false;
}, 100);
if (result.cancelled) return;
$timeout(function() {
var data = result.text;
$scope.onScan({ data: data });
}, 1000);
},
function onError(error) {
$timeout(function() {
window.ignoreMobilePause = false;
window.plugins.spinnerDialog.hide();
}, 100);
alert('Scanning error');
}
);
if (!isMobile.Windows()) {
cloudSky.zBar.scan({}, onSuccess, onError);
} else {
cordova.plugins.barcodeScanner.scan(onSuccess, onError);
}
if ($scope.beforeScan) {
$scope.beforeScan();
}