mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 09:20:18 +08:00
feat: 通过 IPC 实现应用版本号获取功能
移除预加载脚本中的版本号获取逻辑,改为通过 IPC 从主进程获取
This commit is contained in:
@@ -105,6 +105,8 @@ ipcMain.handle("get-store-filter", (): "spark" | "apm" | "both" =>
|
|||||||
getStoreFilterFromArgv(),
|
getStoreFilterFromArgv(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ipcMain.handle("get-app-version", (): string => getAppVersion());
|
||||||
|
|
||||||
async function createWindow() {
|
async function createWindow() {
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
title: "星火应用商店",
|
title: "星火应用商店",
|
||||||
|
|||||||
@@ -36,15 +36,6 @@ contextBridge.exposeInMainWorld("apm_store", {
|
|||||||
return arch;
|
return arch;
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
version: (() => {
|
|
||||||
// 从 package.json 读取版本号
|
|
||||||
try {
|
|
||||||
const pkg = require("../../package.json");
|
|
||||||
return pkg.version || "unknown";
|
|
||||||
} catch {
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
})(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// --------- Preload scripts loading ---------
|
// --------- Preload scripts loading ---------
|
||||||
|
|||||||
@@ -111,11 +111,15 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const version = ref("unknown");
|
const version = ref("unknown");
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
// 从预加载脚本获取版本号
|
// 通过 IPC 从主进程获取版本号
|
||||||
const apmStore = (window as any).apm_store;
|
try {
|
||||||
if (apmStore?.version) {
|
const appVersion = await window.ipcRenderer.invoke("get-app-version");
|
||||||
version.value = apmStore.version;
|
if (appVersion) {
|
||||||
|
version.value = appVersion;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
version.value = "unknown";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
5
src/vite-env.d.ts
vendored
5
src/vite-env.d.ts
vendored
@@ -15,4 +15,9 @@ interface Window {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IPC channel type definitions
|
||||||
|
declare interface IpcChannels {
|
||||||
|
"get-app-version": () => string;
|
||||||
|
}
|
||||||
|
|
||||||
declare const __APP_VERSION__: string;
|
declare const __APP_VERSION__: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user