add old scanner for windows platform
This commit is contained in:
parent
f6245652d9
commit
8627e60103
7 changed files with 121 additions and 62 deletions
|
|
@ -60,6 +60,7 @@
|
|||
<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-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">
|
||||
<variable name="URL_SCHEME" value="bitcoin" />
|
||||
<variable name="SECOND_URL_SCHEME" value="*APPURI*" />
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ angular.module('copayApp.controllers').controller('joinController',
|
|||
|
||||
$scope.onQrCodeScannedJoin = function(data) {
|
||||
$scope.formData.secret = data;
|
||||
$scope.$apply();
|
||||
};
|
||||
|
||||
if ($stateParams.url) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'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) {
|
||||
if (!incomingData.redir(data)) {
|
||||
|
|
@ -22,6 +22,25 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
|
|||
}, 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) {
|
||||
$rootScope.hideTabs = '';
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.directives')
|
||||
.directive('qrScanner', function($state, $rootScope, $log, $ionicHistory) {
|
||||
.directive('qrScanner', function($state, $rootScope, $log, $ionicHistory, platformInfo, scannerService) {
|
||||
|
||||
return {
|
||||
restrict: 'E',
|
||||
|
|
@ -9,26 +9,49 @@ angular.module('copayApp.directives')
|
|||
onScan: "&"
|
||||
},
|
||||
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) {
|
||||
|
||||
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() {
|
||||
$log.debug('Opening scanner by directive...');
|
||||
$ionicHistory.nextViewOptions({
|
||||
disableAnimate: true
|
||||
});
|
||||
$state.go('scanner', { passthroughMode: 1 });
|
||||
$state.go('scanner', {
|
||||
passthroughMode: 1
|
||||
});
|
||||
};
|
||||
|
||||
var afterEnter = $rootScope.$on('$ionicView.afterEnter', function() {
|
||||
if($rootScope.scanResult) {
|
||||
scope.onScan({ data: $rootScope.scanResult });
|
||||
if ($rootScope.scanResult) {
|
||||
scope.onScan({
|
||||
data: $rootScope.scanResult
|
||||
});
|
||||
$rootScope.scanResult = null;
|
||||
}
|
||||
});
|
||||
|
||||
// Destroy event
|
||||
scope.$on('$destroy', function(){
|
||||
scope.$on('$destroy', function() {
|
||||
afterEnter();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,27 +17,27 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
var canChangeCamera = false;
|
||||
var canOpenSettings = false;
|
||||
|
||||
function _checkCapabilities(status){
|
||||
function _checkCapabilities(status) {
|
||||
$log.debug('scannerService is reviewing platform capabilities...');
|
||||
// Permission can be assumed on the desktop builds
|
||||
hasPermission = (isDesktop || status.authorized)? true: false;
|
||||
isDenied = status.denied? true : false;
|
||||
isRestricted = status.restricted? true : false;
|
||||
canEnableLight = status.canEnableLight? true : false;
|
||||
canChangeCamera = status.canChangeCamera? true : false;
|
||||
canOpenSettings = status.canOpenSettings? true : false;
|
||||
hasPermission = (isDesktop || status.authorized) ? true : false;
|
||||
isDenied = status.denied ? true : false;
|
||||
isRestricted = status.restricted ? true : false;
|
||||
canEnableLight = status.canEnableLight ? true : false;
|
||||
canChangeCamera = status.canChangeCamera ? true : false;
|
||||
canOpenSettings = status.canOpenSettings ? true : false;
|
||||
_logCapabilities();
|
||||
}
|
||||
|
||||
function _logCapabilities(){
|
||||
function _orIsNot(bool){
|
||||
return bool? '' : 'not ';
|
||||
function _logCapabilities() {
|
||||
function _orIsNot(bool) {
|
||||
return bool ? '' : 'not ';
|
||||
}
|
||||
$log.debug('A camera is ' + _orIsNot(isAvailable) + 'available to this app.');
|
||||
var access = 'not authorized';
|
||||
if(hasPermission) access = 'authorized';
|
||||
if(isDenied) access = 'denied';
|
||||
if(isRestricted) access = 'restricted';
|
||||
if (hasPermission) access = 'authorized';
|
||||
if (isDenied) access = 'denied';
|
||||
if (isRestricted) access = 'restricted';
|
||||
$log.debug('Camera access is ' + access + '.');
|
||||
$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.');
|
||||
|
|
@ -47,7 +47,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
/**
|
||||
* Immediately return known capabilities of the current platform.
|
||||
*/
|
||||
this.getCapabilities = function(){
|
||||
this.getCapabilities = function() {
|
||||
return {
|
||||
isAvailable: isAvailable,
|
||||
hasPermission: hasPermission,
|
||||
|
|
@ -68,18 +68,18 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
* The `status` of QRScanner is returned to the callback.
|
||||
*/
|
||||
this.gentleInitialize = function(callback) {
|
||||
if(initializeStarted && !isDesktop){
|
||||
QRScanner.getStatus(function(status){
|
||||
if (initializeStarted && !isDesktop) {
|
||||
QRScanner.getStatus(function(status) {
|
||||
_completeInitialization(status, callback);
|
||||
});
|
||||
return;
|
||||
}
|
||||
initializeStarted = true;
|
||||
$log.debug('Trying to pre-initialize QRScanner.');
|
||||
if(!isDesktop){
|
||||
QRScanner.getStatus(function(status){
|
||||
if (!isDesktop) {
|
||||
QRScanner.getStatus(function(status) {
|
||||
_checkCapabilities(status);
|
||||
if(status.authorized){
|
||||
if (status.authorized) {
|
||||
$log.debug('Camera permission already granted.');
|
||||
initialize(callback);
|
||||
} else {
|
||||
|
|
@ -92,14 +92,14 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
}
|
||||
};
|
||||
|
||||
function initialize(callback){
|
||||
function initialize(callback) {
|
||||
$log.debug('Initializing scanner...');
|
||||
QRScanner.prepare(function(err, status){
|
||||
if(err){
|
||||
QRScanner.prepare(function(err, status) {
|
||||
if (err) {
|
||||
isAvailable = false;
|
||||
$log.error(err);
|
||||
// does not return `status` if there is an error
|
||||
QRScanner.getStatus(function(status){
|
||||
QRScanner.getStatus(function(status) {
|
||||
_completeInitialization(status, callback);
|
||||
});
|
||||
} else {
|
||||
|
|
@ -112,18 +112,19 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
// This could be much cleaner with a Promise API
|
||||
// (needs a polyfill for some platforms)
|
||||
var initializeCompleted = false;
|
||||
function _completeInitialization(status, callback){
|
||||
|
||||
function _completeInitialization(status, callback) {
|
||||
_checkCapabilities(status);
|
||||
initializeCompleted = true;
|
||||
$rootScope.$emit('scannerServiceInitialized');
|
||||
if(typeof callback === "function"){
|
||||
if (typeof callback === "function") {
|
||||
callback(status);
|
||||
}
|
||||
}
|
||||
this.isInitialized = function(){
|
||||
this.isInitialized = function() {
|
||||
return initializeCompleted;
|
||||
};
|
||||
this.initializeStarted = function(){
|
||||
this.initializeStarted = function() {
|
||||
return initializeStarted;
|
||||
};
|
||||
|
||||
|
|
@ -140,21 +141,21 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
*/
|
||||
this.activate = function(callback) {
|
||||
$log.debug('Activating scanner...');
|
||||
QRScanner.show(function(status){
|
||||
initializeCompleted = true;
|
||||
_checkCapabilities(status);
|
||||
if(typeof callback === "function"){
|
||||
callback(status);
|
||||
}
|
||||
});
|
||||
if(nextHide !== null){
|
||||
$timeout.cancel(nextHide);
|
||||
nextHide = null;
|
||||
}
|
||||
if(nextDestroy !== null){
|
||||
$timeout.cancel(nextDestroy);
|
||||
nextDestroy = null;
|
||||
QRScanner.show(function(status) {
|
||||
initializeCompleted = true;
|
||||
_checkCapabilities(status);
|
||||
if (typeof callback === "function") {
|
||||
callback(status);
|
||||
}
|
||||
});
|
||||
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
|
||||
// On mobile platforms, this can reduce GPU/power usage
|
||||
// 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...');
|
||||
QRScanner.hide();
|
||||
}
|
||||
|
||||
// Reduce QRScanner power/processing consumption by the maximum amount
|
||||
function _destroy(){
|
||||
function _destroy() {
|
||||
$log.debug('Scanner not in use for ' + destroyAfterSeconds + ' seconds, destroying...');
|
||||
QRScanner.destroy();
|
||||
}
|
||||
|
||||
this.reinitialize = function(callback){
|
||||
this.reinitialize = function(callback) {
|
||||
initializeCompleted = false;
|
||||
QRScanner.destroy();
|
||||
initialize(callback);
|
||||
|
|
@ -217,17 +218,18 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
*/
|
||||
this.toggleLight = function(callback) {
|
||||
$log.debug('Toggling light...');
|
||||
if(lightEnabled){
|
||||
if (lightEnabled) {
|
||||
QRScanner.disableLight(_handleResponse);
|
||||
} else {
|
||||
QRScanner.enableLight(_handleResponse);
|
||||
}
|
||||
function _handleResponse(err, status){
|
||||
if(err){
|
||||
|
||||
function _handleResponse(err, status) {
|
||||
if (err) {
|
||||
$log.error(err);
|
||||
} else {
|
||||
lightEnabled = status.lightEnabled;
|
||||
var state = lightEnabled? 'enabled' : 'disabled';
|
||||
var state = lightEnabled ? 'enabled' : 'disabled';
|
||||
$log.debug('Light ' + state + '.');
|
||||
}
|
||||
callback(lightEnabled);
|
||||
|
|
@ -241,16 +243,17 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
* is complete.
|
||||
*/
|
||||
this.toggleCamera = function(callback) {
|
||||
var nextCamera = backCamera? 1 : 0;
|
||||
function cameraToString(index){
|
||||
return index === 1? 'front' : 'back'; // front = 1, back = 0
|
||||
var nextCamera = backCamera ? 1 : 0;
|
||||
|
||||
function cameraToString(index) {
|
||||
return index === 1 ? 'front' : 'back'; // front = 1, back = 0
|
||||
}
|
||||
$log.debug('Toggling to the ' + cameraToString(nextCamera) + ' camera...');
|
||||
QRScanner.useCamera(nextCamera, function(err, status){
|
||||
if(err){
|
||||
QRScanner.useCamera(nextCamera, function(err, status) {
|
||||
if (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.');
|
||||
callback(status);
|
||||
});
|
||||
|
|
@ -260,4 +263,15 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
$log.debug('Attempting to open device settings...');
|
||||
QRScanner.openSettings();
|
||||
};
|
||||
|
||||
this.useOldScanner = function(callback) {
|
||||
cordova.plugins.barcodeScanner.scan(
|
||||
function(result) {
|
||||
callback(null, result.text);
|
||||
},
|
||||
function(error) {
|
||||
callback(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
spinner="ios-small"
|
||||
on-refresh="onRefresh()">
|
||||
</ion-refresher>
|
||||
|
||||
<div class="list card release ng-hide" ng-show="newRelease">
|
||||
<i class="item icon big-icon-svg">
|
||||
<img src="img/icon-update.svg" class="bg"/>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<ion-nav-view name="tab-receive"></ion-nav-view>
|
||||
</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-tab>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue