앱 버전표시

This commit is contained in:
Macbook
2026-06-14 19:20:48 +09:00
parent b2c6650cd5
commit 5045a548a4
10 changed files with 137 additions and 31 deletions
+37 -9
View File
@@ -1,32 +1,60 @@
import { getVersion } from '@tauri-apps/api/app';
import { getCurrentWindow } from '@tauri-apps/api/window';
import {
formatDesktopWindowTitle,
readBakedDesktopAppVersion,
} from '@frontend/utils/desktopAppVersion';
const APP_NAME = 'GoldenChart';
export function formatDesktopWindowTitle(version: string): string {
const v = version.trim();
return v ? `${APP_NAME} (v${v})` : APP_NAME;
}
export { formatDesktopWindowTitle } from '@frontend/utils/desktopAppVersion';
/** macOS/Windows 네이티브 창 타이틀 — GoldenChart (vX.Y.Z) */
export async function syncMainWindowTitle(): Promise<string> {
try {
const version = await getVersion();
const version = (await getVersion()) || readBakedDesktopAppVersion() || '';
const title = formatDesktopWindowTitle(version);
await getCurrentWindow().setTitle(title);
if (typeof document !== 'undefined') {
if (typeof document !== 'undefined' && document.title !== title) {
document.title = title;
}
return title;
} catch (e) {
const fallback = formatDesktopWindowTitle(readBakedDesktopAppVersion());
if (typeof document !== 'undefined') {
document.title = fallback;
}
console.warn('[desktop] syncMainWindowTitle failed:', e);
throw e;
}
}
let titleGuardInstalled = false;
/** macOS WebKit — document.title 변경 시 네이티브 타이틀을 다시 맞춤 */
export function installDocumentTitleGuard(): void {
if (titleGuardInstalled || typeof document === 'undefined') return;
titleGuardInstalled = true;
const rebalance = () => {
void syncMainWindowTitle().catch(() => {});
};
const titleEl = document.querySelector('title');
if (titleEl) {
const observer = new MutationObserver(() => {
if (!document.title.includes('(v')) rebalance();
});
observer.observe(titleEl, { childList: true, characterData: true, subtree: true });
}
window.setInterval(() => {
if (!document.title.includes('(v')) rebalance();
}, 3000);
}
/** WebView 로드 후 macOS가 document.title로 타이틀을 덮어쓸 수 있어 재시도 */
export function scheduleMainWindowTitleSync(): void {
const delays = [0, 150, 600, 2000];
installDocumentTitleGuard();
const delays = [0, 50, 150, 400, 1000, 2500, 5000];
for (const ms of delays) {
window.setTimeout(() => {
void syncMainWindowTitle().catch(() => {});