From 396ed2e832388162b8b41931c2891ecb840e2ffe Mon Sep 17 00:00:00 2001 From: Andreas Blaesius Date: Mon, 10 Jan 2022 23:37:33 +0100 Subject: [PATCH 1/4] feature: optional retry to take a picture on error Change-Id: I830caf18be25c6d51a42318ba4055b7e3afb9a72 --- config/config.inc.php | 2 ++ lib/configsetup.inc.php | 22 ++++++++++++++++++++++ resources/lang/en.json | 6 ++++++ src/js/core.js | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/config/config.inc.php b/config/config.inc.php index 6b9577d93..b40af776d 100644 --- a/config/config.inc.php +++ b/config/config.inc.php @@ -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'; diff --git a/lib/configsetup.inc.php b/lib/configsetup.inc.php index a55380cd8..f80a9caa7 100644 --- a/lib/configsetup.inc.php +++ b/lib/configsetup.inc.php @@ -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', diff --git a/resources/lang/en.json b/resources/lang/en.json index f40b8bdde..325b41ac2 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -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)", @@ -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.", @@ -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", @@ -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 ...", diff --git a/src/js/core.js b/src/js/core.js index 194c56250..68c08cdba 100644 --- a/src/js/core.js +++ b/src/js/core.js @@ -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) @@ -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( + $('

').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); + $('

') + .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; From 72ecae687d070b476feabc1645bd1ec4f05fc516 Mon Sep 17 00:00:00 2001 From: Andreas Blaesius Date: Wed, 12 Jan 2022 07:07:02 +0100 Subject: [PATCH 2/4] core: move GET request to api.thrill function - avoid making a get request while retrying to take a picture Change-Id: Ie59ec8cfc7687dd3558d7b101e51c94e77130cff --- src/js/core.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/js/core.js b/src/js/core.js index 68c08cdba..b6046a33d 100644 --- a/src/js/core.js +++ b/src/js/core.js @@ -312,6 +312,9 @@ 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); }); }; @@ -920,22 +923,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--; From eae2bbbdd7cdc9a46e4138fb2dabc20895f9bbf4 Mon Sep 17 00:00:00 2001 From: Andreas Blaesius Date: Wed, 12 Jan 2022 21:28:44 +0100 Subject: [PATCH 3/4] core: add retry check to api.cheese function - on retry we only need the cheese message again, save some lines of code Change-Id: I21f89d3e8deb0c649e1793cf86678cc8481e454c --- src/js/core.js | 53 +++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/src/js/core.js b/src/js/core.js index b6046a33d..8d3fe37aa 100644 --- a/src/js/core.js +++ b/src/js/core.js @@ -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(); @@ -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); + } } }; @@ -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); - $('

') - .text(`${nextCollageNumber + 1} / ${config.collage.limit}`) - .appendTo('.cheese'); - } + api.cheese(data.style, retry); setTimeout(() => { api.callTakePicApi(data, retry); }, config.picture.cheese_time); From 244aa7a82818f682712d7b144300c0cedfe547aa Mon Sep 17 00:00:00 2001 From: Andreas Blaesius Date: Wed, 12 Jan 2022 22:06:41 +0100 Subject: [PATCH 4/4] manual: be more clear about timeout setting timeout = countdown Change-Id: Ib5e9714aebfd9081ed043dd71f0983c4ab21ebf7 --- resources/lang/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en.json b/resources/lang/en.json index 325b41ac2..8176d4324 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -304,7 +304,7 @@ "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_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.",