diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue index d3842874ca..d6c8e220ba 100644 --- a/apps/desktop/src/App.vue +++ b/apps/desktop/src/App.vue @@ -152,6 +152,7 @@ const { checkUpdates, openLatestRelease, downloadAndInstallUpdate, + cancelDownload, installDownloadedUpdate, restartApp, } = useAppUpdater({ @@ -2518,6 +2519,7 @@ onUnmounted(() => { :active-task-count="activeUpdateTaskCount" @open-latest-release="openLatestRelease" @download-and-install="downloadAndInstallUpdate" + @cancel-download="cancelDownload" @install-downloaded="installDownloadedUpdate" @restart="restartApp" /> diff --git a/apps/desktop/src/components/layout/UpdateDialog.spec.ts b/apps/desktop/src/components/layout/UpdateDialog.spec.ts index 00b7c70835..f8a0d8c5c9 100644 --- a/apps/desktop/src/components/layout/UpdateDialog.spec.ts +++ b/apps/desktop/src/components/layout/UpdateDialog.spec.ts @@ -40,6 +40,7 @@ async function mountDialog(activeTaskCount: number, initialState: Partial { }); describe("UpdateDialog close protection", () => { + it("cancels the background download when the close button is clicked", async () => { + const { state, cancelDownload } = await mountDialog(0, { isDownloadingUpdate: true, downloadProgress: 42 }); + + const closeButton = document.body.querySelector('[data-slot="dialog-close"]'); + closeButton?.click(); + await flushDialog(); + + expect(cancelDownload).toHaveBeenCalledOnce(); + expect(state.open).toBe(false); + }); + it("allows closing while a downloaded update is idle", async () => { const { state } = await mountDialog(0, { updateDownloaded: true, downloadProgress: 100 }); @@ -232,7 +245,7 @@ describe("UpdateDialog close protection", () => { expect(downloadAndInstall).not.toHaveBeenCalled(); }); - it("keeps the successful install flow protected", async () => { + it("allows dismissing after a successful install while restart remains available", async () => { const installDownloaded = vi.fn(async () => {}); const { state, downloadAndInstall } = await mountDialog(0, { updateDownloaded: true }, installDownloaded); @@ -242,9 +255,9 @@ describe("UpdateDialog close protection", () => { expect(state.updateDownloaded).toBe(false); expect(state.updateReady).toBe(true); expect(buttonWithText("Restart")).toBeDefined(); - expect(buttonWithText("Cancel")).toBeUndefined(); + expect(buttonWithText("Cancel")).toBeDefined(); await pressEscape(); - expect(state.open).toBe(true); + expect(state.open).toBe(false); expect(installDownloaded).toHaveBeenCalledOnce(); expect(downloadAndInstall).not.toHaveBeenCalled(); }); diff --git a/apps/desktop/src/components/layout/UpdateDialog.vue b/apps/desktop/src/components/layout/UpdateDialog.vue index df17264530..3c547cb9ab 100644 --- a/apps/desktop/src/components/layout/UpdateDialog.vue +++ b/apps/desktop/src/components/layout/UpdateDialog.vue @@ -24,6 +24,7 @@ const props = defineProps<{ const emit = defineEmits<{ "open-latest-release": []; "download-and-install": []; + "cancel-download": []; "install-downloaded": []; restart: []; }>(); @@ -32,8 +33,24 @@ const { t } = useI18n(); const isDesktop = isTauriRuntime(); const renderedNotes = ref(""); -// Keep a downloaded package retryable after install errors; only active transitions must trap the dialog. -const isCloseBlocked = computed(() => props.isDownloadingUpdate || props.isInstallingUpdate || props.updateReady); +// Only active file replacement (installation) must trap the dialog. +const isCloseBlocked = computed(() => props.isInstallingUpdate); + +function handleCancel() { + handleOpenChange(false); +} + +function handleOpenChange(nextOpen: boolean) { + if (nextOpen) { + open.value = true; + return; + } + if (isCloseBlocked.value) return; + if (props.isDownloadingUpdate) { + emit("cancel-download"); + } + open.value = false; +} function handleReleaseNotesClick(event: MouseEvent) { const target = event.target as HTMLElement; @@ -65,7 +82,7 @@ watch(