From 15bc0e4dba7ffd8ad250061b765424e838bf3099 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Wed, 25 Sep 2024 23:53:26 +0200 Subject: [PATCH] Squish the last bugs --- public/scripts/extensions-slashcommands.js | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/public/scripts/extensions-slashcommands.js b/public/scripts/extensions-slashcommands.js index 499b86ecb..c8bfa96f3 100644 --- a/public/scripts/extensions-slashcommands.js +++ b/public/scripts/extensions-slashcommands.js @@ -20,7 +20,7 @@ function getExtensionActionCallback(action) { return ''; } - const reload = isTrueBoolean(args?.reload); + const reload = !isFalseBoolean(args?.reload); const internalExtensionName = findExtension(extensionName); if (!internalExtensionName) { toastr.warning(`Extension ${extensionName} does not exist.`); @@ -43,7 +43,14 @@ function getExtensionActionCallback(action) { action = isEnabled ? 'disable' : 'enable'; } - reload && toastr.info(`${action.charAt(0).toUpperCase() + action.slice(1)}ing extension ${extensionName} and reloading...`); + if (reload) { + toastr.info(`${action.charAt(0).toUpperCase() + action.slice(1)}ing extension ${extensionName} and reloading...`); + + // Clear input, so it doesn't stay because the command didn't "finish", + // and wait for a bit to both show the toast and let the clear bubble through. + $('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true })); + await new Promise(resolve => setTimeout(resolve, 100)); + } if (action === 'enable') { await enableExtension(internalExtensionName, reload); @@ -53,6 +60,12 @@ function getExtensionActionCallback(action) { toastr.success(`Extension ${extensionName} ${action}d.`); + + console.info(`Extension ${action}ed: ${extensionName}`); + if (!reload) { + console.info('Reload not requested, so page needs to be reloaded manually for changes to take effect.'); + } + return internalExtensionName; }; } @@ -88,6 +101,7 @@ export function registerExtensionSlashCommands() { SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'extension-enable', callback: getExtensionActionCallback('enable'), + returns: 'The internal extension name', namedArgumentList: [ SlashCommandNamedArgument.fromProps({ name: 'reload', @@ -127,7 +141,8 @@ export function registerExtensionSlashCommands() { })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'extension-disable', - callback: getExtensionActionCallback('enable'), + callback: getExtensionActionCallback('disable'), + returns: 'The internal extension name', namedArgumentList: [ SlashCommandNamedArgument.fromProps({ name: 'reload', @@ -177,6 +192,7 @@ export function registerExtensionSlashCommands() { return await getExtensionActionCallback(action)(args, extensionName); }, + returns: 'The internal extension name', namedArgumentList: [ SlashCommandNamedArgument.fromProps({ name: 'reload', @@ -236,6 +252,7 @@ export function registerExtensionSlashCommands() { const isEnabled = !extension_settings.disabledExtensions.includes(internalExtensionName); return String(isEnabled); }, + returns: 'true/false - The state of the extension, whether it is enabled.', unnamedArgumentList: [ SlashCommandArgument.fromProps({ description: 'Extension name', @@ -267,6 +284,7 @@ export function registerExtensionSlashCommands() { const exists = findExtension(extensionName) !== undefined; return exists ? 'true' : 'false'; }, + returns: 'true/false - Whether the extension exists and is installed.', unnamedArgumentList: [ SlashCommandArgument.fromProps({ description: 'Extension name',