앱 버전표시
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { isDesktop } from '../utils/platform';
|
||||
import { getDesktopAppVersion, syncDesktopMainWindowTitle } from '../utils/desktopBridge';
|
||||
|
||||
declare const __DESKTOP_APP_VERSION__: string | undefined;
|
||||
|
||||
function readBakedDesktopVersion(): string | null {
|
||||
if (typeof __DESKTOP_APP_VERSION__ === 'undefined') return null;
|
||||
const v = __DESKTOP_APP_VERSION__.trim();
|
||||
return v || null;
|
||||
}
|
||||
|
||||
/** Desktop — 네이티브 창 타이틀·document.title을 GoldenChart (vX.Y.Z) 로 맞춤 */
|
||||
export function useDesktopAppTitle(): string | null {
|
||||
const [version, setVersion] = useState<string | null>(() =>
|
||||
isDesktop() ? readBakedDesktopVersion() : null,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isDesktop()) return;
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
const v = (await getDesktopAppVersion()) ?? readBakedDesktopVersion();
|
||||
if (cancelled || !v) return;
|
||||
setVersion(v);
|
||||
await syncDesktopMainWindowTitle();
|
||||
})();
|
||||
return () => { cancelled = true; };
|
||||
}, []);
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
export function formatDesktopAppLabel(version: string | null | undefined): string {
|
||||
if (!version?.trim()) return 'GoldenChart';
|
||||
return `GoldenChart (v${version.trim()})`;
|
||||
}
|
||||
Reference in New Issue
Block a user