Skip to content

Commit cb35578

Browse files
jhlee0409claude
andcommitted
fix: use Tauri native timeout for update check and fix ref → state
- Use Tauri's built-in timeout option for check() instead of JS Promise.race - JS timeout cannot interrupt native Rust operations - Tauri native timeout properly cancels HTTP request at Rust level - Change manualCheckRef (useRef) to isManualCheck (useState) - Ref changes don't trigger re-renders - State changes properly trigger React re-renders for toast display Fixes infinite loading on update check Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7f40975 commit cb35578

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

src/components/SimpleUpdateManager.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useRef } from "react";
1+
import { useState, useEffect } from "react";
22
import { useSmartUpdater } from "../hooks/useSmartUpdater";
33
import { SimpleUpdateModal } from "./SimpleUpdateModal";
44
import { UpdateIntroModal } from "./UpdateConsentModal";
@@ -13,20 +13,20 @@ export function SimpleUpdateManager() {
1313
const [showChecking, setShowChecking] = useState(false);
1414
const [showError, setShowError] = useState(false);
1515
const [errorMessage, setErrorMessage] = useState("");
16-
const manualCheckRef = useRef(false);
16+
const [isManualCheck, setIsManualCheck] = useState(false);
1717

1818
// 수동 체크 시 체크 중 알림 표시
1919
useEffect(() => {
20-
if (updater.state.isChecking && manualCheckRef.current) {
20+
if (updater.state.isChecking && isManualCheck) {
2121
setShowChecking(true);
2222
} else {
2323
setShowChecking(false);
2424
}
25-
}, [updater.state.isChecking]);
25+
}, [updater.state.isChecking, isManualCheck]);
2626

2727
// 수동 체크 결과 처리
2828
useEffect(() => {
29-
if (!updater.state.isChecking && manualCheckRef.current) {
29+
if (!updater.state.isChecking && isManualCheck) {
3030
if (updater.state.error) {
3131
// 에러 발생
3232
setErrorMessage(updater.state.error);
@@ -37,18 +37,19 @@ export function SimpleUpdateManager() {
3737
setTimeout(() => setShowUpToDate(false), 3000);
3838
}
3939
// 업데이트가 있는 경우 업데이트 모달이 표시됨
40-
manualCheckRef.current = false;
40+
setIsManualCheck(false);
4141
}
4242
}, [
4343
updater.state.isChecking,
4444
updater.state.hasUpdate,
4545
updater.state.error,
46+
isManualCheck,
4647
]);
4748

4849
// 수동 업데이트 체크 이벤트 리스너
4950
useEffect(() => {
5051
const handleManualCheck = () => {
51-
manualCheckRef.current = true;
52+
setIsManualCheck(true);
5253
setShowError(false);
5354
setShowUpToDate(false);
5455
updater.smartCheckForUpdates(true); // 강제 체크
@@ -83,7 +84,7 @@ export function SimpleUpdateManager() {
8384
<UpdateCheckingNotification
8485
onClose={() => {
8586
setShowChecking(false);
86-
manualCheckRef.current = false; // X 클릭 시 수동 체크 플래그 해제
87+
setIsManualCheck(false);
8788
}}
8889
isVisible={showChecking}
8990
/>

src/hooks/useGitHubUpdater.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ const GITHUB_RELEASE_URL = `https://github.com/${REPO_OWNER}/${REPO_NAME}/releas
1414
const API_TIMEOUT_MS = 10000;
1515
const TAURI_CHECK_TIMEOUT_MS = 15000;
1616

17-
// Promise with timeout wrapper
18-
function withTimeout<T>(promise: Promise<T>, ms: number, errorMessage: string): Promise<T> {
19-
return Promise.race([
20-
promise,
21-
new Promise<T>((_, reject) =>
22-
setTimeout(() => reject(new Error(errorMessage)), ms)
23-
),
24-
]);
25-
}
26-
2717
export interface GitHubRelease {
2818
tag_name: string;
2919
name: string;
@@ -129,12 +119,8 @@ export function useGitHubUpdater(): UseGitHubUpdaterReturn {
129119
}
130120

131121
// Tauri 업데이터로 업데이트 확인 (핵심 - 먼저 실행)
132-
// Timeout 추가로 무한 대기 방지
133-
const update = await withTimeout(
134-
check(),
135-
TAURI_CHECK_TIMEOUT_MS,
136-
'Update check timed out'
137-
);
122+
// Tauri 네이티브 타임아웃 사용 (Rust 레벨에서 HTTP 요청 취소 가능)
123+
const update = await check({ timeout: TAURI_CHECK_TIMEOUT_MS });
138124
const hasUpdate = !!update;
139125

140126
// GitHub API로 릴리즈 정보 가져오기 (실패해도 업데이트 체크는 계속)

0 commit comments

Comments
 (0)