Merge pull request #6195 from gabrielbazan7/fix/wpScanner
add old scanner for windows platform
This commit is contained in:
commit
44efc77481
34 changed files with 233 additions and 123 deletions
|
|
@ -5,7 +5,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
|||
var credentials = {};
|
||||
var isCordova = platformInfo.isCordova;
|
||||
var isNW = platformInfo.isNW;
|
||||
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
|
||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||
|
||||
root.priceSensitivity = [{
|
||||
value: 0.5,
|
||||
|
|
@ -327,14 +327,14 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
|||
};
|
||||
|
||||
root.getBuyOrder = function(token, accountId, buyId, cb) {
|
||||
if (!token) return cb('Invalid Token');
|
||||
$http(_get('/accounts/' + accountId + '/buys/' + buyId, token)).then(function(data) {
|
||||
$log.info('Coinbase Buy Info: SUCCESS');
|
||||
return cb(null, data.data);
|
||||
}, function(data) {
|
||||
$log.error('Coinbase Buy Info: ERROR ' + data.statusText);
|
||||
return cb(data.data);
|
||||
});
|
||||
if (!token) return cb('Invalid Token');
|
||||
$http(_get('/accounts/' + accountId + '/buys/' + buyId, token)).then(function(data) {
|
||||
$log.info('Coinbase Buy Info: SUCCESS');
|
||||
return cb(null, data.data);
|
||||
}, function(data) {
|
||||
$log.error('Coinbase Buy Info: ERROR ' + data.statusText);
|
||||
return cb(data.data);
|
||||
});
|
||||
};
|
||||
|
||||
root.getTransaction = function(token, accountId, transactionId, cb) {
|
||||
|
|
@ -761,7 +761,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
|||
|
||||
var register = function() {
|
||||
|
||||
root.isActive(function(err, isActive){
|
||||
root.isActive(function(err, isActive) {
|
||||
if (err) return;
|
||||
|
||||
buyAndSellService.register({
|
||||
|
|
@ -780,7 +780,7 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
|
|||
|
||||
$rootScope.$on('bwsEvent', function(e, walletId, type, n) {
|
||||
if (type == 'NewBlock' && n && n.data && n.data.network == 'livenet') {
|
||||
root.isActive(function(err,isActive){
|
||||
root.isActive(function(err, isActive) {
|
||||
// Update Coinbase
|
||||
if (isActive)
|
||||
root.updatePendingTransactions();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log, $timeout, $rootScope) {
|
||||
angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log, $timeout, $rootScope, platformInfo) {
|
||||
var root = {};
|
||||
|
||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||
|
||||
var defaultConfig = {
|
||||
// wallet limits
|
||||
limits: {
|
||||
|
|
@ -65,7 +67,7 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
},
|
||||
|
||||
hideNextSteps: {
|
||||
enabled: false,
|
||||
enabled: isWindowsPhoneApp ? true : false,
|
||||
},
|
||||
|
||||
rates: {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
var root = {};
|
||||
var credentials = {};
|
||||
var isCordova = platformInfo.isCordova;
|
||||
var isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
|
||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||
|
||||
var setCredentials = function() {
|
||||
if (!$window.externalServices || !$window.externalServices.glidera) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
angular.module('copayApp.services').factory('ongoingProcess', function($log, $timeout, $filter, lodash, $ionicLoading, gettext, platformInfo) {
|
||||
var root = {};
|
||||
var isCordova = platformInfo.isCordova;
|
||||
var isWP = platformInfo.isWP;
|
||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||
|
||||
var ongoingProcess = {};
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
|
|||
|
||||
root.clear = function() {
|
||||
ongoingProcess = {};
|
||||
if (isCordova && !isWP) {
|
||||
if (isCordova && !isWindowsPhoneApp) {
|
||||
window.plugins.spinnerDialog.hide();
|
||||
} else {
|
||||
$ionicLoading.hide();
|
||||
|
|
@ -81,19 +81,19 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
|
|||
if (customHandler) {
|
||||
customHandler(processName, showName, isOn);
|
||||
} else if (root.onGoingProcessName) {
|
||||
if (isCordova && !isWP) {
|
||||
if (isCordova && !isWindowsPhoneApp) {
|
||||
window.plugins.spinnerDialog.show(null, showName, root.clear);
|
||||
} else {
|
||||
|
||||
var tmpl;
|
||||
if (isWP) tmpl = '<div>' + showName + '</div>';
|
||||
if (isWindowsPhoneApp) tmpl = '<div>' + showName + '</div>';
|
||||
else tmpl = '<div class="item-icon-left">' + showName + '<ion-spinner class="spinner-stable" icon="lines"></ion-spinner></div>';
|
||||
$ionicLoading.show({
|
||||
template: tmpl
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (isCordova && !isWP) {
|
||||
if (isCordova && !isWindowsPhoneApp) {
|
||||
window.plugins.spinnerDialog.hide();
|
||||
} else {
|
||||
$ionicLoading.hide();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
angular.module('copayApp.services').service('popupService', function($log, $ionicPopup, platformInfo, gettextCatalog) {
|
||||
|
||||
var isCordova = platformInfo.isCordova;
|
||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||
|
||||
/*************** Ionic ****************/
|
||||
|
||||
|
|
@ -121,7 +122,7 @@ angular.module('copayApp.services').service('popupService', function($log, $ioni
|
|||
|
||||
opts = opts || {};
|
||||
|
||||
if (isCordova && !opts.forceHTMLPrompt)
|
||||
if (isCordova && !isWindowsPhoneApp && !opts.forceHTMLPrompt)
|
||||
_cordovaPrompt(title, message, opts, cb);
|
||||
else
|
||||
_ionicPrompt(title, message, opts, cb);
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ angular.module('copayApp.services')
|
|||
|
||||
var isChromeApp = platformInfo.isChromeApp;
|
||||
var isCordova = platformInfo.isCordova;
|
||||
var isWP = platformInfo.isWP;
|
||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||
var isIOS = platformInfo.isIOS;
|
||||
|
||||
var root = {};
|
||||
var errors = bwcService.getErrors();
|
||||
var usePushNotifications = isCordova && !isWP;
|
||||
var usePushNotifications = isCordova && !isWindowsPhoneApp;
|
||||
|
||||
var UPDATE_PERIOD = 15;
|
||||
|
||||
|
|
@ -208,9 +208,9 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
var shouldSkipValidation = function(walletId) {
|
||||
return root.profile.isChecked(platformInfo.ua, walletId) || isIOS || isWP;
|
||||
}
|
||||
// Used when reading wallets from the profile
|
||||
return root.profile.isChecked(platformInfo.ua, walletId) || isIOS || isWindowsPhoneApp;
|
||||
}
|
||||
// Used when reading wallets from the profile
|
||||
root.bindWallet = function(credentials, cb) {
|
||||
if (!credentials.walletId || !credentials.m)
|
||||
return cb('bindWallet should receive credentials JSON');
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue