()
| 165 | }; |
| 166 | |
| 167 | // --- React 组件 --- |
| 168 | const UnityModuleFetcherInner: React.FC = () => { |
| 169 | // --- 使用钩子获取 URL 参数和路由控制 --- |
| 170 | const searchParams = useSearchParams(); // 获取查询参数对象 |
| 171 | const router = useRouter(); // 用于更新浏览器 URL |
| 172 | const pathname = usePathname(); // 当前页面路径(不含查询参数) |
| 173 | |
| 174 | const [inputUri, setInputUri] = useState<string>(''); |
| 175 | const [parsedVersion, setParsedVersion] = useState<string | null>(null); |
| 176 | |
| 177 | // --- 用户选择的状态 --- |
| 178 | const [selectedPlatform, setSelectedPlatform] = useState<UnityReleaseDownloadPlatform>(UnityReleaseDownloadPlatform.WINDOWS); |
| 179 | const [selectedArchitecture, setSelectedArchitecture] = useState<UnityReleaseDownloadArchitecture>(UnityReleaseDownloadArchitecture.X86_64); |
| 180 | const [selectedStream, setSelectedStream] = useState<UnityReleaseStream | ''>(''); // 允许空字符串表示不指定 |
| 181 | const [selectedEntitlements, setSelectedEntitlements] = useState<UnityReleaseEntitlement[]>([]); // 允许空数组 |
| 182 | |
| 183 | const [loading, setLoading] = useState<boolean>(false); |
| 184 | const [error, setError] = useState<string | null>(null); |
| 185 | const [modules, setModules] = useState<Module[] | null>(null); |
| 186 | |
| 187 | // --- 在组件挂载时处理 URL 查询参数 --- |
| 188 | useEffect(() => { |
| 189 | // 从 URL 中获取 'v' 参数 |
| 190 | const uriFromParam = searchParams.get('v'); |
| 191 | const platformFromParam = searchParams.get('platform') as UnityReleaseDownloadPlatform | null; |
| 192 | const archFromParam = searchParams.get('arch') as UnityReleaseDownloadArchitecture | null; |
| 193 | const streamFromParam = searchParams.get('stream') as UnityReleaseStream | null; |
| 194 | const entitlementsFromParam = searchParams.get('entitlements'); |
| 195 | |
| 196 | if (uriFromParam) { |
| 197 | setInputUri(uriFromParam); |
| 198 | const result = parseUnityHubUri(uriFromParam); |
| 199 | if (result) { |
| 200 | setParsedVersion(result.version); |
| 201 | setError(null); |
| 202 | } else { |
| 203 | setParsedVersion(null); |
| 204 | setError('无法解析 URI,请检查格式是否正确!'); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // 设置平台 |
| 209 | if (platformFromParam && Object.values(UnityReleaseDownloadPlatform).includes(platformFromParam)) { |
| 210 | setSelectedPlatform(platformFromParam); |
| 211 | } |
| 212 | |
| 213 | // 设置架构 |
| 214 | if (archFromParam && Object.values(UnityReleaseDownloadArchitecture).includes(archFromParam)) { |
| 215 | setSelectedArchitecture(archFromParam); |
| 216 | } |
| 217 | |
| 218 | // 设置 Stream |
| 219 | if (!streamFromParam) { |
| 220 | setSelectedStream(''); |
| 221 | } else if (Object.values(UnityReleaseStream).includes(streamFromParam as UnityReleaseStream)) { |
| 222 | setSelectedStream(streamFromParam); |
| 223 | } |
| 224 |
nothing calls this directly
no test coverage detected