버전 표시 오류 수정7
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { useCallback, useEffect, useState, useRef, useMemo } from 'react';
|
||||
import { getAppVersionInfo, isAndroidPlatform, isIOSPlatform } from '@/utils/platform';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { isAndroidPlatform, isIOSPlatform } from '@/utils/platform';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Capacitor } from '@capacitor/core';
|
||||
|
||||
@@ -27,192 +27,30 @@ const AppVersionInfo: React.FC<AppVersionInfoProps> = ({
|
||||
showDevInfo = true,
|
||||
editable = false
|
||||
}) => {
|
||||
// 저장된 버전 정보 가져오기 (localStorage)
|
||||
const savedInfo = useMemo(() => {
|
||||
try {
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
// localStorage 초기화 - 저장된 오래된 버전 정보 제거
|
||||
localStorage.removeItem('app_version_info');
|
||||
|
||||
const saved = localStorage.getItem('app_version_info');
|
||||
return saved ? JSON.parse(saved) : null;
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
console.error('localStorage 접근 오류:', e);
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
// 하드코딩된 버전 정보 - 빌드 스크립트에서 설정한 값과 일치시켜야 함
|
||||
const hardcodedVersionInfo: VersionInfo = {
|
||||
versionName: '1.1.1.3',
|
||||
buildNumber: 7,
|
||||
versionCode: 7,
|
||||
platform: Capacitor.getPlatform(),
|
||||
defaultValuesUsed: false
|
||||
};
|
||||
|
||||
// 기본 버전 정보를 useMemo로 생성하여 불필요한 재계산 방지
|
||||
const defaultInfo = useMemo<VersionInfo>(() => {
|
||||
const platform = Capacitor.getPlatform();
|
||||
const isWeb = platform === 'web';
|
||||
|
||||
// 항상 최신 버전 정보 사용
|
||||
const defaultVersionInfo: VersionInfo = {
|
||||
versionName: isWeb ? '1.1.1.3' : '1.0.0', // 최신 버전으로 업데이트
|
||||
buildNumber: isWeb ? 7 : 1, // 최신 빌드 번호로 업데이트
|
||||
versionCode: isWeb ? 7 : 1, // 최신 버전 코드로 업데이트
|
||||
platform: platform,
|
||||
defaultValuesUsed: true
|
||||
};
|
||||
|
||||
console.log('사용할 기본 정보:', defaultVersionInfo);
|
||||
|
||||
if (isWeb && typeof localStorage !== 'undefined') {
|
||||
try {
|
||||
localStorage.setItem('app_version_info', JSON.stringify(defaultVersionInfo));
|
||||
console.log('localStorage에 초기 버전 정보 저장됨');
|
||||
} catch (e) {
|
||||
console.error('localStorage에 초기 버전 정보 저장 실패:', e);
|
||||
}
|
||||
}
|
||||
|
||||
return defaultVersionInfo;
|
||||
}, []);
|
||||
|
||||
const [versionInfo, setVersionInfo] = useState<VersionInfo>(defaultInfo);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(false);
|
||||
const [retries, setRetries] = useState(0);
|
||||
|
||||
const fetchVersionInfo = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(false);
|
||||
try {
|
||||
console.log('앱 버전 정보 요청 시작... (retries:', retries, ')');
|
||||
console.log('현재 플랫폼은',
|
||||
isAndroidPlatform() ? 'Android' : isIOSPlatform() ? 'iOS' : '웹');
|
||||
|
||||
if (retries > 0) {
|
||||
await new Promise(resolve => setTimeout(resolve, 300));
|
||||
}
|
||||
|
||||
const info = await getAppVersionInfo();
|
||||
console.log('받은 앱 버전 정보:', info);
|
||||
|
||||
if (!info || typeof info !== 'object') {
|
||||
throw new Error('유효하지 않은 응답 형식');
|
||||
}
|
||||
|
||||
const parseVersionInfo = (data: Record<string, unknown>): VersionInfo => {
|
||||
let buildNumber: number = defaultInfo.buildNumber;
|
||||
if (typeof data.buildNumber === 'number') {
|
||||
buildNumber = data.buildNumber;
|
||||
} else if (typeof data.buildNumber === 'string') {
|
||||
const parsed = parseInt(data.buildNumber, 10);
|
||||
if (!isNaN(parsed)) buildNumber = parsed;
|
||||
}
|
||||
|
||||
let versionCode: number | undefined = defaultInfo.versionCode;
|
||||
if (typeof data.versionCode === 'number') {
|
||||
versionCode = data.versionCode;
|
||||
} else if (typeof data.versionCode === 'string') {
|
||||
const parsed = parseInt(data.versionCode as string, 10);
|
||||
if (!isNaN(parsed)) versionCode = parsed;
|
||||
}
|
||||
|
||||
return {
|
||||
versionName: typeof data.versionName === 'string' && data.versionName.trim() !== ''
|
||||
? data.versionName as string
|
||||
: defaultInfo.versionName,
|
||||
buildNumber,
|
||||
versionCode,
|
||||
platform: data.platform as string || defaultInfo.platform,
|
||||
pluginResponse: typeof data.pluginResponse === 'string'
|
||||
? data.pluginResponse
|
||||
: JSON.stringify(data),
|
||||
timestamp: typeof data.timestamp === 'number' ? data.timestamp : Date.now(),
|
||||
defaultValuesUsed: false
|
||||
};
|
||||
};
|
||||
|
||||
const newVersionInfo = parseVersionInfo(info);
|
||||
|
||||
try {
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
localStorage.setItem('app_version_info', JSON.stringify(newVersionInfo));
|
||||
console.log('버전 정보가 localStorage에 저장됨:', newVersionInfo);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('버전 정보 저장 실패:', e);
|
||||
}
|
||||
|
||||
setVersionInfo(newVersionInfo);
|
||||
setLoading(false);
|
||||
console.log('앱 버전 정보 표시 준비 완료');
|
||||
} catch (error) {
|
||||
console.error('버전 정보 가져오기 실패:', error);
|
||||
setError(true);
|
||||
setLoading(false);
|
||||
}
|
||||
}, [retries, defaultInfo]);
|
||||
|
||||
const handleRetry = useCallback(() => {
|
||||
setRetries(prev => prev + 1);
|
||||
fetchVersionInfo();
|
||||
}, [fetchVersionInfo]);
|
||||
|
||||
const initialLoadAttemptedRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
|
||||
const loadVersionInfo = async () => {
|
||||
console.log('앱 버전 정보 로딩 시작');
|
||||
|
||||
try {
|
||||
const newVersionInfo = await getAppVersionInfo();
|
||||
|
||||
if (!isMounted) return;
|
||||
|
||||
console.log('불러온 버전 정보:', newVersionInfo);
|
||||
|
||||
try {
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
localStorage.setItem('app_version_info', JSON.stringify(newVersionInfo));
|
||||
console.log('버전 정보가 localStorage에 저장됨:', newVersionInfo);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('버전 정보 저장 실패:', e);
|
||||
}
|
||||
|
||||
if (isMounted) {
|
||||
setVersionInfo(newVersionInfo);
|
||||
setLoading(false);
|
||||
console.log('앱 버전 정보 표시 준비 완료');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('버전 정보 가져오기 실패:', error);
|
||||
|
||||
if (isMounted) {
|
||||
const fallbackInfo = defaultInfo;
|
||||
console.log('오류 발생으로 대체 정보 사용:', fallbackInfo);
|
||||
setVersionInfo(fallbackInfo);
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
loadVersionInfo();
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, [defaultInfo]);
|
||||
const [versionInfo, setVersionInfo] = useState<VersionInfo>(hardcodedVersionInfo);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
// 개발자 정보 표시
|
||||
const renderDevInfo = () => {
|
||||
if (versionInfo && showDevInfo) {
|
||||
return (
|
||||
<div className="mt-2 text-xs text-muted-foreground">
|
||||
<div>
|
||||
<span className="font-semibold">앱 플랫폼:</span> {versionInfo.platform || 'unknown'}
|
||||
</div>
|
||||
{versionInfo.defaultValuesUsed && (
|
||||
<div className="text-yellow-600 dark:text-yellow-400">
|
||||
⚠️ 기본값 사용 중: 실제 버전 정보를 가져오지 못했습니다
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
<p>
|
||||
{versionInfo.versionCode ? `버전 코드: ${versionInfo.versionCode}` : ''}
|
||||
{versionInfo.buildNumber ? `, 빌드: ${versionInfo.buildNumber}` : ''}
|
||||
{versionInfo.platform ? ` (${versionInfo.platform})` : ''}
|
||||
</p>
|
||||
{versionInfo.errorMessage && (
|
||||
<p className="text-destructive">오류: {versionInfo.errorMessage}</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@@ -222,44 +60,17 @@ const AppVersionInfo: React.FC<AppVersionInfoProps> = ({
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
{loading ? (
|
||||
<div className="py-1 text-center">
|
||||
<p className="text-sm text-gray-400 animate-pulse">버전 정보 로딩 중...</p>
|
||||
</div>
|
||||
) : error ? (
|
||||
<div className="py-1 text-center">
|
||||
<p className="text-sm text-red-500">빌드 정보 로딩 오류</p>
|
||||
<button
|
||||
onClick={handleRetry}
|
||||
className="text-xs text-blue-500 underline mt-1 px-2 py-0.5 rounded hover:bg-blue-50"
|
||||
>
|
||||
재시도
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="py-2 text-center neuro-flat px-4 rounded-md">
|
||||
<p className="text-sm text-gray-600">
|
||||
버전: <span className="font-semibold">{versionInfo.versionName}</span>
|
||||
</p>
|
||||
<p className="text-xs text-gray-500 mt-1">
|
||||
빌드: <span className="font-mono">{versionInfo.buildNumber}</span>
|
||||
</p>
|
||||
{showDevInfo && versionInfo.versionCode && (
|
||||
<p className="text-xs text-gray-400 mt-1 font-mono">
|
||||
versionCode: {versionInfo.versionCode}
|
||||
</p>
|
||||
<div className="flex flex-col space-y-1">
|
||||
<Label className="text-base">버전 정보</Label>
|
||||
<p className="text-sm">
|
||||
{loading ? (
|
||||
"버전 정보 로딩 중..."
|
||||
) : (
|
||||
versionInfo.versionName || "알 수 없음"
|
||||
)}
|
||||
{showDevInfo && versionInfo.platform && (
|
||||
<p className="text-xs text-gray-400 mt-1 font-mono">
|
||||
플랫폼: {versionInfo.platform}
|
||||
</p>
|
||||
)}
|
||||
{editable && (
|
||||
<p className="text-gray-400 font-semibold text-sm mt-2">ZELLYY CLOUD</p>
|
||||
)}
|
||||
{renderDevInfo()}
|
||||
</div>
|
||||
)}
|
||||
</p>
|
||||
{renderDevInfo()}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user