// desktop/src/components/settings/ChatGPTOfficialLogin.tsx import { useEffect } from 'react' import { open as shellOpen } from '@tauri-apps/plugin-shell' import { LogIn, LogOut } from 'lucide-react' import { useHahaOpenAIOAuthStore } from '../../stores/hahaOpenAIOAuthStore' import { useTranslation } from '../../i18n' export function ChatGPTOfficialLogin() { const t = useTranslation() const { status, isLoading, error, fetchStatus, login, logout, startPolling, stopPolling, } = useHahaOpenAIOAuthStore() useEffect(() => { void fetchStatus() return () => stopPolling() }, [fetchStatus, stopPolling]) const handleLogin = async () => { try { const { authorizeUrl } = await login() try { await shellOpen(authorizeUrl) startPolling() } catch (err) { console.error('[ChatGPTOfficialLogin] shellOpen failed:', err) useHahaOpenAIOAuthStore.setState({ error: t('settings.chatgptOfficialLogin.openBrowserFailed'), }) } } catch { // store.login() errors are already captured into store.error } } if (status === null) { if (error) { return (