From 77c11b8f2b2ada05a07fa7ef26adb222fa4b74ac Mon Sep 17 00:00:00 2001 From: Juha Jeronen Date: Fri, 5 Jan 2024 12:15:24 +0200 Subject: [PATCH] set_emotion is not supported by old talkinghead versions --- .../scripts/extensions/expressions/index.js | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js index fcf5013f1..13f958455 100644 --- a/public/scripts/extensions/expressions/index.js +++ b/public/scripts/extensions/expressions/index.js @@ -1109,39 +1109,39 @@ async function setExpression(character, expression, force) { document.getElementById('expression-holder').style.display = ''; } else { - - - talkingHeadCheck().then(result => { + // Set the talkinghead emotion to the specified expression + // TODO: For now, talkinghead emote only supported when VN mode is off; see also updateVisualNovelMode. + try + { + let result = await talkingHeadCheck(); if (result) { - // Set the talkinghead emotion to the specified expression - // TODO: For now, talkinghead emote only supported when VN mode is off; see also updateVisualNovelMode. const url = new URL(getApiUrl()); url.pathname = '/api/talkinghead/set_emotion'; - doExtrasFetch(url, { + await doExtrasFetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ emotion_name: expression }), - }) - .then(response => { - // Find the element with id="expression-image" and class="expression" - const imgElement = document.querySelector('img#expression-image.expression'); - //console.log("searching"); - if (imgElement && imgElement instanceof HTMLImageElement) { - //console.log("setting value"); - imgElement.src = getApiUrl() + '/api/talkinghead/result_feed'; - } - }) - .catch(error => { - console.error(error); - }) - } else { - //console.log("The fetch failed!"); + }); } - }); - + } + catch (error) { + // `set_emotion` is not present in old versions, so let it 404. + } + try { + // Find the element with id="expression-image" and class="expression" + const imgElement = document.querySelector('img#expression-image.expression'); + //console.log("searching"); + if (imgElement && imgElement instanceof HTMLImageElement) { + //console.log("setting value"); + imgElement.src = getApiUrl() + '/api/talkinghead/result_feed'; + } + } + catch (error) { + //console.log("The fetch failed!"); + } } }