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,
Tray,
nativeTheme,
session
session,
} from "electron";
import { fileURLToPath } from "node:url";
import path from "node:path";
@@ -62,7 +62,7 @@ if (!app.requestSingleInstanceLock()) {
let win: BrowserWindow | null = null;
const preload = path.join(__dirname, "../preload/index.mjs");
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() {
win = new BrowserWindow({

View File

@@ -37,6 +37,7 @@
</div>
<p class="text-sm text-slate-500 dark:text-slate-400">
{{ app?.pkgname || "" }} · {{ app?.version || "" }}
<span v-if="downloadCount"> · 下载量{{ downloadCount }}</span>
</p>
</div>
</div>
@@ -199,7 +200,8 @@
</template>
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { computed, useAttrs, ref, watch } from "vue";
import axios from "axios";
import {
useDownloadItemStatus,
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`;
});
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 = () => {
emit("close");
};

View File

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