diff --git a/browser_tests/extensionAPI.spec.ts b/browser_tests/extensionAPI.spec.ts index 37d6dee20..2e5192e85 100644 --- a/browser_tests/extensionAPI.spec.ts +++ b/browser_tests/extensionAPI.spec.ts @@ -280,5 +280,22 @@ test.describe('Topbar commands', () => { await comfyPage.confirmDialog.click('confirm') expect(await comfyPage.page.evaluate(() => window['value'])).toBe(true) }) + + test('Should allow dismissing a dialog', async ({ comfyPage }) => { + await comfyPage.page.evaluate(() => { + window['value'] = 'foo' + window['app'].extensionManager.dialog + .confirm({ + title: 'Test Confirm', + message: 'Test Confirm Message' + }) + .then((value: boolean) => { + window['value'] = value + }) + }) + + await comfyPage.confirmDialog.click('reject') + expect(await comfyPage.page.evaluate(() => window['value'])).toBeNull() + }) }) }) diff --git a/src/stores/dialogStore.ts b/src/stores/dialogStore.ts index bf80fa727..548827bcc 100644 --- a/src/stores/dialogStore.ts +++ b/src/stores/dialogStore.ts @@ -43,18 +43,13 @@ export const useDialogStore = defineStore('dialog', () => { } function closeDialog(options?: { key: string }) { - if (!options) { - dialogStack.value.pop() - return - } + const targetDialog = options + ? dialogStack.value.find((d) => d.key === options.key) + : dialogStack.value[0] + if (!targetDialog) return - const dialogKey = options.key - - const index = dialogStack.value.findIndex((d) => d.key === dialogKey) - if (index === -1) { - return - } - dialogStack.value.splice(index, 1) + targetDialog.dialogComponentProps?.onClose?.() + dialogStack.value.splice(dialogStack.value.indexOf(targetDialog), 1) } function createDialog(options: { @@ -93,7 +88,6 @@ export const useDialogStore = defineStore('dialog', () => { dialog.dialogComponentProps.maximized = false }, onAfterHide: () => { - options.dialogComponentProps?.onClose?.() closeDialog(dialog) }, pt: {