M5: 포터블 exe 앱 (트레이·설정 창·첫 실행 마법사) + M6 사전 기능
- app/src/main: Electron 메인(트레이 상태 아이콘, 설정 창, 단일 실행, DPAPI safeStorage, 스모크 모드), IPC(window.gvr), 파인튜닝 관리 - app/src/renderer: 설정 8개 탭 + 5단계 첫 실행 마법사 (React) - electron-builder: GameVoiceRecorder.exe, zip(폴더 포터블) + 단일 exe 포터블, 워커·리소스 포함 - 사전: 사이트에서 단어·교정 규칙 추가/삭제(/api/dictionary), 게임 패치 이름 자동 추가, 묶음별 중복 허용 + DB 마이그레이션 - 사이트 서버: 종료 시 WebSocket 먼저 끊기(재시작 멈춤 수정) + 재연결 테스트 - scripts/finetune-e2e.mts, stt-eval.mts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
64
app/src/renderer/util.ts
Normal file
64
app/src/renderer/util.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
// 렌더러 공용 유틸 (포맷 · 병합)
|
||||
|
||||
export function deepMerge<T>(base: T, over: unknown): T {
|
||||
if (over === undefined || over === null || typeof base !== 'object' || base === null || Array.isArray(base)) {
|
||||
return (over ?? base) as T;
|
||||
}
|
||||
const out: Record<string, unknown> = { ...(base as Record<string, unknown>) };
|
||||
for (const [k, v] of Object.entries(over as Record<string, unknown>)) {
|
||||
const b = out[k];
|
||||
out[k] = b && typeof b === 'object' && !Array.isArray(b) ? deepMerge(b, v) : v;
|
||||
}
|
||||
return out as T;
|
||||
}
|
||||
|
||||
export function errMsg(e: unknown): string {
|
||||
if (e instanceof Error) return e.message;
|
||||
return String(e);
|
||||
}
|
||||
|
||||
/** MB → "1.6GB" / "464MB" */
|
||||
export function fmtMb(mb: number, digits = 1): string {
|
||||
if (mb >= 1000) return `${(mb / 1024).toFixed(digits)}GB`;
|
||||
return `${Math.round(mb)}MB`;
|
||||
}
|
||||
|
||||
export function fmtBytes(b: number | null | undefined): string {
|
||||
if (b === null || b === undefined) return '-';
|
||||
if (b >= 1024 ** 3) return `${(b / 1024 ** 3).toFixed(1)}GB`;
|
||||
if (b >= 1024 ** 2) return `${(b / 1024 ** 2).toFixed(0)}MB`;
|
||||
if (b >= 1024) return `${(b / 1024).toFixed(0)}KB`;
|
||||
return `${b}B`;
|
||||
}
|
||||
|
||||
export function fmtEta(sec: number | undefined): string {
|
||||
if (sec === undefined || !isFinite(sec)) return '';
|
||||
const s = Math.max(0, Math.round(sec));
|
||||
if (s < 60) return `${s}초`;
|
||||
const m = Math.floor(s / 60);
|
||||
if (m < 60) return `${m}분 ${s % 60}초`;
|
||||
return `${Math.floor(m / 60)}시간 ${m % 60}분`;
|
||||
}
|
||||
|
||||
export function fmtClock(ts: number): string {
|
||||
const d = new Date(ts);
|
||||
return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
export function fmtDuration(ms: number): string {
|
||||
const s = Math.max(0, Math.floor(ms / 1000));
|
||||
const h = Math.floor(s / 3600);
|
||||
const m = Math.floor((s % 3600) / 60);
|
||||
return h ? `${h}시간 ${m}분` : `${m}분 ${s % 60}초`;
|
||||
}
|
||||
|
||||
export function fmtDate(ts: number): string {
|
||||
const d = new Date(ts);
|
||||
return `${d.getMonth() + 1}/${d.getDate()} ${fmtClock(ts)}`;
|
||||
}
|
||||
|
||||
export const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
|
||||
|
||||
export function go(hash: string) {
|
||||
if (location.hash !== hash) location.hash = hash;
|
||||
}
|
||||
Reference in New Issue
Block a user