fix(web): show app version in sidebar instead of empty string

Inject __APP_VERSION__ from package.json via Vite define, read it in
WebPlatformAdapter.getVersion(), and call getVersion() on all platforms
(not just Electron) in Sidebar onMounted.
This commit is contained in:
digua committed 2026-05-18 22:43:00 +08:00
1 parent e5dc1fcb9b
commit 620ae40d45
3 files changed
+11 -7

No files matched your search

+6 -6
View File
@@ -71,13 +71,13 @@ let unlistenImportCompleted: (() => void) | null = null
onMounted(async () => {
sessionStore.loadSessions()
if (IS_ELECTRON) {
try {
version.value = await usePlatformService().getVersion()
} catch (e) {
console.error('Failed to get version', e)
}
try {
version.value = await usePlatformService().getVersion()
} catch (e) {
console.error('Failed to get version', e)
}
if (IS_ELECTRON) {
unlistenImportCompleted = window.apiServerApi.onImportCompleted(() => {
sessionStore.loadSessions()
})
+3 -1
View File
@@ -6,9 +6,11 @@
import type { PlatformAdapter, OpenDialogOptions, OpenDialogResult, RemoteConfigResult } from './types'
declare const __APP_VERSION__: string
export class WebPlatformAdapter implements PlatformAdapter {
async getVersion(): Promise<string> {
return 'web'
return typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : 'web'
}
async fetchRemoteConfig(url: string): Promise<RemoteConfigResult> {
+2
View File
@@ -11,6 +11,7 @@
*/
import { resolve } from 'path'
import { readFileSync } from 'fs'
import { spawn, type ChildProcess } from 'child_process'
import * as net from 'net'
import { defineConfig, type Plugin } from 'vite'
@@ -112,6 +113,7 @@ export default defineConfig({
define: {
__IS_ELECTRON__: JSON.stringify(false),
__IS_BROWSER_STANDALONE__: JSON.stringify(false),
__APP_VERSION__: JSON.stringify(JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8')).version),
},
plugins: [
vue(),