Hide wand if no extensions with menu button are active

This commit is contained in:
Cohee
2023-06-12 17:13:56 +03:00
parent ecd8cad933
commit 65ee58d383

View File

@ -1,4 +1,4 @@
import { callPopup, eventSource, event_types, extension_prompt_types, saveSettings, saveSettingsDebounced } from "../script.js"; import { callPopup, eventSource, event_types, saveSettings, saveSettingsDebounced } from "../script.js";
import { isSubsetOf, debounce } from "./utils.js"; import { isSubsetOf, debounce } from "./utils.js";
export { export {
getContext, getContext,
@ -69,6 +69,20 @@ const getContext = () => window['SillyTavern'].getContext();
const getApiUrl = () => extension_settings.apiUrl; const getApiUrl = () => extension_settings.apiUrl;
let connectedToApi = false; let connectedToApi = false;
function showHideExtensionsMenu() {
const hasMenuItems = $('#extensionsMenu').children().length > 0;
// We have menu items, so we can stop checking
if (hasMenuItems) {
clearInterval(menuInterval);
}
$('#extensionsMenuButton').toggle(hasMenuItems);
}
// Periodically check for new extensions
const menuInterval = setInterval(showHideExtensionsMenu, 1000);
async function doExtrasFetch(endpoint, args) { async function doExtrasFetch(endpoint, args) {
if (!args) { if (!args) {
args = {} args = {}
@ -219,7 +233,7 @@ function autoConnectInputHandler() {
function addExtensionsButtonAndMenu() { function addExtensionsButtonAndMenu() {
const buttonHTML = const buttonHTML =
`<div id="extensionsMenuButton" class="fa-solid fa-magic-wand-sparkles" title="Extras Extensions" /></div>`; `<div id="extensionsMenuButton" style="display: none;" class="fa-solid fa-magic-wand-sparkles" title="Extras Extensions" /></div>`;
const extensionsMenuHTML = `<div id="extensionsMenu" class="options-content" style="display: none;"></div>`; const extensionsMenuHTML = `<div id="extensionsMenu" class="options-content" style="display: none;"></div>`;
$(document.body).append(extensionsMenuHTML); $(document.body).append(extensionsMenuHTML);