Async logic fixes

0e81fb6a4a449ae49e7055027669e2eee581ac47

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +6 -13Ignore whitespace
public/scripts/extensions.js+6 -13
@@ -4,7 +4,7 @@ import { eventSource, event_types, saveSettings, saveSettingsDebounced, getReque
44import { showLoader } from './loader.js';
55import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js';
66import { renderTemplate, renderTemplateAsync } from './templates.js';
77import { delay, isSubsetOf, setValueByPath } from './utils.js';
88import { getContext } from './st-context.js';
99import { isAdmin } from './user.js';
1010import { t } from './i18n.js';
@@ -689,6 +689,8 @@ async function showExtensionsDetails() {
689689 const abortController = new AbortController();
690690 let popupPromise;
691691 try {
692+ // If we are updating an extension, the "old" popup is still active. We should close that.
693+ await Popup.util.popups.find(popup => popup.content.querySelector('.extensions_info'))?.completeCancelled();
692694 const htmlDefault = $('<div class="marginBot10"><h3 class="textAlignCenter">Built-in Extensions:</h3></div>');
693695 const htmlExternal = $('<div class="marginBot10"><h3 class="textAlignCenter">Installed Extensions:</h3></div>');
694696 const htmlLoading = $(`<div class="flex-container alignItemsCenter justifyCenter marginTop10 marginBot5">
@@ -723,12 +725,6 @@ async function showExtensionsDetails() {
723725 },
724726 };
725727
726- // If we are updating an extension, the "old" popup is still active. We should close that.
727- const oldPopup = Popup.util.popups.find(popup => popup.content.querySelector('.extensions_info'));
728- if (oldPopup) {
729- await oldPopup.complete(POPUP_RESULT.CANCELLED);
730- }
731-
732728 let waitingForSave = false;
733729
734730 const popup = new Popup(html, POPUP_TYPE.TEXT, '', {
@@ -816,7 +812,7 @@ async function updateExtension(extensionName, quiet) {
816812 const data = await response.json();
817813
818814 if (!quiet) {
819815 awaitvoid showExtensionsDetails();
820816 }
821817
822818 if (data.isUpToDate) {
@@ -908,8 +904,7 @@ async function moveExtension(extensionName, source, destination) {
908904
909905 toastr.success(t`Extension ${extensionName} moved.`);
910906 await loadExtensionSettings({}, false, false);
911- await Popup.util.popups.find(popup => popup.content.querySelector('.extensions_info'))?.completeCancelled();
907+ void showExtensionsDetails();
912- showExtensionsDetails();
913908 } catch (error) {
914909 console.error('Error:', error);
915910 }
@@ -934,9 +929,7 @@ export async function deleteExtension(extensionName) {
934929 }
935930
936931 toastr.success(t`Extension ${extensionName} deleted`);
937- showExtensionsDetails();
932+ delay(1000).then(() => location.reload());
938- // reload the page to remove the extension from the list
939- location.reload();
940933}
941934
942935/**