From 60628ff1fa60cd5e435f6e8669eb93e273219321 Mon Sep 17 00:00:00 2001 From: momen Date: Sun, 12 Apr 2026 19:11:11 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=94=AF=E6=8C=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=97=B6=E5=B1=95=E7=A4=BA=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unit/update-center/store.test.ts | 30 +++++++++++++++++++ src/modules/updateCenter.ts | 25 ++++++++++++---- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/__tests__/unit/update-center/store.test.ts b/src/__tests__/unit/update-center/store.test.ts index 519912ef..873aefda 100644 --- a/src/__tests__/unit/update-center/store.test.ts +++ b/src/__tests__/unit/update-center/store.test.ts @@ -1,6 +1,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import { createUpdateCenterStore } from "@/modules/updateCenter"; +import { downloads } from "@/global/downloadStatus"; const createSnapshot = (overrides = {}) => ({ items: [ @@ -33,6 +34,7 @@ describe("updateCenter store", () => { start.mockReset(); onState.mockReset(); offState.mockReset(); + downloads.value = []; Object.defineProperty(window, "updateCenter", { configurable: true, @@ -97,6 +99,34 @@ describe("updateCenter store", () => { expect(start).toHaveBeenCalledWith(["aptss:spark-weather"]); }); + it("uses remoteIcon when adding update tasks to the download queue", async () => { + const snapshot = createSnapshot({ + items: [ + { + taskKey: "aptss:spark-weather", + packageName: "spark-weather", + displayName: "Spark Weather", + currentVersion: "1.0.0", + newVersion: "2.0.0", + source: "aptss" as const, + ignored: false, + remoteIcon: "https://example.com/icons/spark-weather.png", + }, + ], + }); + open.mockResolvedValue(snapshot); + const store = createUpdateCenterStore(); + + await store.open(); + store.toggleSelection("aptss:spark-weather"); + await store.startSelected(); + + expect(downloads.value).toHaveLength(1); + expect(downloads.value[0]?.icon).toBe( + "https://example.com/icons/spark-weather.png", + ); + }); + it("blocks close requests while the snapshot reports running tasks", () => { const store = createUpdateCenterStore(); store.isOpen.value = true; diff --git a/src/modules/updateCenter.ts b/src/modules/updateCenter.ts index 14e0b3a4..ba129bff 100644 --- a/src/modules/updateCenter.ts +++ b/src/modules/updateCenter.ts @@ -155,18 +155,31 @@ export const createUpdateCenterStore = (): UpdateCenterStore => { // 在前端创建下载项,这样用户能在下载列表中看到更新任务 const arch = window.apm_store.arch || "amd64"; - let downloadIdCounter = downloads.value.length > 0 ? Math.max(...downloads.value.map(d => d.id)) + 1 : 1; + let downloadIdCounter = + downloads.value.length > 0 + ? Math.max(...downloads.value.map((d) => d.id)) + 1 + : 1; selectedItems.forEach((item) => { // 检查任务是否已存在 - if (!downloads.value.find(d => d.pkgname === item.packageName && d.origin === (item.source === "apm" ? "apm" : "spark"))) { - const finalArch = item.source === "apm" ? `${arch}-apm` : `${arch}-store`; + if ( + !downloads.value.find( + (d) => + d.pkgname === item.packageName && + d.origin === (item.source === "apm" ? "apm" : "spark"), + ) + ) { + const finalArch = + item.source === "apm" ? `${arch}-apm` : `${arch}-store`; + const icon = + item.remoteIcon || + `${APM_STORE_BASE_URL}/${finalArch}/unknown/${item.packageName}/icon.png`; const download: DownloadItem = { id: downloadIdCounter++, name: item.displayName, pkgname: item.packageName, version: item.newVersion, - icon: `${APM_STORE_BASE_URL}/${finalArch}/unknown/${item.packageName}/icon.png`, + icon, origin: item.source === "apm" ? "apm" : "spark", status: "queued", progress: 0, @@ -180,7 +193,9 @@ export const createUpdateCenterStore = (): UpdateCenterStore => { retry: false, upgradeOnly: true, filename: item.fileName, - metalinkUrl: item.downloadUrl ? `${item.downloadUrl}.metalink` : undefined, + metalinkUrl: item.downloadUrl + ? `${item.downloadUrl}.metalink` + : undefined, }; downloads.value.push(download); }