feat(app): add download count display

This commit is contained in:
Elysia
2026-02-14 23:22:41 +08:00
parent 5ac9376200
commit a3f18bb593
4 changed files with 33 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ import {
shell, shell,
Tray, Tray,
nativeTheme, nativeTheme,
session session,
} from "electron"; } from "electron";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
import path from "node:path"; import path from "node:path";
@@ -62,7 +62,7 @@ if (!app.requestSingleInstanceLock()) {
let win: BrowserWindow | null = null; let win: BrowserWindow | null = null;
const preload = path.join(__dirname, "../preload/index.mjs"); const preload = path.join(__dirname, "../preload/index.mjs");
const indexHtml = path.join(RENDERER_DIST, "index.html"); const indexHtml = path.join(RENDERER_DIST, "index.html");
const userAgent = `APM-Store/${JSON.stringify(process.env.npm_package_version)}` const userAgent = `APM-Store/${JSON.stringify(process.env.npm_package_version)}`;
async function createWindow() { async function createWindow() {
win = new BrowserWindow({ win = new BrowserWindow({

View File

@@ -37,6 +37,7 @@
</div> </div>
<p class="text-sm text-slate-500 dark:text-slate-400"> <p class="text-sm text-slate-500 dark:text-slate-400">
{{ app?.pkgname || "" }} · {{ app?.version || "" }} {{ app?.pkgname || "" }} · {{ app?.version || "" }}
<span v-if="downloadCount"> · 下载量{{ downloadCount }}</span>
</p> </p>
</div> </div>
</div> </div>
@@ -199,7 +200,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, useAttrs } from "vue"; import { computed, useAttrs, ref, watch } from "vue";
import axios from "axios";
import { import {
useDownloadItemStatus, useDownloadItemStatus,
useInstallFeedback, useInstallFeedback,
@@ -255,6 +257,31 @@ const iconPath = computed(() => {
return `${APM_STORE_BASE_URL}/${window.apm_store.arch}/${props.app.category}/${props.app.pkgname}/icon.png`; return `${APM_STORE_BASE_URL}/${window.apm_store.arch}/${props.app.category}/${props.app.pkgname}/icon.png`;
}); });
const downloadCount = ref<string>("");
// 监听 app 变化获取新app的下载量
watch(
() => props.app,
async (newApp) => {
if (newApp) {
downloadCount.value = "";
try {
const url = `${APM_STORE_BASE_URL}/${window.apm_store.arch}/${newApp.category}/${newApp.pkgname}/download-times.txt`;
const resp = await axios.get(url, { responseType: "text" });
if (resp.status === 200) {
downloadCount.value = String(resp.data).trim();
} else {
downloadCount.value = "N/A";
throw new Error(`Unexpected response status: ${resp.status}`);
}
} catch (e) {
console.error("Failed to fetch download count", e);
}
}
},
{ immediate: true },
);
const closeModal = () => { const closeModal = () => {
emit("close"); emit("close");
}; };

View File

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

View File

@@ -74,7 +74,7 @@ export const handleInstall = () => {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} },
) )
.then((response) => { .then((response) => {
logger.info("下载次数统计已发送,状态:", response.data); logger.info("下载次数统计已发送,状态:", response.data);
@@ -146,7 +146,7 @@ window.ipcRenderer.on(
if (downloadObj) { if (downloadObj) {
downloadObj.progress = payload.progress; downloadObj.progress = payload.progress;
} }
} },
); );
window.ipcRenderer.on("install-log", (_event, log: InstallLog) => { window.ipcRenderer.on("install-log", (_event, log: InstallLog) => {