feat: support download statistics

close #15
This commit is contained in:
Elysia
2026-02-14 23:11:43 +08:00
parent c4ffc880e4
commit 5ac9376200
9 changed files with 99 additions and 45 deletions

View File

@@ -4,6 +4,9 @@ import type { App } from "./typedefinition";
export const APM_STORE_BASE_URL: string =
import.meta.env.VITE_APM_STORE_BASE_URL || "";
export const APM_STORE_STATS_BASE_URL: string =
import.meta.env.VITE_APM_STORE_STATS_BASE_URL || "";
// 下面的变量用于存储当前应用的信息,其实用在多个组件中
export const currentApp = ref<App | null>(null);
export const currentAppIsInstalled = ref(false);

View File

@@ -3,7 +3,11 @@
// })
import pino from "pino";
import { currentApp, currentAppIsInstalled } from "../global/storeConfig";
import {
APM_STORE_STATS_BASE_URL,
currentApp,
currentAppIsInstalled,
} from "../global/storeConfig";
import { APM_STORE_BASE_URL } from "../global/storeConfig";
import { downloads } from "../global/downloadStatus";
@@ -14,6 +18,7 @@ import {
App,
DownloadItemStatus,
} from "../global/typedefinition";
import axios from "axios";
let downloadIdCounter = 0;
const logger = pino({ name: "processInstall.ts" });
@@ -53,10 +58,27 @@ export const handleInstall = () => {
// Send to main process to start download
window.ipcRenderer.send("queue-install", JSON.stringify(download));
// const encodedPkg = encodeURIComponent(currentApp.value.Pkgname);
// openApmStoreUrl(`apmstore://install?pkg=${encodedPkg}`, {
// fallbackText: `/usr/bin/apm-installer --install ${currentApp.value.Pkgname}`
// });
// Send download statistics to server
logger.info("发送下载次数统计...");
const axiosInstance = axios.create({
baseURL: APM_STORE_STATS_BASE_URL,
timeout: 5000, // 增加到 5 秒,避免网络波动导致的超时
});
axiosInstance
.post(
"/handle_post",
{
path: `${window.apm_store.arch}/${currentApp.value.category}/${currentApp.value.pkgname}`,
},
{
headers: {
"Content-Type": "application/json",
},
}
)
.then((response) => {
logger.info("下载次数统计已发送,状态:", response.data);
});
};
export const handleRetry = (download_: DownloadItem) => {
@@ -124,7 +146,7 @@ window.ipcRenderer.on(
if (downloadObj) {
downloadObj.progress = payload.progress;
}
},
}
);
window.ipcRenderer.on("install-log", (_event, log: InstallLog) => {

2
src/vite-env.d.ts vendored
View File

@@ -12,3 +12,5 @@ interface Window {
ipcRenderer: import("electron").IpcRenderer;
apm_store: any;
}
declare const __APP_VERSION__: string;