fix: stop desktop startup update loop — manifest version matches bundles

Do not inflate latest.json from dmg filenames; use build version only.
Add client loop guard when the same update retries without version bump.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Macbook
2026-06-14 12:36:42 +09:00
parent e658d9afe4
commit 36c06b55ea
3 changed files with 112 additions and 28 deletions
+94
View File
@@ -2,6 +2,82 @@ import { check } from '@tauri-apps/plugin-updater';
import { relaunch } from '@tauri-apps/plugin-process';
import { getVersion } from '@tauri-apps/api/app';
const UPDATE_LOOP_GUARD_KEY = 'goldenchart:startup-update-guard';
const UPDATE_LOOP_MAX_ATTEMPTS = 2;
const UPDATE_LOOP_WINDOW_MS = 15 * 60 * 1000;
function cmpSemver(a: string, b: string): number {
const pa = a.split('.').map(Number);
const pb = b.split('.').map(Number);
for (let i = 0; i < 3; i++) {
const d = (pa[i] || 0) - (pb[i] || 0);
if (d !== 0) return d;
}
return 0;
}
interface UpdateLoopGuard {
targetVersion: string;
fromVersion: string;
attempts: number;
lastAt: number;
}
function readUpdateLoopGuard(): UpdateLoopGuard | null {
try {
const raw = localStorage.getItem(UPDATE_LOOP_GUARD_KEY);
if (!raw) return null;
return JSON.parse(raw) as UpdateLoopGuard;
} catch {
return null;
}
}
function writeUpdateLoopGuard(guard: UpdateLoopGuard) {
try {
localStorage.setItem(UPDATE_LOOP_GUARD_KEY, JSON.stringify(guard));
} catch {
/* ignore */
}
}
function clearUpdateLoopGuard() {
try {
localStorage.removeItem(UPDATE_LOOP_GUARD_KEY);
} catch {
/* ignore */
}
}
function shouldBlockUpdateLoop(currentVersion: string, targetVersion: string): boolean {
const guard = readUpdateLoopGuard();
if (!guard) return false;
if (guard.targetVersion !== targetVersion) return false;
if (currentVersion === targetVersion) return false;
if (Date.now() - guard.lastAt > UPDATE_LOOP_WINDOW_MS) return false;
return guard.attempts >= UPDATE_LOOP_MAX_ATTEMPTS && guard.fromVersion === currentVersion;
}
function recordUpdateLoopAttempt(currentVersion: string, targetVersion: string) {
const guard = readUpdateLoopGuard();
const now = Date.now();
if (
guard
&& guard.targetVersion === targetVersion
&& guard.fromVersion === currentVersion
&& now - guard.lastAt < UPDATE_LOOP_WINDOW_MS
) {
writeUpdateLoopGuard({ ...guard, attempts: guard.attempts + 1, lastAt: now });
return;
}
writeUpdateLoopGuard({
targetVersion,
fromVersion: currentVersion,
attempts: 1,
lastAt: now,
});
}
export type DesktopUpdatePhase =
| 'checking'
| 'uptodate'
@@ -172,11 +248,29 @@ export async function runDesktopUpdate(
try {
const update = await check();
if (!update) {
clearUpdateLoopGuard();
const message = `최신 버전입니다. (v${currentVersion})`;
emit(onProgress, { phase: 'uptodate', message, currentVersion });
return { ok: true, phase: 'uptodate', message, currentVersion };
}
if (cmpSemver(update.version, currentVersion) <= 0) {
clearUpdateLoopGuard();
const message = `최신 버전입니다. (v${currentVersion})`;
emit(onProgress, { phase: 'uptodate', message, currentVersion });
return { ok: true, phase: 'uptodate', message, currentVersion };
}
if (shouldBlockUpdateLoop(currentVersion, update.version)) {
const message =
`v${update.version} 업데이트가 반복 실패했습니다. 서버 패키지와 버전이 맞지 않을 수 있습니다. ` +
'PC 프로그램 탭에서 설치 파일을 받아 다시 설치해 주세요.';
emit(onProgress, { phase: 'error', message, currentVersion, newVersion: update.version });
return { ok: false, phase: 'error', message, currentVersion, newVersion: update.version };
}
recordUpdateLoopAttempt(currentVersion, update.version);
emit(onProgress, {
phase: 'available',
message: `새 버전 v${update.version}을(를) 받습니다. (현재 v${currentVersion})`,