From 9e6f8077f7508fd463b17ebf99325b9d61828fa3 Mon Sep 17 00:00:00 2001 From: hicccc77 <98377878+hicccc77@users.noreply.github.com> Date: Mon, 30 Mar 2026 12:05:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=95=B0=E6=8D=AE=E5=8C=BF=E5=90=8D?= =?UTF-8?q?=E6=94=B6=E9=9B=86=E5=8F=97=20analyticsConsent=20=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E6=8E=A7=E5=88=B6=20(#589)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 analyticsConsent state 追踪用户同意状态 - initCloudControl() 仅在用户明确同意后执行 - recordPage() 同样受 analyticsConsent 守卫 - handleAnalyticsAllow 同步更新 state,用户同意后立即生效 Fixes #589 --- src/App.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 83af689..d5f2512 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -103,6 +103,7 @@ function App() { // 数据收集同意状态 const [showAnalyticsConsent, setShowAnalyticsConsent] = useState(false) + const [analyticsConsent, setAnalyticsConsent] = useState(null) const [showWaylandWarning, setShowWaylandWarning] = useState(false) @@ -252,6 +253,7 @@ function App() { // 协议已同意,检查数据收集同意状态 const consent = await configService.getAnalyticsConsent() const denyCount = await configService.getAnalyticsDenyCount() + setAnalyticsConsent(consent) // 如果未设置同意状态且拒绝次数小于2次,显示弹窗 if (consent === null && denyCount < 2) { setShowAnalyticsConsent(true) @@ -266,18 +268,21 @@ function App() { checkAgreement() }, []) - // 初始化数据收集 + // 初始化数据收集(仅在用户同意后) useEffect(() => { - cloudControl.initCloudControl() - }, []) + if (analyticsConsent === true) { + cloudControl.initCloudControl() + } + }, [analyticsConsent]) - // 记录页面访问 + // 记录页面访问(仅在用户同意后) useEffect(() => { + if (analyticsConsent !== true) return const path = location.pathname if (path && path !== '/') { cloudControl.recordPage(path) } - }, [location.pathname]) + }, [location.pathname, analyticsConsent]) const handleAgree = async () => { if (!agreementChecked) return @@ -296,6 +301,7 @@ function App() { const handleAnalyticsAllow = async () => { await configService.setAnalyticsConsent(true) + setAnalyticsConsent(true) setShowAnalyticsConsent(false) }