import { TopView } from '@renderer/components/TopView' import { useTheme } from '@renderer/context/ThemeProvider' import { ThemeMode } from '@renderer/types' import { runAsyncFunction } from '@renderer/utils' import { Button, Modal } from 'antd' import { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import styled from 'styled-components' const WebViewContainer = styled.div` width: 100%; height: 500px; overflow: hidden; webview { width: 100%; height: 100%; border: none; background: transparent; } ` interface ShowParams { title?: string showDeclineButton?: boolean } interface Props extends ShowParams { resolve: (data: any) => void } const PopupContainer: React.FC = ({ title, showDeclineButton = true, resolve }) => { const [open, setOpen] = useState(true) const [privacyUrl, setPrivacyUrl] = useState('') const { theme } = useTheme() const { i18n } = useTranslation() const getTitle = () => { if (title) return title const isChinese = i18n.language.startsWith('zh') return isChinese ? '隐私协议' : 'Privacy Policy' } const handleAccept = () => { setOpen(false) localStorage.setItem('privacy-popup-accepted', 'true') resolve({ accepted: true }) } const handleDecline = () => { setOpen(false) window.api.quit() resolve({ accepted: false }) } const onClose = () => { if (!showDeclineButton) { handleAccept() } else { handleDecline() } } useEffect(() => { runAsyncFunction(async () => { const { appPath } = await window.api.getAppInfo() const isChinese = i18n.language.startsWith('zh') const htmlFile = isChinese ? 'privacy-zh.html' : 'privacy-en.html' const url = `file://${appPath}/resources/cherry-studio/${htmlFile}?theme=${theme === ThemeMode.dark ? 'dark' : 'light'}` setPrivacyUrl(url) }) }, [theme, i18n.language]) PrivacyPopup.hide = () => setOpen(false) return ( {i18n.language.startsWith('zh') ? '拒绝' : 'Decline'} ), ].filter(Boolean)}> {privacyUrl && } ) } const TopViewKey = 'PrivacyPopup' export default class PrivacyPopup { static topviewId = 0 static hide() { TopView.hide(TopViewKey) } static async show(props?: ShowParams) { const accepted = localStorage.getItem('privacy-popup-accepted') if (accepted) { return } return new Promise<{ accepted: boolean }>((resolve) => { TopView.show( { resolve(v) TopView.hide(TopViewKey) }} />, TopViewKey ) }) } }