Fix use_face_correction not disabling on false

This commit is contained in:
Marc-Andre Ferland 2022-11-03 20:34:12 -04:00
parent c3cc75feff
commit d5f854d376

View File

@ -1,5 +1,35 @@
"use strict" // Opt in to a restricted variant of JavaScript "use strict" // Opt in to a restricted variant of JavaScript
function parseBoolean(stringValue) {
if (typeof stringValue === 'boolean') {
return stringValue
}
if (typeof stringValue === 'number') {
return stringValue !== 0
}
if (typeof stringValue !== 'string') {
return false
}
switch(stringValue?.toLowerCase()?.trim()) {
case "true":
case "yes":
case "1":
return true;
case "false":
case "no":
case "0":
case null:
case undefined:
return false;
}
try {
return Boolean(JSON.parse(stringValue));
} catch {
return Boolean(stringValue)
}
}
const TASK_MAPPING = { const TASK_MAPPING = {
prompt: { name: 'Prompt', prompt: { name: 'Prompt',
setUI: (prompt) => { setUI: (prompt) => {
@ -93,10 +123,10 @@ const TASK_MAPPING = {
use_face_correction: { name: 'Use Face Correction', use_face_correction: { name: 'Use Face Correction',
setUI: (use_face_correction) => { setUI: (use_face_correction) => {
useFaceCorrectionField.checked = Boolean(use_face_correction) useFaceCorrectionField.checked = parseBoolean(use_face_correction)
}, },
readUI: () => useFaceCorrectionField.checked, readUI: () => useFaceCorrectionField.checked,
parse: (val) => val parse: (val) => parseBoolean(val)
}, },
use_upscale: { name: 'Use Upscaling', use_upscale: { name: 'Use Upscaling',
setUI: (use_upscale) => { setUI: (use_upscale) => {