Skip to content

Commit 624ddd5

Browse files
author
Raghav Katyal
committed
Making focus handler work only for windows 10 phone
1 parent fb871d4 commit 624ddd5

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/windows/CameraProxy.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,9 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
745745
cameraCaptureUI.photoSettings.maxResolution = maxRes;
746746

747747
var cameraPicture;
748-
var savePhotoOnFocus = function() {
749-
748+
749+
// define focus handler for windows phone 10.0
750+
var savePhotoOnFocus = function () {
750751
window.removeEventListener("focus", savePhotoOnFocus);
751752
// call only when the app is in focus again
752753
savePhoto(cameraPicture, {
@@ -758,16 +759,31 @@ function takePictureFromCameraWindows(successCallback, errorCallback, args) {
758759
}, successCallback, errorCallback);
759760
};
760761

761-
// add and delete focus eventHandler to capture the focus back from cameraUI to app
762-
window.addEventListener("focus", savePhotoOnFocus);
763-
cameraCaptureUI.captureFileAsync(WMCapture.CameraCaptureUIMode.photo).done(function(picture) {
762+
// if windows phone 10, add and delete focus eventHandler to capture the focus back from cameraUI to app
763+
if (navigator.appVersion.indexOf('Windows Phone 10.0') >= 0) {
764+
window.addEventListener("focus", savePhotoOnFocus);
765+
}
766+
767+
cameraCaptureUI.captureFileAsync(WMCapture.CameraCaptureUIMode.photo).done(function (picture) {
764768
if (!picture) {
765769
errorCallback("User didn't capture a photo.");
770+
// Remove the focus handler if present
766771
window.removeEventListener("focus", savePhotoOnFocus);
767772
return;
768773
}
769774
cameraPicture = picture;
770-
}, function() {
775+
776+
// If not windows 10, call savePhoto() now. If windows 10, wait for the app to be in focus again
777+
if (navigator.appVersion.indexOf('Windows Phone 10.0') < 0) {
778+
savePhoto(cameraPicture, {
779+
destinationType: destinationType,
780+
targetHeight: targetHeight,
781+
targetWidth: targetWidth,
782+
encodingType: encodingType,
783+
saveToPhotoAlbum: saveToPhotoAlbum
784+
}, successCallback, errorCallback);
785+
}
786+
}, function () {
771787
errorCallback("Fail to capture a photo.");
772788
window.removeEventListener("focus", savePhotoOnFocus);
773789
});

0 commit comments

Comments
 (0)