import { Copy, Download, ExternalLink, RotateCw, Scale } from 'lucide-react' import React, { useEffect, useRef, useState } from 'react' import '../i18n/domains/settings.gen' import { I18nKey, t } from '../i18n' import { taskDetail } from '../lib/tasks' import { AppUpdateInfo, Locale, Task } from '../types' import { Button, IconButton } from '../ui/controls' import { Modal } from '../ui/dialog' import { Segmented } from '../ui/settings' import { api } from '../wails' import { REPO_URL, siteURL } from './TitleMenus' import type { UpdatePhase } from '../lib/useAppUpdate' import { BrandMark } from '../ui/themeVisuals' const DISCORD_INVITE_URL = 'https://discord.gg/Tj682rW5rS' const QQ_GROUP_ID = '1136042744' type AppUpdateChannel = 'stable' | 'alpha' | 'dev' interface Props { locale: Locale appVersion?: string appUpdateChannel: AppUpdateChannel onAppUpdateChannel: (channel: AppUpdateChannel) => Promise | void /** Latest update check, shared with the sidebar's update button. */ appUpdate: AppUpdateInfo | null onAppUpdate: (info: AppUpdateInfo) => void updatePhase: UpdatePhase updateTask: Task | null /** The swap has started and the app is about to restart. */ installing: boolean onDownloadUpdate: () => void onCancelUpdate: () => void onInstallUpdate: () => void onCopy?: (text: string) => void onError: (title: string, e: unknown) => void } /** About page: version and updates, project links and community channels. */ export const AboutPage: React.FC = ({ locale, appVersion, appUpdateChannel, onAppUpdateChannel, appUpdate, onAppUpdate, updatePhase, updateTask, installing, onDownloadUpdate, onCancelUpdate, onInstallUpdate, onCopy, onError, }) => { const tr = (k: I18nKey, v?: Record) => t(locale, k, v) const [checkingUpdate, setCheckingUpdate] = useState(false) const [switchingChannel, setSwitchingChannel] = useState(false) const [updateErr, setUpdateErr] = useState('') const [qqInstalled, setQQInstalled] = useState(null) const [openingQQ, setOpeningQQ] = useState(false) const [qqLaunchErr, setQQLaunchErr] = useState('') const [licenseOpen, setLicenseOpen] = useState(false) const [licenseTab, setLicenseTab] = useState<'notice' | 'license'>('notice') const [licenses, setLicenses] = useState<{ license: string; notice: string } | null>(null) const mountedRef = useRef(true) const loadingLicensesRef = useRef(false) const licensePreRef = useRef(null) const openLicenses = async () => { if (licenses) { setLicenseOpen(true) return } if (loadingLicensesRef.current) return loadingLicensesRef.current = true try { // Load embedded license text before mounting the modal so the dialog opens // with its final content on frame 1 instead of reflowing mid-animation. const res = await api.GetLicenseTexts() if (!mountedRef.current) return setLicenses({ license: res?.license ?? '', notice: res?.notice ?? '' }) setLicenseOpen(true) } catch (e) { if (mountedRef.current) onError(tr('failGeneric'), e) } finally { loadingLicensesRef.current = false } } const handleLicenseTabChange = (next: 'notice' | 'license') => { setLicenseTab(next) if (licensePreRef.current) licensePreRef.current.scrollTop = 0 } const runUpdateCheck = async (force: boolean) => { setCheckingUpdate(true) setUpdateErr('') try { onAppUpdate(await api.CheckAppUpdate(force)) } catch (e) { setUpdateErr(String(e).replace(/^Error:\s*/, '')) } finally { setCheckingUpdate(false) } } useEffect(() => { mountedRef.current = true if (!appUpdate) void runUpdateCheck(false) let cancelled = false api.CanOpenQQGroup() .then((ok) => { if (!cancelled) setQQInstalled(!!ok) }) .catch(() => { if (!cancelled) setQQInstalled(false) }) return () => { mountedRef.current = false cancelled = true } }, []) const openURL = (url: string) => { api.OpenURL(url).catch((e) => onError(tr('failGeneric'), e)) } const openQQGroup = async () => { setOpeningQQ(true) setQQLaunchErr('') try { await api.OpenQQGroup() } catch (e) { const msg = String(e).replace(/^Error:\s*/, '') if (/qq not installed/i.test(msg)) { setQQInstalled(false) } else { setQQLaunchErr(msg) } } finally { setOpeningQQ(false) } } const handleChannelChange = async (next: AppUpdateChannel) => { if (next === appUpdateChannel || switchingChannel) return setSwitchingChannel(true) setUpdateErr('') try { await onAppUpdateChannel(next) } catch (e) { setUpdateErr(String(e).replace(/^Error:\s*/, '')) } finally { setSwitchingChannel(false) } } const version = appVersion ?? appUpdate?.current ?? '' const pct = updateTask && updateTask.percent >= 0 ? Math.round(updateTask.percent) : null const updateAvailableKey: I18nKey = appUpdate?.channel === 'dev' ? 'appUpdateAvailableDev' : appUpdate?.channel === 'alpha' ? 'appUpdateAvailableAlpha' : 'appUpdateAvailable' let updateSub: React.ReactNode = null if (updatePhase === 'downloading') { updateSub = ( <>
{tr('updateDownloadingSub', { v: appUpdate?.latest ?? '' })}{updateTask && taskDetail(updateTask) ? ` ยท ${taskDetail(updateTask)}` : ''}