Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Avoid crash on Surface3
Browse files Browse the repository at this point in the history
Looks like focusState property somehow is not accessible on Surface3. Since there is no other way to detect whether accessing property would cause a crash, the only chance to avoid it - wrap in try/catch and continue focusing it it threw

This fixes #288
  • Loading branch information
vladimir-kotikov committed Sep 1, 2016
1 parent 3cf975b commit 1473daa
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/windows/BarcodeScannerProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,14 @@ module.exports = {
}

// Multiple calls to focusAsync leads to internal focusing hang on some Windows Phone 8.1 devices
if (controller.focusControl.focusState === Windows.Media.Devices.MediaCaptureFocusState.searching) {
return result;
// Also need to wrap in try/catch to avoid crash on Surface 3 - looks like focusState property
// somehow is not accessible there. See https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/288
try {
if (controller.focusControl.focusState === Windows.Media.Devices.MediaCaptureFocusState.searching) {
return result;
}
} catch (e) {
// Nothing to do - just continue w/ focusing
}

// The delay prevents focus hang on slow devices
Expand Down Expand Up @@ -399,7 +405,7 @@ module.exports = {

focusControl.configure(focusConfig);

// Continuous focus should start only after preview has started. See 'Remarks' at
// Continuous focus should start only after preview has started. See 'Remarks' at
// https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.devices.focuscontrol.configure.aspx
function waitForIsPlaying() {
var isPlaying = !capturePreview.paused && !capturePreview.ended && capturePreview.readyState > 2;
Expand Down

0 comments on commit 1473daa

Please sign in to comment.