add old scanner for windows platform

This commit is contained in:
Gabriel Bazán 2017-06-07 12:23:07 -03:00
commit 8627e60103
7 changed files with 121 additions and 62 deletions

View file

@ -60,6 +60,7 @@
<plugin name="cordova-plugin-whitelist" spec="~1.3.0" /> <plugin name="cordova-plugin-whitelist" spec="~1.3.0" />
<plugin name="cordova-plugin-wkwebview-engine" spec="https://github.com/driftyco/cordova-plugin-wkwebview-engine.git#4221015eb3f309fe593a7d81205b691e27088743" /> <plugin name="cordova-plugin-wkwebview-engine" spec="https://github.com/driftyco/cordova-plugin-wkwebview-engine.git#4221015eb3f309fe593a7d81205b691e27088743" />
<plugin name="cordova-plugin-qrscanner" spec="~2.5.0" /> <plugin name="cordova-plugin-qrscanner" spec="~2.5.0" />
<plugin name="phonegap-plugin-barcodescanner" spec="https://github.com/phonegap/phonegap-plugin-barcodescanner.git" />
<plugin name="cordova-plugin-customurlscheme" spec="https://github.com/cmgustavo/Custom-URL-scheme.git"> <plugin name="cordova-plugin-customurlscheme" spec="https://github.com/cmgustavo/Custom-URL-scheme.git">
<variable name="URL_SCHEME" value="bitcoin" /> <variable name="URL_SCHEME" value="bitcoin" />
<variable name="SECOND_URL_SCHEME" value="*APPURI*" /> <variable name="SECOND_URL_SCHEME" value="*APPURI*" />

View file

@ -50,6 +50,7 @@ angular.module('copayApp.controllers').controller('joinController',
$scope.onQrCodeScannedJoin = function(data) { $scope.onQrCodeScannedJoin = function(data) {
$scope.formData.secret = data; $scope.formData.secret = data;
$scope.$apply();
}; };
if ($stateParams.url) { if ($stateParams.url) {

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, incomingData, lodash, popupService, gettextCatalog) { angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService) {
$scope.onScan = function(data) { $scope.onScan = function(data) {
if (!incomingData.redir(data)) { if (!incomingData.redir(data)) {
@ -22,6 +22,25 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
}, 1); }, 1);
}; };
$scope.chooseScanner = function() {
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
if (!isWindowsPhoneApp) {
$state.go('tabs.scan');
return;
}
scannerService.useOldScanner(function(err, contents) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
incomingData.redir(contents);
});
};
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
$rootScope.hideTabs = ''; $rootScope.hideTabs = '';
}); });

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.directives') angular.module('copayApp.directives')
.directive('qrScanner', function($state, $rootScope, $log, $ionicHistory) { .directive('qrScanner', function($state, $rootScope, $log, $ionicHistory, platformInfo, scannerService) {
return { return {
restrict: 'E', restrict: 'E',
@ -9,26 +9,49 @@ angular.module('copayApp.directives')
onScan: "&" onScan: "&"
}, },
replace: true, replace: true,
template: '<a on-tap="openScanner()" nav-transition="none"><i class="icon ion-qr-scanner"></i></a>', template: '<a on-tap="chooseScanner()" nav-transition="none"><i class="icon ion-qr-scanner"></i></a>',
link: function(scope, el, attrs) { link: function(scope, el, attrs) {
scope.chooseScanner = function() {
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
if (!isWindowsPhoneApp) {
scope.openScanner();
return;
}
scannerService.useOldScanner(function(err, contents) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
scope.onScan({
data: contents
});
});
};
scope.openScanner = function() { scope.openScanner = function() {
$log.debug('Opening scanner by directive...'); $log.debug('Opening scanner by directive...');
$ionicHistory.nextViewOptions({ $ionicHistory.nextViewOptions({
disableAnimate: true disableAnimate: true
}); });
$state.go('scanner', { passthroughMode: 1 }); $state.go('scanner', {
passthroughMode: 1
});
}; };
var afterEnter = $rootScope.$on('$ionicView.afterEnter', function() { var afterEnter = $rootScope.$on('$ionicView.afterEnter', function() {
if($rootScope.scanResult) { if ($rootScope.scanResult) {
scope.onScan({ data: $rootScope.scanResult }); scope.onScan({
data: $rootScope.scanResult
});
$rootScope.scanResult = null; $rootScope.scanResult = null;
} }
}); });
// Destroy event // Destroy event
scope.$on('$destroy', function(){ scope.$on('$destroy', function() {
afterEnter(); afterEnter();
}); });
} }

View file

@ -17,27 +17,27 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
var canChangeCamera = false; var canChangeCamera = false;
var canOpenSettings = false; var canOpenSettings = false;
function _checkCapabilities(status){ function _checkCapabilities(status) {
$log.debug('scannerService is reviewing platform capabilities...'); $log.debug('scannerService is reviewing platform capabilities...');
// Permission can be assumed on the desktop builds // Permission can be assumed on the desktop builds
hasPermission = (isDesktop || status.authorized)? true: false; hasPermission = (isDesktop || status.authorized) ? true : false;
isDenied = status.denied? true : false; isDenied = status.denied ? true : false;
isRestricted = status.restricted? true : false; isRestricted = status.restricted ? true : false;
canEnableLight = status.canEnableLight? true : false; canEnableLight = status.canEnableLight ? true : false;
canChangeCamera = status.canChangeCamera? true : false; canChangeCamera = status.canChangeCamera ? true : false;
canOpenSettings = status.canOpenSettings? true : false; canOpenSettings = status.canOpenSettings ? true : false;
_logCapabilities(); _logCapabilities();
} }
function _logCapabilities(){ function _logCapabilities() {
function _orIsNot(bool){ function _orIsNot(bool) {
return bool? '' : 'not '; return bool ? '' : 'not ';
} }
$log.debug('A camera is ' + _orIsNot(isAvailable) + 'available to this app.'); $log.debug('A camera is ' + _orIsNot(isAvailable) + 'available to this app.');
var access = 'not authorized'; var access = 'not authorized';
if(hasPermission) access = 'authorized'; if (hasPermission) access = 'authorized';
if(isDenied) access = 'denied'; if (isDenied) access = 'denied';
if(isRestricted) access = 'restricted'; if (isRestricted) access = 'restricted';
$log.debug('Camera access is ' + access + '.'); $log.debug('Camera access is ' + access + '.');
$log.debug('Support for opening device settings is ' + _orIsNot(canOpenSettings) + 'available on this platform.'); $log.debug('Support for opening device settings is ' + _orIsNot(canOpenSettings) + 'available on this platform.');
$log.debug('A light is ' + _orIsNot(canEnableLight) + 'available on this platform.'); $log.debug('A light is ' + _orIsNot(canEnableLight) + 'available on this platform.');
@ -47,7 +47,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
/** /**
* Immediately return known capabilities of the current platform. * Immediately return known capabilities of the current platform.
*/ */
this.getCapabilities = function(){ this.getCapabilities = function() {
return { return {
isAvailable: isAvailable, isAvailable: isAvailable,
hasPermission: hasPermission, hasPermission: hasPermission,
@ -68,18 +68,18 @@ 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 && !isDesktop){ if (initializeStarted && !isDesktop) {
QRScanner.getStatus(function(status){ QRScanner.getStatus(function(status) {
_completeInitialization(status, callback); _completeInitialization(status, callback);
}); });
return; return;
} }
initializeStarted = true; initializeStarted = true;
$log.debug('Trying to pre-initialize QRScanner.'); $log.debug('Trying to pre-initialize QRScanner.');
if(!isDesktop){ if (!isDesktop) {
QRScanner.getStatus(function(status){ QRScanner.getStatus(function(status) {
_checkCapabilities(status); _checkCapabilities(status);
if(status.authorized){ if (status.authorized) {
$log.debug('Camera permission already granted.'); $log.debug('Camera permission already granted.');
initialize(callback); initialize(callback);
} else { } else {
@ -92,14 +92,14 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
} }
}; };
function initialize(callback){ function initialize(callback) {
$log.debug('Initializing scanner...'); $log.debug('Initializing scanner...');
QRScanner.prepare(function(err, status){ QRScanner.prepare(function(err, status) {
if(err){ if (err) {
isAvailable = false; 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 {
@ -112,18 +112,19 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
// This could be much cleaner with a Promise API // This could be much cleaner with a Promise API
// (needs a polyfill for some platforms) // (needs a polyfill for some platforms)
var initializeCompleted = false; var initializeCompleted = false;
function _completeInitialization(status, callback){
function _completeInitialization(status, callback) {
_checkCapabilities(status); _checkCapabilities(status);
initializeCompleted = true; initializeCompleted = true;
$rootScope.$emit('scannerServiceInitialized'); $rootScope.$emit('scannerServiceInitialized');
if(typeof callback === "function"){ if (typeof callback === "function") {
callback(status); callback(status);
} }
} }
this.isInitialized = function(){ this.isInitialized = function() {
return initializeCompleted; return initializeCompleted;
}; };
this.initializeStarted = function(){ this.initializeStarted = function() {
return initializeStarted; return initializeStarted;
}; };
@ -140,21 +141,21 @@ 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; initializeCompleted = true;
_checkCapabilities(status); _checkCapabilities(status);
if(typeof callback === "function"){ if (typeof callback === "function") {
callback(status); callback(status);
}
});
if(nextHide !== null){
$timeout.cancel(nextHide);
nextHide = null;
}
if(nextDestroy !== null){
$timeout.cancel(nextDestroy);
nextDestroy = null;
} }
});
if (nextHide !== null) {
$timeout.cancel(nextHide);
nextHide = null;
}
if (nextDestroy !== null) {
$timeout.cancel(nextDestroy);
nextDestroy = null;
}
}; };
/** /**
@ -193,18 +194,18 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
// Natively hide the QRScanner's preview // Natively hide the QRScanner's preview
// On mobile platforms, this can reduce GPU/power usage // On mobile platforms, this can reduce GPU/power usage
// On desktop, this fully turns off the camera (and any associated privacy lights) // On desktop, this fully turns off the camera (and any associated privacy lights)
function _hide(){ function _hide() {
$log.debug('Scanner not in use for ' + hideAfterSeconds + ' seconds, hiding...'); $log.debug('Scanner not in use for ' + hideAfterSeconds + ' seconds, hiding...');
QRScanner.hide(); QRScanner.hide();
} }
// Reduce QRScanner power/processing consumption by the maximum amount // Reduce QRScanner power/processing consumption by the maximum amount
function _destroy(){ function _destroy() {
$log.debug('Scanner not in use for ' + destroyAfterSeconds + ' seconds, destroying...'); $log.debug('Scanner not in use for ' + destroyAfterSeconds + ' seconds, destroying...');
QRScanner.destroy(); QRScanner.destroy();
} }
this.reinitialize = function(callback){ this.reinitialize = function(callback) {
initializeCompleted = false; initializeCompleted = false;
QRScanner.destroy(); QRScanner.destroy();
initialize(callback); initialize(callback);
@ -217,17 +218,18 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
*/ */
this.toggleLight = function(callback) { this.toggleLight = function(callback) {
$log.debug('Toggling light...'); $log.debug('Toggling light...');
if(lightEnabled){ if (lightEnabled) {
QRScanner.disableLight(_handleResponse); QRScanner.disableLight(_handleResponse);
} else { } else {
QRScanner.enableLight(_handleResponse); QRScanner.enableLight(_handleResponse);
} }
function _handleResponse(err, status){
if(err){ function _handleResponse(err, status) {
if (err) {
$log.error(err); $log.error(err);
} else { } else {
lightEnabled = status.lightEnabled; lightEnabled = status.lightEnabled;
var state = lightEnabled? 'enabled' : 'disabled'; var state = lightEnabled ? 'enabled' : 'disabled';
$log.debug('Light ' + state + '.'); $log.debug('Light ' + state + '.');
} }
callback(lightEnabled); callback(lightEnabled);
@ -241,16 +243,17 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
* is complete. * is complete.
*/ */
this.toggleCamera = function(callback) { this.toggleCamera = function(callback) {
var nextCamera = backCamera? 1 : 0; var nextCamera = backCamera ? 1 : 0;
function cameraToString(index){
return index === 1? 'front' : 'back'; // front = 1, back = 0 function cameraToString(index) {
return index === 1 ? 'front' : 'back'; // front = 1, back = 0
} }
$log.debug('Toggling to the ' + cameraToString(nextCamera) + ' camera...'); $log.debug('Toggling to the ' + cameraToString(nextCamera) + ' camera...');
QRScanner.useCamera(nextCamera, function(err, status){ QRScanner.useCamera(nextCamera, function(err, status) {
if(err){ if (err) {
$log.error(err); $log.error(err);
} }
backCamera = status.currentCamera === 1? false : true; backCamera = status.currentCamera === 1 ? false : true;
$log.debug('Camera toggled. Now using the ' + cameraToString(backCamera) + ' camera.'); $log.debug('Camera toggled. Now using the ' + cameraToString(backCamera) + ' camera.');
callback(status); callback(status);
}); });
@ -260,4 +263,15 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
$log.debug('Attempting to open device settings...'); $log.debug('Attempting to open device settings...');
QRScanner.openSettings(); QRScanner.openSettings();
}; };
this.useOldScanner = function(callback) {
cordova.plugins.barcodeScanner.scan(
function(result) {
callback(null, result.text);
},
function(error) {
callback(error);
}
);
}
}); });

View file

@ -10,6 +10,7 @@
spinner="ios-small" spinner="ios-small"
on-refresh="onRefresh()"> on-refresh="onRefresh()">
</ion-refresher> </ion-refresher>
<div class="list card release ng-hide" ng-show="newRelease"> <div class="list card release ng-hide" ng-show="newRelease">
<i class="item icon big-icon-svg"> <i class="item icon big-icon-svg">
<img src="img/icon-update.svg" class="bg"/> <img src="img/icon-update.svg" class="bg"/>

View file

@ -8,7 +8,7 @@
<ion-nav-view name="tab-receive"></ion-nav-view> <ion-nav-view name="tab-receive"></ion-nav-view>
</ion-tab> </ion-tab>
<ion-tab title="{{'Scan'|translate}}" icon-off="ico-scan" icon-on="ico-scan-selected" ui-sref="tabs.scan"> <ion-tab title="{{'Scan'|translate}}" icon-off="ico-scan" icon-on="ico-scan-selected" ng-click="chooseScanner()">
<ion-nav-view name="tab-scan"></ion-nav-view> <ion-nav-view name="tab-scan"></ion-nav-view>
</ion-tab> </ion-tab>