mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-08-10 06:14:07 +08:00
修复更新中心发送的下载项和普通下载故障覆盖的问题
This commit is contained in:
@@ -3,6 +3,34 @@ import type { DownloadItem, DownloadItemStatus } from "./typedefinition";
|
||||
|
||||
export const downloads = ref<DownloadItem[]>([]);
|
||||
|
||||
let nextDownloadId = 1;
|
||||
|
||||
export function getNextDownloadId(): number {
|
||||
if (downloads.value.length > 0) {
|
||||
nextDownloadId = Math.max(
|
||||
nextDownloadId,
|
||||
Math.max(...downloads.value.map((item) => item.id)) + 1,
|
||||
);
|
||||
}
|
||||
|
||||
const downloadId = nextDownloadId;
|
||||
nextDownloadId += 1;
|
||||
|
||||
return downloadId;
|
||||
}
|
||||
|
||||
export function getNextUpdateDownloadId(): number {
|
||||
const negativeIds = downloads.value
|
||||
.map((item) => item.id)
|
||||
.filter((id) => id < 0);
|
||||
|
||||
if (negativeIds.length === 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return Math.min(...negativeIds) - 1;
|
||||
}
|
||||
|
||||
export function removeDownloadItem(pkgname: string) {
|
||||
const list = downloads.value;
|
||||
for (let i = list.length - 1; i >= 0; i -= 1) {
|
||||
|
||||
@@ -165,6 +165,11 @@ export interface UpdateCenterTaskState {
|
||||
errorMessage: string;
|
||||
}
|
||||
|
||||
export interface UpdateCenterStartTask {
|
||||
taskKey: string;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export interface UpdateCenterSnapshot {
|
||||
items: UpdateCenterItem[];
|
||||
tasks: UpdateCenterTaskState[];
|
||||
@@ -183,7 +188,7 @@ export interface UpdateCenterBridge {
|
||||
packageName: string;
|
||||
newVersion: string;
|
||||
}) => Promise<void>;
|
||||
start: (taskKeys: string[]) => Promise<void>;
|
||||
start: (tasks: UpdateCenterStartTask[]) => Promise<void>;
|
||||
cancel: (taskKey: string) => Promise<void>;
|
||||
getState: () => Promise<UpdateCenterSnapshot>;
|
||||
onState: (listener: (snapshot: UpdateCenterSnapshot) => void) => void;
|
||||
|
||||
Reference in New Issue
Block a user