mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 09:20:18 +08:00
feat(app): add download count display
This commit is contained in:
@@ -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({
|
||||||
|
|||||||
@@ -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");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user