Skip to content

Commit

Permalink
Merge pull request wildabeast#267 from daserge/multiple-scan
Browse files Browse the repository at this point in the history
Prevent multiple calls to scanner
  • Loading branch information
Sergey Shakhnazarov authored Jun 23, 2016
2 parents 55e6938 + 2aa5bdc commit 78a5345
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion www/barcodescanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

var exec = require("cordova/exec");

var scanInProgress = false;

/**
* Constructor.
*
Expand Down Expand Up @@ -97,7 +99,26 @@ BarcodeScanner.prototype.scan = function (successCallback, errorCallback, config
return;
}

exec(successCallback, errorCallback, 'BarcodeScanner', 'scan', config);
if (scanInProgress) {
errorCallback('Scan is already in progress');
return;
}

scanInProgress = true;

exec(
function(result) {
scanInProgress = false;
successCallback(result);
},
function(error) {
scanInProgress = false;
errorCallback(error);
},
'BarcodeScanner',
'scan',
config
);
};

//-------------------------------------------------------------------
Expand Down

0 comments on commit 78a5345

Please sign in to comment.