Async logic fixes
| @@ -4,7 +4,7 @@ import { eventSource, event_types, saveSettings, saveSettingsDebounced, getReque | |||
| 4 | import { showLoader } from './loader.js'; | 4 | import { showLoader } from './loader.js'; |
| 5 | import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js'; | 5 | import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js'; |
| 6 | import { renderTemplate, renderTemplateAsync } from './templates.js'; | 6 | import { renderTemplate, renderTemplateAsync } from './templates.js'; |
| 7 | import { isSubsetOf, setValueByPath } from './utils.js'; | 7 | import { delay, isSubsetOf, setValueByPath } from './utils.js'; |
| 8 | import { getContext } from './st-context.js'; | 8 | import { getContext } from './st-context.js'; |
| 9 | import { isAdmin } from './user.js'; | 9 | import { isAdmin } from './user.js'; |
| 10 | import { t } from './i18n.js'; | 10 | import { 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 | }; |
| 725 | 727 | ||
| 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; |
| 733 | 729 | ||
| 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(); |
| 817 | 813 | ||
| 818 | if (!quiet) { | 814 | if (!quiet) { |
| 819 | await showExtensionsDetails(); | 815 | void showExtensionsDetails(); |
| 820 | } | 816 | } |
| 821 | 817 | ||
| 822 | if (data.isUpToDate) { | 818 | if (data.isUpToDate) { |
| @@ -908,8 +904,7 @@ async function moveExtension(extensionName, source, destination) { | |||
| 908 | 904 | ||
| 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 | } |
| 935 | 930 | ||
| 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 | } |
| 941 | 934 | ||
| 942 | /** | 935 | /** |