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

Commit

Permalink
feature: optional retry to take a picture on error
Browse files Browse the repository at this point in the history
Change-Id: I830caf18be25c6d51a42318ba4055b7e3afb9a72
  • Loading branch information
andi34 committed Jan 11, 2022
1 parent 22ddfa8 commit 396ed2e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
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' => [
'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. \"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
37 changes: 36 additions & 1 deletion src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,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 +422,41 @@ 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();
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');
}
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

0 comments on commit 396ed2e

Please sign in to comment.