From 4167fe3d2b807f4a77977df29fc0feb65f2e67e6 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 27 Sep 2024 00:44:58 +0300 Subject: [PATCH] Add Save and Update --- public/css/popup.css | 2 ++ .../extensions/connection-manager/index.js | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/public/css/popup.css b/public/css/popup.css index d184dc1fb..30586c3b2 100644 --- a/public/css/popup.css +++ b/public/css/popup.css @@ -149,10 +149,12 @@ body.no-blur .popup[open]::backdrop { box-shadow: 0 0 5px var(--white20a); } +.menu_button.primary, .menu_button.popup-button-ok { background-color: var(--crimson70a); } +.menu_button.primary:hover, .menu_button.popup-button-ok:hover { background-color: var(--crimson-hover); } diff --git a/public/scripts/extensions/connection-manager/index.js b/public/scripts/extensions/connection-manager/index.js index 19e4be3e8..6f16cadf3 100644 --- a/public/scripts/extensions/connection-manager/index.js +++ b/public/scripts/extensions/connection-manager/index.js @@ -1,6 +1,6 @@ import { event_types, eventSource, main_api, saveSettingsDebounced } from '../../../script.js'; import { extension_settings, renderExtensionTemplateAsync } from '../../extensions.js'; -import { callGenericPopup, Popup, POPUP_TYPE } from '../../popup.js'; +import { callGenericPopup, Popup, POPUP_RESULT, POPUP_TYPE } from '../../popup.js'; import { SlashCommand } from '../../slash-commands/SlashCommand.js'; import { SlashCommandAbortController } from '../../slash-commands/SlashCommandAbortController.js'; import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js'; @@ -523,6 +523,7 @@ async function renderDetailsContent(detailsContent) { profile.exclude = []; } + let saveChanges = false; const commands = profile.mode === 'cc' ? CC_COMMANDS : TC_COMMANDS; const settings = commands.reduce((acc, command) => { const fancyName = FANCY_NAMES[command]; @@ -530,7 +531,16 @@ async function renderDetailsContent(detailsContent) { return acc; }, {}); const template = $(await renderExtensionTemplateAsync(MODULE_NAME, 'edit', { name: profile.name, settings })); - const newName = await callGenericPopup(template, POPUP_TYPE.INPUT, profile.name); + const newName = await callGenericPopup(template, POPUP_TYPE.INPUT, profile.name, { + customButtons: [{ + text: 'Save and Update', + classes: ['primary'], + result: POPUP_RESULT.AFFIRMATIVE, + action: () => { + saveChanges = true; + }, + }], + }); if (!newName) { return; @@ -550,7 +560,11 @@ async function renderDetailsContent(detailsContent) { for (const command of newExcludeList) { delete profile[command]; } - toastr.info('Press "Update" to record them into the profile.', 'Included settings list updated'); + if (saveChanges) { + await updateConnectionProfile(profile); + } else { + toastr.info('Press "Update" to record them into the profile.', 'Included settings list updated'); + } } if (profile.name !== newName) {