mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-08-10 06:14:07 +08:00
fix: 修复应用还没有安装完,按钮就重新变成可安装状态 (#11)
fix:先用比较简单的方案解决安装之后卸载了还是显示已安装的问题 fix: 在安装成功的ipc信息之后再删除安装队列的任务 删除pnpm workspace
This commit is contained in:
@@ -1,4 +1,78 @@
|
||||
import { ref } from "vue";
|
||||
import type { DownloadItem } from './typedefinition';
|
||||
import { computed,ComputedRef,ref,unref,watch } from "vue";
|
||||
import type { DownloadItem,DownloadItemStatus } from "./typedefinition";
|
||||
|
||||
export const downloads = ref<DownloadItem[]>([]);
|
||||
|
||||
export function removeDownloadItem(pkgname:string) {
|
||||
const list = downloads.value;
|
||||
for (let i = list.length - 1; i >= 0; i -= 1) {
|
||||
if (list[i].pkgname === pkgname) {
|
||||
list.splice(i,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function watchDownloadsChange (cb: () => void) {
|
||||
const statusById = new Map<number,DownloadItemStatus>();
|
||||
|
||||
for (const item of downloads.value) {
|
||||
statusById.set(item.id,item.status);
|
||||
}
|
||||
|
||||
watch(
|
||||
downloads,
|
||||
(list) => {
|
||||
for (const item of list) {
|
||||
const prevStatus = statusById.get(item.id);
|
||||
if (item.status === "completed" && prevStatus !== "completed") {
|
||||
cb();
|
||||
}
|
||||
statusById.set(item.id,item.status);
|
||||
}
|
||||
|
||||
if (statusById.size > list.length) {
|
||||
const liveIds = new Set<number>();
|
||||
for (const item of list) liveIds.add(item.id);
|
||||
for (const id of statusById.keys()) {
|
||||
if (!liveIds.has(id)) statusById.delete(id);
|
||||
}
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
}
|
||||
|
||||
export function useDownloadItemStatus (
|
||||
pkgname?: ComputedRef<string | undefined>,
|
||||
) {
|
||||
const status: ComputedRef<DownloadItemStatus | undefined> = computed(() => {
|
||||
const name = unref(pkgname);
|
||||
if (!name) return;
|
||||
const task = downloads.value.find((d) => d.pkgname === name);
|
||||
if (!task) return;
|
||||
return task.status;
|
||||
});
|
||||
|
||||
const isCompleted = computed(() => {
|
||||
return status.value === "completed";
|
||||
});
|
||||
|
||||
return {
|
||||
status,
|
||||
isCompleted,
|
||||
};
|
||||
}
|
||||
|
||||
export function useInstallFeedback (pkgname?: ComputedRef<string | undefined>) {
|
||||
const installFeedback = computed(() => {
|
||||
const name = unref(pkgname);
|
||||
if (!name) return false;
|
||||
const task = downloads.value.find((d) => d.pkgname === name);
|
||||
if (!task) return false;
|
||||
return task.status !== "completed" && task.status !== "failed";
|
||||
});
|
||||
|
||||
return {
|
||||
installFeedback,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user