diff --git a/src/app/features/settings/about/About.tsx b/src/app/features/settings/about/About.tsx index 082317d37..f3535d83e 100644 --- a/src/app/features/settings/about/About.tsx +++ b/src/app/features/settings/about/About.tsx @@ -8,6 +8,7 @@ import { getOriginBaseUrl, withOriginBaseUrl } from '../../../pages/pathUtils'; import pkg from '../../../../../package.json'; import { clearCacheAndReload } from '../../../../client/initMatrix'; import { useMatrixClient } from '../../../hooks/useMatrixClient'; +import { tauriInvoke } from '../../../hooks/useTauri'; const LotusLogo = withOriginBaseUrl(getOriginBaseUrl(), '/public/res/lotus-logo.png'); @@ -78,6 +79,51 @@ function useServerSupport(): { support: MSC1929Support | null; loading: boolean type AboutProps = { requestClose: () => void; }; +/** + * [Gitea #276] Which build someone is on: the web deploy's commit and build + * date (stamped in by vite.config.js), plus the desktop app's own version from + * Tauri, the number a desktop or updater bug report needs. + */ +function BuildInfo() { + const [desktopVersion, setDesktopVersion] = useState(); + useEffect(() => { + tauriInvoke()?.('plugin:app|version') + .then((v) => { + if (typeof v === 'string') setDesktopVersion(v); + }) + .catch(() => undefined); + }, []); + const commit = __LOTUS_BUILD_COMMIT__; + const built = new Date(__LOTUS_BUILD_DATE__); + const builtText = Number.isNaN(built.getTime()) + ? undefined + : built.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' }); + return ( + + {desktopVersion && ( + + Desktop {desktopVersion} + + )} + + Web build{' '} + {commit !== 'unknown' ? ( + + {commit} + + ) : ( + commit + )} + {builtText && ` · built ${builtText}`} + + + ); +} + export function About({ requestClose }: AboutProps) { const mx = useMatrixClient(); const { support: serverSupport, loading: supportLoading } = useServerSupport(); @@ -117,6 +163,7 @@ export function About({ requestClose }: AboutProps) { v{pkg.version} A Matrix client for Lotus Guild. + diff --git a/src/ext.d.ts b/src/ext.d.ts index 844a21747..6db433e1d 100644 --- a/src/ext.d.ts +++ b/src/ext.d.ts @@ -1,5 +1,9 @@ /// +// [Gitea #276] Set by vite.config.js `define`. +declare const __LOTUS_BUILD_COMMIT__: string; +declare const __LOTUS_BUILD_DATE__: string; + declare module 'browser-encrypt-attachment' { export interface EncryptedAttachmentInfo { v: string; diff --git a/vite.config.js b/vite.config.js index 1aaf5c5f6..739304f0e 100644 --- a/vite.config.js +++ b/vite.config.js @@ -6,6 +6,7 @@ import { viteStaticCopy } from 'vite-plugin-static-copy'; import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin'; import { VitePWA } from 'vite-plugin-pwa'; import fs from 'fs'; +import { execSync } from 'child_process'; import path from 'path'; import buildConfig from './build.config'; @@ -272,8 +273,26 @@ const vendorChunks = (id) => { if (id.includes('node_modules/chroma-js')) return 'chroma'; }; +// [Gitea #276] Which build is this? The short commit and build time are shown +// in Settings → About (web deploys change many times a day while the package +// version stays the same). LOTUS_BUILD_COMMIT overrides; no git → "unknown". +const buildCommit = (() => { + if (process.env.LOTUS_BUILD_COMMIT) return process.env.LOTUS_BUILD_COMMIT.slice(0, 12); + try { + return execSync('git rev-parse --short=8 HEAD', { stdio: ['ignore', 'pipe', 'ignore'] }) + .toString() + .trim(); + } catch { + return 'unknown'; + } +})(); + export default defineConfig({ appType: 'spa', + define: { + __LOTUS_BUILD_COMMIT__: JSON.stringify(buildCommit), + __LOTUS_BUILD_DATE__: JSON.stringify(new Date().toISOString()), + }, publicDir: false, base: buildConfig.base, server: {