// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. ========= // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. ========= import { proxyFetchGet, proxyFetchPut } from '@/api/http'; import privacy_settings from '@/assets/privacy_settings.png'; import { useAuthStore } from '@/store/authStore'; import { ArrowRight, Square, SquareCheckBig } from 'lucide-react'; import React, { useEffect, useMemo, useState } from 'react'; import { Button } from '../ui/button'; export const Permissions: React.FC = () => { const { setInitState } = useAuthStore(); const API_FIELDS = useMemo( () => [ 'take_screenshot', 'access_local_software', 'access_your_address', 'password_storage', ], [] ); const [settings, setSettings] = useState([ { title: 'Enable screen recording', checked: false, }, { title: 'Enable access Local Software', checked: false, }, { title: 'Grant location access', checked: false, }, { title: 'Share data to enhance Eigent', checked: false, }, ]); useEffect(() => { proxyFetchGet('/api/user/privacy') .then((res) => { setSettings((prev) => prev.map((item, index) => ({ ...item, checked: res[API_FIELDS[index]] || false, })) ); }) .catch((err) => console.error('Failed to fetch settings:', err)); }, [API_FIELDS]); const handleToggle = (index: number) => { setSettings((prev) => { const newSettings = [...prev]; newSettings[index] = { ...newSettings[index], checked: !newSettings[index].checked, }; return newSettings; }); const requestData = { [API_FIELDS[0]]: settings[0].checked, [API_FIELDS[1]]: settings[1].checked, [API_FIELDS[2]]: settings[2].checked, [API_FIELDS[3]]: settings[3].checked, }; requestData[API_FIELDS[index]] = !settings[index].checked; proxyFetchPut('/api/user/privacy', requestData).catch((err) => console.error('Failed to update settings:', err) ); }; return (