Require to save settings before reloading.

bc7660bba6a606f61f28aa0c7ff8e2b032e5ae75

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

2 files changed, +20 -4Ignore whitespace
public/scripts/extensions.js+17 -1
@@ -21,6 +21,7 @@ const defaultUrl = 'http://localhost:5100';
2121let saveMetadataTimeout = null;
2222
2323let requiresReload = false;
24+let stateChanged = false;
2425
2526export function saveMetadataDebounced() {
2627 const context = getContext();
@@ -238,6 +239,7 @@ function onEnableExtensionClick() {
238239
239240async function enableExtension(name, reload = true) {
240241 extension_settings.disabledExtensions = extension_settings.disabledExtensions.filter(x => x !== name);
242+ stateChanged = true;
241243 await saveSettings();
242244 if (reload) {
243245 location.reload();
@@ -248,6 +250,7 @@ async function enableExtension(name, reload = true) {
248250
249251async function disableExtension(name, reload = true) {
250252 extension_settings.disabledExtensions.push(name);
253+ stateChanged = true;
251254 await saveSettings();
252255 if (reload) {
253256 location.reload();
@@ -657,7 +660,20 @@ async function showExtensionsDetails() {
657660 await oldPopup.complete(POPUP_RESULT.CANCELLED);
658661 }
659662
660663 const popup = new Popup(html, POPUP_TYPE.TEXT, '', { okButton: 'Close', wide: true, large: true, customButtons: [updateAllButton], allowVerticalScrolling: true });
664+ okButton: 'Close',
665+ wide: true,
666+ large: true,
667+ customButtons: [updateAllButton],
668+ allowVerticalScrolling: true,
669+ onClosing: async () => {
670+ if (stateChanged) {
671+ toastr.info('The page will be reloaded shortly...', 'Extensions state changed');
672+ await saveSettings();
673+ }
674+ return true;
675+ },
676+ });
661677 popupPromise = popup.show();
662678 } catch (error) {
663679 toastr.error('Error loading extensions. See browser console for details.');
public/scripts/popup.js+3 -3
@@ -40,7 +40,7 @@ export const POPUP_RESULT = {
4040 * @property {POPUP_RESULT|number?} [defaultResult=POPUP_RESULT.AFFIRMATIVE] - The default result of this popup when Enter is pressed. Can be changed from `POPUP_RESULT.AFFIRMATIVE`.
4141 * @property {CustomPopupButton[]|string[]?} [customButtons=null] - Custom buttons to add to the popup. If only strings are provided, the buttons will be added with default options, and their result will be in order from `2` onward.
4242 * @property {CustomPopupInput[]?} [customInputs=null] - Custom inputs to add to the popup. The display below the content and the input box, one by one.
4343 * @property {(popup: Popup) => Promise<boolean?>|boolean?} [onClosing=null] - Handler called before the popup closes, return `false` to cancel the close
4444 * @property {(popup: Popup) => void?} [onClose=null] - Handler called after the popup closes, but before the DOM is cleaned up
4545 * @property {number?} [cropAspect=null] - Aspect ratio for the crop popup
4646 * @property {string?} [cropImage=null] - Image URL to display in the crop popup
@@ -138,7 +138,7 @@ export class Popup {
138138 /** @readonly @type {CustomPopupButton[]|string[]?} */ customButtons;
139139 /** @readonly @type {CustomPopupInput[]} */ customInputs;
140140
141141 /** @type {(popup: Popup) => Promise<boolean?>|boolean?} */ onClosing;
142142 /** @type {(popup: Popup) => void?} */ onClose;
143143
144144 /** @type {POPUP_RESULT|number} */ result;
@@ -509,7 +509,7 @@ export class Popup {
509509 this.result = result;
510510
511511 if (this.onClosing) {
512512 const shouldClose = await this.onClosing(this);
513513 if (!shouldClose) {
514514 this.#isClosingPrevented = true;
515515 // Set values back if we cancel out of closing the popup