Appearance, VM busy state, the in-app update, file drops and the theme event stream are now hooks in lib/. VMAction moved to types.ts, so the VM page and its parts no longer import each other, and error toasts have one builder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
398 lines
16 KiB
TypeScript
398 lines
16 KiB
TypeScript
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> | 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<Props> = ({
|
|
locale, appVersion, appUpdateChannel, onAppUpdateChannel, appUpdate, onAppUpdate, updatePhase, updateTask, installing,
|
|
onDownloadUpdate, onCancelUpdate, onInstallUpdate, onCopy, onError,
|
|
}) => {
|
|
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
|
const [checkingUpdate, setCheckingUpdate] = useState(false)
|
|
const [switchingChannel, setSwitchingChannel] = useState(false)
|
|
const [updateErr, setUpdateErr] = useState('')
|
|
const [qqInstalled, setQQInstalled] = useState<boolean | null>(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<HTMLPreElement>(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 = (
|
|
<>
|
|
<div className="row-sub">{tr('updateDownloadingSub', { v: appUpdate?.latest ?? '' })}{updateTask && taskDetail(updateTask) ? ` · ${taskDetail(updateTask)}` : ''}</div>
|
|
<span className="progress rg-p-progress about-update-progress" aria-hidden="true">
|
|
<span className="progress-fill" style={{ transform: `scaleX(${(pct ?? 0) / 100})` }} />
|
|
</span>
|
|
</>
|
|
)
|
|
} else if (updatePhase === 'ready') {
|
|
updateSub = <div className="row-sub">{tr('updateReadySub', { v: appUpdate?.latest ?? '' })}</div>
|
|
} else if (updatePhase === 'failed') {
|
|
updateSub = <div className="row-sub warn-text" title={updateTask?.error}>{tr('updateFailedSub')}</div>
|
|
} else if (appUpdate?.has_update) {
|
|
updateSub = <div className="row-sub">{tr(updateAvailableKey, { v: appUpdate.latest })}</div>
|
|
} else if (updateErr) {
|
|
updateSub = <div className="row-sub" title={updateErr}>{tr('appUpdateLookupFailed')}</div>
|
|
}
|
|
|
|
let updateAction: React.ReactNode
|
|
if (updatePhase === 'downloading') {
|
|
updateAction = <Button onClick={onCancelUpdate}>{tr('updateCancel')}</Button>
|
|
} else if (updatePhase === 'ready') {
|
|
updateAction = <Button variant="primary" busy={installing} onClick={onInstallUpdate}>{tr('updateRestart')}</Button>
|
|
} else if (updatePhase === 'failed') {
|
|
updateAction = <Button variant="primary" icon={<RotateCw size={14} aria-hidden="true" />} onClick={onDownloadUpdate}>{tr('updateRetry')}</Button>
|
|
} else if (updatePhase === 'available') {
|
|
updateAction = <Button variant="primary" icon={<Download size={14} aria-hidden="true" />} onClick={onDownloadUpdate}>{tr('updateDownloadInstall')}</Button>
|
|
} else {
|
|
updateAction = <Button busy={checkingUpdate} onClick={() => void runUpdateCheck(true)}>{tr('appCheckUpdate')}</Button>
|
|
}
|
|
|
|
return (
|
|
<div className="page about-page">
|
|
<header className="about-hero">
|
|
<BrandMark className="about-hero-mark" />
|
|
<div className="about-hero-text">
|
|
<h1>Reims-Go</h1>
|
|
<p>{tr('aboutTagline')}</p>
|
|
</div>
|
|
</header>
|
|
|
|
<section className="section">
|
|
<div className="list">
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">
|
|
{tr('appVersionTitle')} <span className="mono">{version}</span>
|
|
{appUpdate && !appUpdate.has_update && (
|
|
<span className="badge rg-p-badge badge-ok">{tr('appUpToDate')}</span>
|
|
)}
|
|
</div>
|
|
{updateSub}
|
|
</div>
|
|
<div className="row-right">
|
|
{appUpdate?.has_update && appUpdate.page_url && (
|
|
<Button variant="ghost" icon={<ExternalLink size={14} aria-hidden="true" />} onClick={() => openURL(appUpdate.page_url!)}>
|
|
{tr('updateReleaseNotes')}
|
|
</Button>
|
|
)}
|
|
{updateAction}
|
|
</div>
|
|
</div>
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">{tr('appUpdateChannelTitle')}</div>
|
|
<div className="row-sub">
|
|
{appUpdateChannel === 'stable'
|
|
? tr('appUpdateChannelSubStable')
|
|
: tr('appUpdateChannelSubKeepOld', {
|
|
channel: appUpdateChannel === 'dev' ? tr('appUpdateChannelDev') : tr('appUpdateChannelAlpha'),
|
|
})}
|
|
</div>
|
|
</div>
|
|
<div className="row-right">
|
|
<Segmented
|
|
label={tr('appUpdateChannelTitle')}
|
|
value={appUpdateChannel}
|
|
onChange={(v) => void handleChannelChange(v)}
|
|
options={[
|
|
{ value: 'stable' as AppUpdateChannel, label: tr('appUpdateChannelStable'), disabled: switchingChannel || checkingUpdate || updatePhase === 'downloading' || installing },
|
|
{ value: 'alpha' as AppUpdateChannel, label: tr('appUpdateChannelAlpha'), disabled: switchingChannel || checkingUpdate || updatePhase === 'downloading' || installing },
|
|
{ value: 'dev' as AppUpdateChannel, label: tr('appUpdateChannelDev'), disabled: switchingChannel || checkingUpdate || updatePhase === 'downloading' || installing },
|
|
]}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section className="section">
|
|
<div className="section-title">{tr('aboutCommunity')}</div>
|
|
<div className="list">
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">{tr('helpWebsite')}</div>
|
|
<div className="row-sub">{tr('aboutWebsiteSub')}</div>
|
|
</div>
|
|
<div className="row-right">
|
|
<Button icon={<ExternalLink size={14} aria-hidden="true" />} onClick={() => openURL(siteURL(locale))}>
|
|
{tr('openShort')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">{tr('helpProjectPage')}</div>
|
|
<div className="row-sub">{tr('aboutProjectSub')}</div>
|
|
</div>
|
|
<div className="row-right">
|
|
<Button icon={<ExternalLink size={14} aria-hidden="true" />} onClick={() => openURL(REPO_URL)}>
|
|
{tr('openShort')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">{tr('helpReportIssue')}</div>
|
|
<div className="row-sub">{tr('aboutIssueSub')}</div>
|
|
</div>
|
|
<div className="row-right">
|
|
<Button icon={<ExternalLink size={14} aria-hidden="true" />} onClick={() => openURL(`${REPO_URL}/issues`)}>
|
|
{tr('openShort')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">{tr('aboutLicensesTitle')}</div>
|
|
<div className="row-sub">{tr('aboutLicensesSub')}</div>
|
|
</div>
|
|
<div className="row-right">
|
|
<Button icon={<Scale size={14} aria-hidden="true" />} onClick={() => void openLicenses()}>
|
|
{tr('aboutLicensesView')}
|
|
</Button>
|
|
<Button variant="ghost" icon={<ExternalLink size={14} aria-hidden="true" />} onClick={() => openURL(`${REPO_URL}/blob/main/NOTICE.md`)}>
|
|
{tr('openShort')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">{tr('aboutDiscord')}</div>
|
|
<div className="row-sub">{tr('aboutDiscordSub')}</div>
|
|
</div>
|
|
<div className="row-right">
|
|
{onCopy && (
|
|
<IconButton
|
|
small
|
|
label={tr('aboutCopyDiscord')}
|
|
icon={<Copy size={14} aria-hidden="true" />}
|
|
onClick={() => onCopy(DISCORD_INVITE_URL)}
|
|
/>
|
|
)}
|
|
<Button icon={<ExternalLink size={14} aria-hidden="true" />} onClick={() => openURL(DISCORD_INVITE_URL)}>
|
|
{tr('aboutJoinDiscord')}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">
|
|
{tr('aboutQQGroup')} <span className="mono">{QQ_GROUP_ID}</span>
|
|
{qqInstalled === false && (
|
|
<span className="badge rg-p-badge">{tr('aboutQQNotInstalled')}</span>
|
|
)}
|
|
</div>
|
|
{qqInstalled === false ? (
|
|
<div className="row-sub">{tr('aboutQQNotInstalledSub')}</div>
|
|
) : qqLaunchErr ? (
|
|
<div className="row-sub" title={qqLaunchErr}>{tr('aboutQQLaunchFailed')}</div>
|
|
) : (
|
|
<div className="row-sub">{tr('aboutQQGroupSub')}</div>
|
|
)}
|
|
</div>
|
|
<div className="row-right">
|
|
{qqInstalled && !qqLaunchErr ? (
|
|
<>
|
|
{onCopy && (
|
|
<IconButton
|
|
small
|
|
label={tr('aboutCopyQQGroup')}
|
|
icon={<Copy size={14} aria-hidden="true" />}
|
|
onClick={() => onCopy(QQ_GROUP_ID)}
|
|
/>
|
|
)}
|
|
<Button busy={openingQQ} icon={<ExternalLink size={14} aria-hidden="true" />} onClick={() => void openQQGroup()}>
|
|
{tr('aboutJoinQQGroup')}
|
|
</Button>
|
|
</>
|
|
) : onCopy ? (
|
|
<Button icon={<Copy size={14} aria-hidden="true" />} onClick={() => onCopy(QQ_GROUP_ID)}>
|
|
{tr('aboutCopyQQGroup')}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
{licenseOpen && (
|
|
<Modal
|
|
title={tr('aboutLicensesTitle')}
|
|
subtitle={tr('aboutLicensesSub')}
|
|
closeLabel={tr('close')}
|
|
onClose={() => setLicenseOpen(false)}
|
|
>
|
|
<div className="dialog-body license-modal-body">
|
|
<Segmented
|
|
label={tr('aboutLicensesTitle')}
|
|
value={licenseTab}
|
|
onChange={handleLicenseTabChange}
|
|
options={[
|
|
{ value: 'notice', label: tr('aboutLicensesTabNotice') },
|
|
{ value: 'license', label: tr('aboutLicensesTabLicense') },
|
|
]}
|
|
/>
|
|
<pre
|
|
ref={licensePreRef}
|
|
className="license-pre"
|
|
dir="ltr"
|
|
tabIndex={0}
|
|
role="region"
|
|
aria-label={licenseTab === 'notice' ? tr('aboutLicensesTabNotice') : tr('aboutLicensesTabLicense')}
|
|
>
|
|
{licenses
|
|
? (licenseTab === 'notice' ? licenses.notice : licenses.license)
|
|
: ''}
|
|
</pre>
|
|
</div>
|
|
<div className="dialog-foot">
|
|
<Button
|
|
variant="ghost"
|
|
icon={<ExternalLink size={14} aria-hidden="true" />}
|
|
onClick={() => openURL(`${REPO_URL}/blob/main/${licenseTab === 'notice' ? 'NOTICE.md' : 'LICENSE'}`)}
|
|
>
|
|
{tr('aboutLicensesOpenGitHub')}
|
|
</Button>
|
|
<Button variant="primary" onClick={() => setLicenseOpen(false)}>
|
|
{tr('close')}
|
|
</Button>
|
|
</div>
|
|
</Modal>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|