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:
@@ -2,6 +2,82 @@ import { check } from '@tauri-apps/plugin-updater';
|
|||||||
import { relaunch } from '@tauri-apps/plugin-process';
|
import { relaunch } from '@tauri-apps/plugin-process';
|
||||||
import { getVersion } from '@tauri-apps/api/app';
|
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 =
|
export type DesktopUpdatePhase =
|
||||||
| 'checking'
|
| 'checking'
|
||||||
| 'uptodate'
|
| 'uptodate'
|
||||||
@@ -172,11 +248,29 @@ export async function runDesktopUpdate(
|
|||||||
try {
|
try {
|
||||||
const update = await check();
|
const update = await check();
|
||||||
if (!update) {
|
if (!update) {
|
||||||
|
clearUpdateLoopGuard();
|
||||||
const message = `최신 버전입니다. (v${currentVersion})`;
|
const message = `최신 버전입니다. (v${currentVersion})`;
|
||||||
emit(onProgress, { phase: 'uptodate', message, currentVersion });
|
emit(onProgress, { phase: 'uptodate', message, currentVersion });
|
||||||
return { ok: true, 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, {
|
emit(onProgress, {
|
||||||
phase: 'available',
|
phase: 'available',
|
||||||
message: `새 버전 v${update.version}을(를) 받습니다. (현재 v${currentVersion})`,
|
message: `새 버전 v${update.version}을(를) 받습니다. (현재 v${currentVersion})`,
|
||||||
|
|||||||
@@ -60,17 +60,19 @@ function addPlatform(platformKey, bundleName) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const bundleVersion = versionFromName(bundleName);
|
const bundleVersion = versionFromName(bundleName);
|
||||||
|
const effectiveVersion = bundleVersion === '0.0.0' ? version : bundleVersion;
|
||||||
const existing = platforms[platformKey];
|
const existing = platforms[platformKey];
|
||||||
if (existing && cmpSemver(bundleVersion, existing.bundleVersion) <= 0) return;
|
if (existing && cmpSemver(effectiveVersion, existing.bundleVersion) <= 0) return;
|
||||||
platforms[platformKey] = {
|
platforms[platformKey] = {
|
||||||
url: `${baseUrl}/${encodeURIComponent(bundleName)}`,
|
url: `${baseUrl}/${encodeURIComponent(bundleName)}`,
|
||||||
signature,
|
signature,
|
||||||
bundleVersion,
|
bundleVersion: effectiveVersion,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const f of files) {
|
for (const f of files) {
|
||||||
if (f.endsWith('.sig')) continue;
|
if (f.endsWith('.sig')) continue;
|
||||||
|
if (f.endsWith('.dmg')) continue; // 설치용 dmg — updater manifest 대상 아님
|
||||||
const lower = f.toLowerCase();
|
const lower = f.toLowerCase();
|
||||||
if (lower.includes('aarch64') && (lower.endsWith('.tar.gz') || lower.endsWith('.app.tar.gz'))) {
|
if (lower.includes('aarch64') && (lower.endsWith('.tar.gz') || lower.endsWith('.app.tar.gz'))) {
|
||||||
addPlatform('darwin-aarch64', f);
|
addPlatform('darwin-aarch64', f);
|
||||||
@@ -91,7 +93,12 @@ const bundleMaxVersion = Object.values(platforms).reduce(
|
|||||||
(max, p) => (cmpSemver(p.bundleVersion, max) > 0 ? p.bundleVersion : max),
|
(max, p) => (cmpSemver(p.bundleVersion, max) > 0 ? p.bundleVersion : max),
|
||||||
'0.0.0',
|
'0.0.0',
|
||||||
);
|
);
|
||||||
const manifestVersion = cmpSemver(bundleMaxVersion, version) > 0 ? bundleMaxVersion : version;
|
// manifest 버전 = 빌드 버전(--version). 번들 파일명에 버전 없으면 CLI 버전 사용.
|
||||||
|
// dmg 파일명으로 올리지 않음 — tar.gz 내용과 불일치하면 업데이트 무한 루프.
|
||||||
|
let manifestVersion = version;
|
||||||
|
if (bundleMaxVersion !== '0.0.0' && cmpSemver(bundleMaxVersion, version) < 0) {
|
||||||
|
console.warn(`[warn] bundle version ${bundleMaxVersion} < build ${version} — using build version`);
|
||||||
|
}
|
||||||
|
|
||||||
const manifest = {
|
const manifest = {
|
||||||
version: manifestVersion,
|
version: manifestVersion,
|
||||||
|
|||||||
@@ -15,40 +15,23 @@ if [[ ! -d "$UPDATES_DIR" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
VERSION="$(node -p "require('$CONF').version" 2>/dev/null || echo '0.1.0')"
|
VERSION="$(node -p "require('$CONF').version" 2>/dev/null || echo '0.1.0')"
|
||||||
LATEST_JSON="$UPDATES_DIR/latest.json"
|
|
||||||
BUILD_INFO="$UPDATES_DIR/build-info.json"
|
BUILD_INFO="$UPDATES_DIR/build-info.json"
|
||||||
|
if [[ -f "$BUILD_INFO" ]]; then
|
||||||
# bundle 파일명·build-info·기존 manifest 중 최고 버전 사용 (build-info stale 방지)
|
|
||||||
VERSION="$(node <<NODE
|
VERSION="$(node <<NODE
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
|
||||||
const cmp = (a, b) => {
|
const cmp = (a, b) => {
|
||||||
const pa = a.split('.').map(Number), pb = b.split('.').map(Number);
|
const pa = a.split('.').map(Number), pb = b.split('.').map(Number);
|
||||||
for (let i = 0; i < 3; i++) { const d = (pa[i]||0)-(pb[i]||0); if (d) return d; }
|
for (let i = 0; i < 3; i++) { const d = (pa[i]||0)-(pb[i]||0); if (d) return d; }
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
const maxV = (a, b) => (cmp(a, b) >= 0 ? a : b);
|
const confV = '$VERSION';
|
||||||
let version = '$VERSION';
|
let biV = confV;
|
||||||
const dir = '$UPDATES_DIR';
|
try { biV = JSON.parse(fs.readFileSync('$BUILD_INFO', 'utf8')).version || confV; } catch {}
|
||||||
try {
|
console.log(cmp(biV, confV) > 0 ? biV : confV);
|
||||||
const bi = JSON.parse(fs.readFileSync('$BUILD_INFO', 'utf8'));
|
|
||||||
if (bi.version) version = maxV(version, bi.version);
|
|
||||||
} catch {}
|
|
||||||
try {
|
|
||||||
const j = JSON.parse(fs.readFileSync('$LATEST_JSON', 'utf8'));
|
|
||||||
if (j.version && j.platforms && Object.keys(j.platforms).length > 0) {
|
|
||||||
version = maxV(version, j.version);
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
try {
|
|
||||||
for (const f of fs.readdirSync(dir)) {
|
|
||||||
const m = f.match(/(\\d+\\.\\d+\\.\\d+)/);
|
|
||||||
if (m) version = maxV(version, m[1]);
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
console.log(version);
|
|
||||||
NODE
|
NODE
|
||||||
)"
|
)"
|
||||||
|
fi
|
||||||
|
# dmg/exe 설치 파일명 버전은 manifest에 반영하지 않음 (updater tar.gz/exe와 불일치 시 루프 유발)
|
||||||
NOTES="${DESKTOP_RELEASE_NOTES:-GoldenChart Desktop $VERSION}"
|
NOTES="${DESKTOP_RELEASE_NOTES:-GoldenChart Desktop $VERSION}"
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
|||||||
Reference in New Issue
Block a user