feat(plugin,ui): consolidate builtin.core, enforce Guest Tools toggle, and add QQ group entry
- Merge essential builtins (driver, default theme, start prep, host workarounds) into always-on system plugin builtin.core, with state.json and arg-ledger migration plus app-scoped workaround settings honored by both GUI and CLI. - Ensure disabling builtin.bridge.guest-tools stops the localhost bridge without being restarted by feature callers, fix guesttools.Server Start/Close race, and reflect the disabled state in VMPage and SettingsModal. - Add QQ community group entry in About settings with Windows tencent:// protocol detection, cached invite redirect resolution, and copy-ID fallback. - Update docs/plugin-architecture.md, Wails bindings, and i18n strings.
This commit is contained in:
1 parent
007f2ac93c
commit
181c616909
35 files changed
+1432
-578
No files matched your search
@@ -1,14 +1,16 @@
|
||||
import { Download } from 'lucide-react'
|
||||
import { Copy, Download, ExternalLink } from 'lucide-react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { I18nKey, t } from '../i18n'
|
||||
import { findOptimization, optBadgeClass, optStatusLabel } from '../lib/optimizations'
|
||||
import { AppState, AppUpdateInfo, Locale } from '../types'
|
||||
import { Button } from '../ui/controls'
|
||||
import { Button, IconButton } from '../ui/controls'
|
||||
import { Segmented, Switch } from '../ui/settings'
|
||||
import { api } from '../wails'
|
||||
|
||||
export type ThemeMode = 'light' | 'dark' | 'system'
|
||||
|
||||
const QQ_GROUP_ID = '1136042744'
|
||||
|
||||
interface Props {
|
||||
state: AppState
|
||||
locale: Locale
|
||||
@@ -17,18 +19,22 @@ interface Props {
|
||||
canDark?: boolean
|
||||
onThemeMode: (mode: ThemeMode) => void
|
||||
onSetLocale: (l: Locale) => void
|
||||
onCopy?: (text: string) => void
|
||||
onRefresh: () => void
|
||||
onError: (title: string, e: unknown) => void
|
||||
}
|
||||
|
||||
export const AppSettingsPage: React.FC<Props> = ({
|
||||
state, locale, themeMode, canLight = true, canDark = true, onThemeMode, onSetLocale, onRefresh, onError,
|
||||
state, locale, themeMode, canLight = true, canDark = true, onThemeMode, onSetLocale, onCopy, onRefresh, onError,
|
||||
}) => {
|
||||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||||
const { host, config, optimizations } = state
|
||||
const [appUpdate, setAppUpdate] = useState<AppUpdateInfo | null>(null)
|
||||
const [checkingUpdate, setCheckingUpdate] = useState(false)
|
||||
const [updateErr, setUpdateErr] = useState('')
|
||||
const [qqInstalled, setQQInstalled] = useState<boolean | null>(null)
|
||||
const [openingQQ, setOpeningQQ] = useState(false)
|
||||
const [qqLaunchErr, setQQLaunchErr] = useState('')
|
||||
|
||||
const pcoreOpt = findOptimization(optimizations, 'pcore_pin')
|
||||
|
||||
@@ -47,6 +53,11 @@ export const AppSettingsPage: React.FC<Props> = ({
|
||||
|
||||
useEffect(() => {
|
||||
void runUpdateCheck(false)
|
||||
let cancelled = false
|
||||
api.CanOpenQQGroup()
|
||||
.then((ok) => { if (!cancelled) setQQInstalled(!!ok) })
|
||||
.catch(() => { if (!cancelled) setQQInstalled(false) })
|
||||
return () => { cancelled = true }
|
||||
}, [])
|
||||
|
||||
const guard = (fn: () => Promise<unknown>) => async () => {
|
||||
@@ -63,6 +74,27 @@ export const AppSettingsPage: React.FC<Props> = ({
|
||||
if (dir) await api.SetDataRoot(dir)
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="page rg-p-settings">
|
||||
<header className="page-head">
|
||||
@@ -180,7 +212,7 @@ export const AppSettingsPage: React.FC<Props> = ({
|
||||
<Button
|
||||
variant="primary"
|
||||
icon={<Download size={14} aria-hidden="true" />}
|
||||
onClick={() => guard(() => api.OpenURL(appUpdate.page_url || appUpdate.download_url || ''))()}
|
||||
onClick={() => openURL(appUpdate.page_url || appUpdate.download_url || '')}
|
||||
>
|
||||
{tr('appDownloadUpdate')}
|
||||
</Button>
|
||||
@@ -191,6 +223,51 @@ export const AppSettingsPage: React.FC<Props> = ({
|
||||
)}
|
||||
</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">{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>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
AlertTriangle, BadgeCheck, Clipboard, Code2, Cpu, Disc3, FolderOpen, Keyboard,
|
||||
AlertTriangle, BadgeCheck, Boxes, Clipboard, Code2, Cpu, Disc3, FolderOpen, Keyboard,
|
||||
Layers, Monitor, PackagePlus, Palette, Puzzle, RefreshCw, RotateCcw, Search,
|
||||
Settings2, Shield, ShieldAlert, ShieldCheck, Sparkles, Terminal, Trash2,
|
||||
} from 'lucide-react'
|
||||
@@ -33,6 +33,7 @@ interface PluginVisual {
|
||||
}
|
||||
|
||||
function resolvePluginVisual(p: PluginInfo): PluginVisual {
|
||||
if (p.system) return { tone: 'indigo', icon: <Boxes size={19} aria-hidden="true" /> }
|
||||
const id = p.id.toLowerCase()
|
||||
const perms = new Set((p.permissions ?? []).map((x) => x.name))
|
||||
if (id.includes('theme') || perms.has('ui:script')) {
|
||||
@@ -268,7 +269,11 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
return name.includes(q) || desc.includes(q) || p.id.toLowerCase().includes(q)
|
||||
}
|
||||
|
||||
const builtins = useMemo(() => plugins.filter((p) => p.source === 'builtin'), [plugins])
|
||||
// The always-on core goes first; the optional builtins keep backend order.
|
||||
const builtins = useMemo(
|
||||
() => plugins.filter((p) => p.source === 'builtin').sort((a, b) => Number(!!b.system) - Number(!!a.system)),
|
||||
[plugins],
|
||||
)
|
||||
const external = useMemo(() => plugins.filter((p) => p.source !== 'builtin'), [plugins])
|
||||
const filteredBuiltins = useMemo(() => builtins.filter(matchesFilter), [builtins, q, locale])
|
||||
const filteredExternal = useMemo(() => external.filter(matchesFilter), [external, q, locale])
|
||||
@@ -357,12 +362,16 @@ export const PluginsPage: React.FC<Props> = ({
|
||||
onClick={() => setRemoveTarget(p)}
|
||||
/>
|
||||
)}
|
||||
<Switch
|
||||
label={locText(p.name, locale, p.id)}
|
||||
disabled={busyID === p.id || (p.enabled && p.in_use) || (!!safeMode && !isBuiltin)}
|
||||
checked={p.enabled}
|
||||
onChange={(checked) => void togglePlugin(p, checked)}
|
||||
/>
|
||||
{p.system ? (
|
||||
<span className="plugin-row-fixed">{tr('pluginAlwaysOn')}</span>
|
||||
) : (
|
||||
<Switch
|
||||
label={locText(p.name, locale, p.id)}
|
||||
disabled={busyID === p.id || (p.enabled && p.in_use) || (!!safeMode && !isBuiltin)}
|
||||
checked={p.enabled}
|
||||
onChange={(checked) => void togglePlugin(p, checked)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -722,11 +722,12 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, stats, host, op
|
||||
<Switch
|
||||
label={tr('driveShareMaster')}
|
||||
checked={!!driveSettings?.enabled}
|
||||
disabled={!driveSettings || driveBusy}
|
||||
disabled={!driveSettings || driveBusy || !!detail.guest_tools_disabled}
|
||||
onChange={(enabled) => void updateDriveShares(enabled, selectedDrives())}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{detail.guest_tools_disabled && <div className="notice">{tr('gtStatusOffTip')}</div>}
|
||||
{driveErr && <div className="notice" role="alert">{driveErr}</div>}
|
||||
{driveSettings?.enabled && selectedDrives().length > 0 &&
|
||||
(detail.guest_tools_agent_version ?? 0) < driveSettings.required_agent_version && (
|
||||
@@ -739,7 +740,7 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, stats, host, op
|
||||
key={drive.drive}
|
||||
title={title}
|
||||
desc={drive.system ? tr('driveShareSystem', { root: drive.root }) : tr('driveShareDrive', { root: drive.root })}
|
||||
disabled={!driveSettings?.enabled || driveBusy}
|
||||
disabled={!driveSettings?.enabled || driveBusy || !!detail.guest_tools_disabled}
|
||||
reason={!driveSettings?.enabled ? tr('driveShareMasterOff') : undefined}
|
||||
control={
|
||||
<Switch
|
||||
|
||||
@@ -756,12 +756,16 @@ export const VMPage: React.FC<Props> = ({
|
||||
const gtMountMode = stats?.guest_tools_mount_mode || detail.guest_tools_mount_mode || ''
|
||||
const gtSleepActive = stats?.guest_tools_sleep_guard ?? detail.guest_tools_sleep_active ?? false
|
||||
const needsUpgrade = gtConnected && (detail.guest_tools_agent_version ?? 0) > 0 && (detail.guest_tools_agent_version ?? 0) < 3
|
||||
// Plugin switched off: show the state and hide controls that would only fail.
|
||||
const gtOff = !!detail.guest_tools_disabled
|
||||
|
||||
// One status word per state; how files are shared goes in the tooltip.
|
||||
let gtTone: 'ok' | 'warn' | 'idle' = 'idle'
|
||||
let gtStatus: string
|
||||
let gtTip: string
|
||||
if (needsUpgrade) {
|
||||
if (gtOff) {
|
||||
gtStatus = tr('gtStatusOff'); gtTip = tr('gtStatusOffTip')
|
||||
} else if (needsUpgrade) {
|
||||
gtTone = 'warn'; gtStatus = tr('gtStatusUpgrade'); gtTip = tr('guestToolsUpgradeHint')
|
||||
} else if (gtConnected) {
|
||||
gtTone = 'ok'; gtStatus = tr('gtStatusConnected')
|
||||
@@ -772,7 +776,7 @@ export const VMPage: React.FC<Props> = ({
|
||||
} else {
|
||||
gtStatus = tr('gtStatusNone'); gtTip = tr('gtNotInstalledDesc')
|
||||
}
|
||||
const showInstallCmd = detail.guest_tools_attached && (!gtConnected || needsUpgrade)
|
||||
const showInstallCmd = !gtOff && detail.guest_tools_attached && (!gtConnected || needsUpgrade)
|
||||
const sshText = sshUser ? `ssh -p ${detail.ssh_port} ${sshUser}@127.0.0.1` : sshCommand(detail.ssh_port)
|
||||
|
||||
return (
|
||||
@@ -830,7 +834,7 @@ export const VMPage: React.FC<Props> = ({
|
||||
</Tip>
|
||||
</div>
|
||||
<div className="conn-ctrl">
|
||||
{detail.guest_tools_attached ? (
|
||||
{gtOff ? null : detail.guest_tools_attached ? (
|
||||
<Button busy={busyAction === 'detachGuestTools'} disabled={busy} onClick={() => onAction('detachGuestTools')}>
|
||||
{tr('detachGuestTools')}
|
||||
</Button>
|
||||
@@ -864,7 +868,7 @@ export const VMPage: React.FC<Props> = ({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{tools && (
|
||||
{tools && !gtOff && (
|
||||
<div className="conn-row">
|
||||
<div className="conn-main">
|
||||
<span className="conn-title">{tr('sharedFolder')}</span>
|
||||
@@ -876,7 +880,7 @@ export const VMPage: React.FC<Props> = ({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{tools && (
|
||||
{tools && !gtOff && (
|
||||
<div className="conn-row">
|
||||
<div className="conn-main">
|
||||
<span className="conn-title">{tr('guestToolsPreventSleep')}</span>
|
||||
|
||||
Reference in new issue
Block a user