iloom-flatten/.microcompact/mpmitich/call_f9b326e7cd5e4b75922cc608.txt

30 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

The file /home/project/src/hooks/useNetworkStatus.ts has been updated. Made 1 replacement.
Here's the result of running `cat -n` on a snippet of the edited file:
50→
51→ window.addEventListener('online', handleOnline);
52→ window.addEventListener('offline', handleOffline);
53→
54→ // 检测慢网络(使用轻量级 DNS 预解析代替 HTTP 请求)
55→ const checkConnectionSpeed = async () => {
56→ if (!navigator.onLine) return;
57→
58→ // 仅通过 navigator.connection API 检测(如果可用)
59→ const connection = (navigator as any).connection;
60→ if (connection) {
61→ setState(prev => ({
62→ ...prev,
63→ isSlowConnection: connection.effectiveType === 'slow-2g' || connection.effectiveType === '2g'
64→ }));
65→ }
66→ // 如果不支持 Connection API则不进行主动探测避免产生大量 502 错误
67→ };
68→
69→ // 每60秒检测一次网络质量降低频率
70→ const interval = setInterval(checkConnectionSpeed, 60000);
71→ checkConnectionSpeed();
72→
73→ return () => {
74→ window.removeEventListener('online', handleOnline);
75→ window.removeEventListener('offline', handleOffline);
76→ clearInterval(interval);