Async logic fixes

0e81fb6a4a449ae49e7055027669e2eee581ac47

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

1 files changed, +6 -13Showing whitespace changes
public/scripts/extensions.js+6 -13
@@ -4,7 +4,7 @@ import { eventSource, event_types, saveSettings, saveSettingsDebounced, getReque
4import { showLoader } from './loader.js';4import { showLoader } from './loader.js';
5import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js';5import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js';
6import { renderTemplate, renderTemplateAsync } from './templates.js';6import { renderTemplate, renderTemplateAsync } from './templates.js';
7import { isSubsetOf, setValueByPath } from './utils.js';7import { delay, isSubsetOf, setValueByPath } from './utils.js';
8import { getContext } from './st-context.js';8import { getContext } from './st-context.js';
9import { isAdmin } from './user.js';9import { isAdmin } from './user.js';
10import { t } from './i18n.js';10import { t } from './i18n.js';
@@ -689,6 +689,8 @@ async function showExtensionsDetails() {
689 const abortController = new AbortController();689 const abortController = new AbortController();
690 let popupPromise;690 let popupPromise;
691 try {691 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();
692 const htmlDefault = $('<div class="marginBot10"><h3 class="textAlignCenter">Built-in Extensions:</h3></div>');694 const htmlDefault = $('<div class="marginBot10"><h3 class="textAlignCenter">Built-in Extensions:</h3></div>');
693 const htmlExternal = $('<div class="marginBot10"><h3 class="textAlignCenter">Installed Extensions:</h3></div>');695 const htmlExternal = $('<div class="marginBot10"><h3 class="textAlignCenter">Installed Extensions:</h3></div>');
694 const htmlLoading = $(`<div class="flex-container alignItemsCenter justifyCenter marginTop10 marginBot5">696 const htmlLoading = $(`<div class="flex-container alignItemsCenter justifyCenter marginTop10 marginBot5">
@@ -723,12 +725,6 @@ async function showExtensionsDetails() {
723 },725 },
724 };726 };
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
732 let waitingForSave = false;728 let waitingForSave = false;
733729
734 const popup = new Popup(html, POPUP_TYPE.TEXT, '', {730 const popup = new Popup(html, POPUP_TYPE.TEXT, '', {
@@ -816,7 +812,7 @@ async function updateExtension(extensionName, quiet) {
816 const data = await response.json();812 const data = await response.json();
817813
818 if (!quiet) {814 if (!quiet) {
819 await showExtensionsDetails();815 void showExtensionsDetails();
820 }816 }
821817
822 if (data.isUpToDate) {818 if (data.isUpToDate) {
@@ -908,8 +904,7 @@ async function moveExtension(extensionName, source, destination) {
908904
909 toastr.success(t`Extension ${extensionName} moved.`);905 toastr.success(t`Extension ${extensionName} moved.`);
910 await loadExtensionSettings({}, false, false);906 await loadExtensionSettings({}, false, false);
911 await Popup.util.popups.find(popup => popup.content.querySelector('.extensions_info'))?.completeCancelled();907 void showExtensionsDetails();
912 showExtensionsDetails();
913 } catch (error) {908 } catch (error) {
914 console.error('Error:', error);909 console.error('Error:', error);
915 }910 }
@@ -934,9 +929,7 @@ export async function deleteExtension(extensionName) {
934 }929 }
935930
936 toastr.success(t`Extension ${extensionName} deleted`);931 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();
940}933}
941934
942/**935/**