fix: 修复应用还没有安装完,按钮就重新变成可安装状态 (#11)

fix:先用比较简单的方案解决安装之后卸载了还是显示已安装的问题

fix: 在安装成功的ipc信息之后再删除安装队列的任务

删除pnpm workspace
This commit is contained in:
Delta1035
2026-02-04 13:06:01 +08:00
committed by GitHub
parent 53eb307f5c
commit b43c6117ec
6 changed files with 138 additions and 24 deletions

View File

@@ -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,
};
}

View File

@@ -11,13 +11,15 @@ export interface DownloadResult extends InstallLog {
exitCode: number | null;
}
export type DownloadItemStatus = 'downloading' | 'installing' | 'paused' | 'completed' | 'failed' | 'queued'; // 可根据实际状态扩展
export interface DownloadItem {
id: number;
name: string;
pkgname: string;
version: string;
icon: string;
status: 'downloading' | 'installing' | 'paused' | 'completed' | 'failed' | 'queued'; // 可根据实际状态扩展
status: DownloadItemStatus;
progress: number; // 0 ~ 100 的百分比,或 0 ~ 1 的小数(建议统一)
downloadedSize: number; // 已下载字节数
totalSize: number; // 总字节数(可能为 0 初始时)
@@ -107,4 +109,13 @@ export interface InstalledAppInfo {
arch: string;
flags: string;
raw: string;
}
}
/**
* ipcSender传递的信息
*/
export type ChannelPayload = {
success: boolean;
message: string;
[k: string]: unknown;
};