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,20 +9,43 @@ 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;
} }
}); });

View file

@ -112,6 +112,7 @@ 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;
@ -222,6 +223,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
} else { } else {
QRScanner.enableLight(_handleResponse); QRScanner.enableLight(_handleResponse);
} }
function _handleResponse(err, status) { function _handleResponse(err, status) {
if (err) { if (err) {
$log.error(err); $log.error(err);
@ -242,6 +244,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
*/ */
this.toggleCamera = function(callback) { this.toggleCamera = function(callback) {
var nextCamera = backCamera ? 1 : 0; var nextCamera = backCamera ? 1 : 0;
function cameraToString(index) { function cameraToString(index) {
return index === 1 ? 'front' : 'back'; // front = 1, back = 0 return index === 1 ? 'front' : 'back'; // front = 1, back = 0
} }
@ -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>