feat(updater): support ignoring a specific version

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-08-11 21:39:44 +08:00
1 parent c6f9ddb5a4
commit 967084c498
16 files changed
+439 -14

No files matched your search

+31 -1
View File
@@ -20,6 +20,7 @@ interface DialogState {
updateDownloaded: boolean;
isInstallingUpdate: boolean;
updateReady: boolean;
isIgnoringUpdate: boolean;
}
async function flushDialog() {
@@ -37,10 +38,12 @@ async function mountDialog(activeTaskCount: number, initialState: Partial<Dialog
updateDownloaded: false,
isInstallingUpdate: false,
updateReady: false,
isIgnoringUpdate: false,
...initialState,
});
const downloadAndInstall = vi.fn();
const cancelDownload = vi.fn();
const ignoreVersion = vi.fn();
const container = document.createElement("div");
document.body.append(container);
const app = createApp(
@@ -81,10 +84,12 @@ async function mountDialog(activeTaskCount: number, initialState: Partial<Dialog
updateDownloaded: state.updateDownloaded,
isInstallingUpdate: state.isInstallingUpdate,
updateReady: state.updateReady,
isIgnoringUpdate: state.isIgnoringUpdate,
activeTaskCount,
"onDownload-and-install": downloadAndInstall,
"onCancel-download": cancelDownload,
"onInstall-downloaded": handleInstallDownloaded,
"onIgnore-version": ignoreVersion,
});
},
}),
@@ -94,7 +99,7 @@ async function mountDialog(activeTaskCount: number, initialState: Partial<Dialog
app.mount(container);
await flushDialog();
return { state, downloadAndInstall, cancelDownload, installDownloaded };
return { state, downloadAndInstall, cancelDownload, installDownloaded, ignoreVersion };
}
function buttonWithText(text: string): HTMLButtonElement | undefined {
@@ -275,3 +280,28 @@ describe("UpdateDialog close protection", () => {
expect(downloadAndInstall).not.toHaveBeenCalled();
});
});
describe("UpdateDialog ignore version", () => {
it("emits ignore-version when the ignore button is clicked", async () => {
const { ignoreVersion } = await mountDialog(0);
const ignoreButton = buttonWithText("Ignore this version");
expect(ignoreButton).toBeDefined();
ignoreButton?.click();
await flushDialog();
expect(ignoreVersion).toHaveBeenCalledOnce();
});
it("hides the ignore button once an update has been downloaded", async () => {
await mountDialog(0, { updateDownloaded: true, downloadProgress: 100 });
expect(buttonWithText("Ignore this version")).toBeUndefined();
});
it("disables the ignore button while the setting is being persisted", async () => {
await mountDialog(0, { isIgnoringUpdate: true });
expect(buttonWithText("Ignore this version")?.disabled).toBe(true);
});
});
@@ -18,6 +18,7 @@ const props = defineProps<{
updateDownloaded: boolean;
isInstallingUpdate: boolean;
updateReady: boolean;
isIgnoringUpdate: boolean;
activeTaskCount: number;
}>();
@@ -27,6 +28,7 @@ const emit = defineEmits<{
"cancel-download": [];
"install-downloaded": [];
restart: [];
"ignore-version": [];
}>();
const { t } = useI18n();
@@ -35,6 +37,7 @@ const isDesktop = isTauriRuntime();
const renderedNotes = ref("");
// Only active file replacement (installation) must trap the dialog.
const isCloseBlocked = computed(() => props.isInstallingUpdate);
const canIgnoreVersion = computed(() => props.updateInfo?.update_available === true && !props.updateDownloaded && !props.isDownloadingUpdate && !props.isInstallingUpdate && !props.updateReady);
function handleCancel() {
handleOpenChange(false);
@@ -136,6 +139,10 @@ watch(
</div>
<DialogFooter>
<Button v-if="!isCloseBlocked" variant="outline" @click="handleCancel">{{ t("dangerDialog.cancel") }}</Button>
<Button v-if="canIgnoreVersion" variant="ghost" :disabled="isIgnoringUpdate" @click="emit('ignore-version')">
<Loader2 v-if="isIgnoringUpdate" class="h-4 w-4 animate-spin" />
{{ t("updates.ignoreVersion") }}
</Button>
<template v-if="updateInfo?.update_available">
<Button variant="outline" @click="emit('open-latest-release')">{{ t("updates.openRelease") }}</Button>
<template v-if="canDownloadAndInstallUpdate(updateInfo, isDesktop)">