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

feature: optional retry to take a picture on error #366

Merged
merged 4 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
// control time in seconds until Photobooth reloads automatically
$config['picture']['time_to_live'] = '90';
$config['picture']['preview_before_processing'] = false;
$config['picture']['retry_on_error'] = '0';
$config['picture']['retry_timeout'] = '2';
$config['delete']['no_request'] = false;
$config['database']['enabled'] = true;
$config['database']['file'] = 'db';
Expand Down
22 changes: 22 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,28 @@
'name' => 'picture[preview_before_processing]',
'value' => $config['picture']['preview_before_processing'],
],
'picture_retry_on_error' => [
andi34 marked this conversation as resolved.
Show resolved Hide resolved
'view' => 'expert',
'type' => 'range',
'placeholder' => $defaultConfig['picture']['retry_on_error'],
'name' => 'picture[retry_on_error]',
'value' => $config['picture']['retry_on_error'],
'range_min' => 0,
'range_max' => 10,
'range_step' => 1,
'unit' => 'multiplied',
],
'picture_retry_timeout' => [
'view' => 'expert',
'type' => 'range',
'placeholder' => $defaultConfig['picture']['retry_timeout'],
'name' => 'picture[retry_timeout]',
'value' => $config['picture']['retry_timeout'],
'range_min' => 0,
'range_max' => 10,
'range_step' => 1,
'unit' => 'seconds',
],
'delete_no_request' => [
'view' => 'expert',
'type' => 'checkbox',
Expand Down
6 changes: 6 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
"general:download_enabled": "Allow downloads",
"general:download_thumbs": "Use thumbnails for download",
"general:picture_preview_before_processing": "Preload and show image during filter processing",
"general:picture_retry_on_error": "Retry taking a picture",
"general:picture_retry_timeout": "Retry timeout",
"general:picture_thumb_size": "Thumbnail size",
"general:picture_time_to_live": "Show image after capture:",
"general:start_screen_subtitle": "Start screen (subtitle)",
Expand Down Expand Up @@ -301,6 +303,8 @@
"manual:general:download_enabled": "If enabled, a download button is visible on each picture inside the gallery.",
"manual:general:download_thumbs": "If enabled, thumbnails will be used at download (if exist) instead the full sized image.",
"manual:general:picture_preview_before_processing": "If enabled, images are preloaded and shown during filter processing.",
"manual:general:picture_retry_on_error": "Set how often the system will try to take a picture in the event of an error. 0 = disabled.",
"manual:general:picture_retry_timeout": "Set a time after which the photo recording will be tried again (countdown). \"Retry taking a picture\" needs to be set to a value > 0.",
"manual:general:picture_thumb_size": "Choose thumbnail size: XS = max 360px, S = max 540px, M = max 900px, L = max 1080px, XL = max 1260px",
"manual:general:picture_time_to_live": "Choose a time between 1 and 90 seconds. Your picture is visible for that time on the result screen after taking it.",
"manual:general:start_screen_subtitle": "Enter the subtitle visible on startpage.",
Expand Down Expand Up @@ -449,6 +453,7 @@
"manual:version:check_version": "This will check online against the Github repository for the latest Photobooth version.",
"manual:version:updater_button": "This will check if Photobooth can be updated and perform the update. Only works on Linux if Photobooth was installed via git.",
"milliseconds": "ms",
"multiplied": "x",
"myconfig": "My Config",
"newCollage": "New Collage",
"newPhoto": "New Picture",
Expand Down Expand Up @@ -564,6 +569,7 @@
"reset:reset_remove_images": "Delete images",
"reset:reset_remove_mailtxt": "Delete e-mail addresses database",
"retakePhoto": "Retake",
"retry_message": "Taking picture failed. Retrying. Retry:",
"save": "Save",
"saveerror": "Error!",
"saving": "Saving ...",
Expand Down
90 changes: 60 additions & 30 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,15 @@ const photoBooth = (function () {
loader.addClass('open');

api.startCountdown(nextCollageNumber ? config.collage.cntdwn_time : config.picture.cntdwn_time, counter, () => {
if (config.get_request.countdown) {
api.getRequest(photoStyle);
}
api.cheese(photoStyle);
});
};

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

counter.empty();
Expand All @@ -336,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 @@ -401,6 +406,7 @@ const photoBooth = (function () {
};

api.callTakePicApi = function (data, retry = 0) {
const retrymsg = photoboothTools.getTranslation('retry_message');
startTime = new Date().getTime();
jQuery
.post('api/takePic.php', data)
Expand All @@ -421,7 +427,30 @@ const photoBooth = (function () {
$('#' + imgFilter).addClass('activeSidenavBtn');

if (result.error) {
api.errorPic(result);
if (config.picture.retry_on_error > 0 && retry < config.picture.retry_on_error) {
photoboothTools.console.logDev('Taking picture failed. Retrying. Retry: ' + retry);
retry += 1;
loading.append(
$('<p class="text-muted">').text(
retrymsg + ' ' + retry + '/' + config.picture.retry_on_error
)
);
api.startCountdown(config.picture.retry_timeout, counter, () => {
loading.empty();

if (config.picture.no_cheese) {
photoboothTools.console.log('Cheese is disabled.');
api.callTakePicApi(data, retry);
andi34 marked this conversation as resolved.
Show resolved Hide resolved
} else {
api.cheese(data.style, retry);
setTimeout(() => {
api.callTakePicApi(data, retry);
}, config.picture.cheese_time);
}
});
} else {
api.errorPic(result);
}
} else if (result.success === 'collage') {
currentCollageFile = result.file;
nextCollageNumber = result.current + 1;
Expand Down Expand Up @@ -885,22 +914,23 @@ const photoBooth = (function () {
$('#mail-form-message').html('');
};

// GET Request
api.getRequest = function (photoStyle) {
const getMode =
photoStyle === 'photo' || photoStyle === 'chroma' ? config.get_request.picture : config.get_request.collage;
const getUrl = config.get_request.server + '/' + getMode;
const request = new XMLHttpRequest();
photoboothTools.console.log('Sending GET request to: ' + getUrl);
request.open('GET', getUrl);
request.send();
};

// Countdown Function
api.startCountdown = function (start, element, cb) {
let count = 0;
let current = start;
const stop = start > 2 ? start - 2 : start;

if (config.get_request.countdown) {
const getMode =
start === config.picture.cntdwn_time ? config.get_request.picture : config.get_request.collage;
const getUrl = config.get_request.server + '/' + getMode;
const request = new XMLHttpRequest();
photoboothTools.console.log('Sending GET request to: ' + getUrl);
request.open('GET', getUrl);
request.send();
}

function timerFunction() {
element.text(Number(current) + Number(config.picture.cntdwn_offset));
current--;
Expand Down