diff --git a/electron/main/index.ts b/electron/main/index.ts index 39722ead..c44fc5d6 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -105,6 +105,8 @@ ipcMain.handle("get-store-filter", (): "spark" | "apm" | "both" => getStoreFilterFromArgv(), ); +ipcMain.handle("get-app-version", (): string => getAppVersion()); + async function createWindow() { win = new BrowserWindow({ title: "星火应用商店", diff --git a/electron/preload/index.ts b/electron/preload/index.ts index ef9543a0..aab78e57 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -36,15 +36,6 @@ contextBridge.exposeInMainWorld("apm_store", { return arch; } })(), - version: (() => { - // 从 package.json 读取版本号 - try { - const pkg = require("../../package.json"); - return pkg.version || "unknown"; - } catch { - return "unknown"; - } - })(), }); // --------- Preload scripts loading --------- diff --git a/src/components/AboutModal.vue b/src/components/AboutModal.vue index ca6a207b..6069a31f 100644 --- a/src/components/AboutModal.vue +++ b/src/components/AboutModal.vue @@ -111,11 +111,15 @@ const emit = defineEmits<{ const version = ref("unknown"); -onMounted(() => { - // 从预加载脚本获取版本号 - const apmStore = (window as any).apm_store; - if (apmStore?.version) { - version.value = apmStore.version; +onMounted(async () => { + // 通过 IPC 从主进程获取版本号 + try { + const appVersion = await window.ipcRenderer.invoke("get-app-version"); + if (appVersion) { + version.value = appVersion; + } + } catch { + version.value = "unknown"; } }); diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 043c1114..8a2c9c82 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -15,4 +15,9 @@ interface Window { }; } +// IPC channel type definitions +declare interface IpcChannels { + "get-app-version": () => string; +} + declare const __APP_VERSION__: string;