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

Commit

Permalink
core: add retry check to api.cheese function
Browse files Browse the repository at this point in the history
- on retry we only need the cheese message again,
  save some lines of code

Change-Id: I21f89d3e8deb0c649e1793cf86678cc8481e454c
  • Loading branch information
andi34 committed Jan 12, 2022
1 parent 72ecae6 commit eae2bbb
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ const photoBooth = (function () {
};

// Cheese
api.cheese = function (photoStyle) {
api.cheese = function (photoStyle, retry = 0) {
photoboothTools.console.logDev('Photostyle: ' + photoStyle);

counter.empty();
Expand All @@ -339,27 +339,29 @@ const photoBooth = (function () {
.appendTo('.cheese');
}

if (config.preview.mode === 'gphoto' && !config.picture.no_cheese) {
api.stopPreviewVideo();
}
if (retry <= 0) {
if (config.preview.mode === 'gphoto' && !config.picture.no_cheese) {
api.stopPreviewVideo();
}

if (
config.preview.mode === 'device_cam' &&
config.preview.camTakesPic &&
!api.stream &&
!config.dev.demo_images
) {
photoboothTools.console.log('No preview by device cam available!');
if (
config.preview.mode === 'device_cam' &&
config.preview.camTakesPic &&
!api.stream &&
!config.dev.demo_images
) {
photoboothTools.console.log('No preview by device cam available!');

api.errorPic({
error: 'No preview by device cam available!'
});
} else if (config.picture.no_cheese) {
api.takePic(photoStyle);
} else {
setTimeout(() => {
api.errorPic({
error: 'No preview by device cam available!'
});
} else if (config.picture.no_cheese) {
api.takePic(photoStyle);
}, config.picture.cheese_time);
} else {
setTimeout(() => {
api.takePic(photoStyle);
}, config.picture.cheese_time);
}
}
};

Expand Down Expand Up @@ -435,23 +437,12 @@ const photoBooth = (function () {
);
api.startCountdown(config.picture.retry_timeout, counter, () => {
loading.empty();
counter.empty();
cheese.empty();

if (config.picture.no_cheese) {
photoboothTools.console.log('Cheese is disabled.');
api.callTakePicApi(data, retry);
} else {
if (data.style === 'photo' || data.style === 'chroma') {
const cheesemsg = photoboothTools.getTranslation('cheese');
cheese.text(cheesemsg);
} else {
const cheesemsg = photoboothTools.getTranslation('cheeseCollage');
cheese.text(cheesemsg);
$('<p>')
.text(`${nextCollageNumber + 1} / ${config.collage.limit}`)
.appendTo('.cheese');
}
api.cheese(data.style, retry);
setTimeout(() => {
api.callTakePicApi(data, retry);
}, config.picture.cheese_time);
Expand Down

0 comments on commit eae2bbb

Please sign in to comment.