diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js index 6656353c5..58b93cc0d 100644 --- a/public/scripts/extensions/expressions/index.js +++ b/public/scripts/extensions/expressions/index.js @@ -395,6 +395,26 @@ function onExpressionsShowDefaultInput() { } } +async function unloadLiveChar() { + try { + const url = new URL(getApiUrl()); + url.pathname = '/api/live2d/unload'; + + const loadResponse = await fetch(url); + + if (!loadResponse.ok) { + throw new Error(loadResponse.statusText); + } + + const loadResponseText = await loadResponse.text(); + console.log(`Response: ${loadResponseText}`); + + } catch (error) { + console.error(`Error unloading - ${error}`); + } +} + + async function loadLiveChar() { if (!modules.includes('live2d')) { console.debug('live2d module is disabled'); @@ -615,7 +635,12 @@ function setLive2dState(switch_var){ extension_settings.expressions.live2d = switch_var; // Store setting saveSettingsDebounced(); - if (extension_settings.expressions.live2d) { loadLiveChar(); } // load char as needed + if (extension_settings.expressions.live2d) { + loadLiveChar(); + } else { + unloadLiveChar(); + } + handleImageChange(switch_var); // Change image as needed }