183 lines
7.4 KiB
TypeScript
183 lines
7.4 KiB
TypeScript
import {
|
|
Activity, BadgeCheck, Binary, Clipboard, Code2, Files, Globe,
|
|
Keyboard, Monitor, PanelsTopLeft, Search, ShieldAlert, ShieldCheck, Users,
|
|
} from 'lucide-react'
|
|
import React from 'react'
|
|
import '../i18n/domains/plugins.gen'
|
|
import { I18nKey, locText, t } from '../i18n'
|
|
import { Locale, PluginInfo, ScanReport } from '../types'
|
|
import { Tip } from '../ui/controls'
|
|
|
|
export { PluginAppIcon, resolvePluginVisual, type PluginVisual, type PluginVisualSource } from './PluginAppIcon'
|
|
|
|
/** Selects the accurate high-risk warning notice for a plugin (L3 native vs ui:script). */
|
|
export function resolvePluginApprovalNotice(
|
|
plugin: Pick<PluginInfo, 'tier' | 'permissions'>,
|
|
report: Pick<ScanReport, 'native_exec_notice'> | null | undefined,
|
|
locale: Locale,
|
|
): string {
|
|
if (plugin.tier === 'L3') {
|
|
return report?.native_exec_notice
|
|
? locText(report.native_exec_notice, locale, t(locale, 'pluginApproveL3Warn'))
|
|
: t(locale, 'pluginApproveL3Warn')
|
|
}
|
|
if ((plugin.permissions ?? []).some((p) => p.name === 'ui:script')) {
|
|
return t(locale, 'pluginApproveUIScriptWarn')
|
|
}
|
|
return ''
|
|
}
|
|
|
|
/** Publisher + trust-tier mark shared by Installed rows and Market cards. */
|
|
export const PluginTrustBadge: React.FC<{
|
|
locale: Locale
|
|
trust: string
|
|
publisher?: string
|
|
}> = ({ locale, trust, publisher }) => {
|
|
const tr = (k: I18nKey) => t(locale, k)
|
|
const meta = trust === 'official'
|
|
? { cls: 'is-official', icon: <BadgeCheck size={13} aria-hidden="true" />, label: tr('pluginTrustOfficial') }
|
|
: trust === 'verified'
|
|
? { cls: 'is-verified', icon: <ShieldCheck size={13} aria-hidden="true" />, label: tr('pluginTrustVerified') }
|
|
: trust === 'dev'
|
|
? { cls: 'is-dev', icon: <Code2 size={13} aria-hidden="true" />, label: tr('pluginTrustDev') }
|
|
: { cls: 'is-community', icon: <Users size={13} aria-hidden="true" />, label: tr('pluginTrustCommunity') }
|
|
return (
|
|
<Tip label={meta.label}>
|
|
<span className={`plugin-trust ${meta.cls}`} tabIndex={0}>
|
|
{meta.icon}
|
|
<span className="plugin-trust-name">{publisher || meta.label}</span>
|
|
</span>
|
|
</Tip>
|
|
)
|
|
}
|
|
|
|
/** Search input with leading magnifying glass, shared by Installed and Market. */
|
|
export const PluginSearchInput: React.FC<{
|
|
value: string
|
|
onChange: (value: string) => void
|
|
placeholder: string
|
|
wide?: boolean
|
|
}> = ({ value, onChange, placeholder, wide }) => (
|
|
<div className={`plugin-search-wrap${wide ? ' is-wide' : ''}`}>
|
|
<Search size={13} className="plugin-search-icon" aria-hidden="true" />
|
|
<input
|
|
type="search"
|
|
className="input rg-p-input plugin-search"
|
|
aria-label={placeholder}
|
|
placeholder={placeholder}
|
|
value={value}
|
|
onChange={(e) => onChange(e.target.value)}
|
|
/>
|
|
</div>
|
|
)
|
|
|
|
const RISKS: Record<string, { key: I18nKey; icon: React.ReactNode; high: boolean }> = {
|
|
native: { key: 'pluginRiskNative', icon: <Binary size={15} aria-hidden="true" />, high: true },
|
|
background: { key: 'pluginRiskBackground', icon: <Activity size={15} aria-hidden="true" />, high: true },
|
|
network: { key: 'pluginRiskNetwork', icon: <Globe size={15} aria-hidden="true" />, high: true },
|
|
files: { key: 'pluginRiskFiles', icon: <Files size={15} aria-hidden="true" />, high: true },
|
|
vm: { key: 'pluginRiskVm', icon: <Monitor size={15} aria-hidden="true" />, high: true },
|
|
clipboard: { key: 'pluginRiskClipboard', icon: <Clipboard size={15} aria-hidden="true" />, high: true },
|
|
input: { key: 'pluginRiskInput', icon: <Keyboard size={15} aria-hidden="true" />, high: false },
|
|
ui: { key: 'pluginRiskUi', icon: <PanelsTopLeft size={15} aria-hidden="true" />, high: false },
|
|
}
|
|
|
|
/** Plain-language list of what a plugin can do (backend risk categories). */
|
|
export const RiskList: React.FC<{ locale: Locale; risks?: string[] }> = ({ locale, risks }) => {
|
|
const known = (risks ?? []).filter((r) => RISKS[r])
|
|
if (known.length === 0) return null
|
|
return (
|
|
<ul className="plugin-risk-list">
|
|
{known.map((r) => (
|
|
<li key={r} className={`plugin-risk${RISKS[r].high ? ' is-high' : ''}`}>
|
|
<span className="plugin-risk-icon">{RISKS[r].icon}</span>
|
|
<span>{t(locale, RISKS[r].key)}</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)
|
|
}
|
|
|
|
/** High-risk approval disclosure shared by Installed approval and Market enable flows. */
|
|
export const PluginApprovalBody: React.FC<{
|
|
locale: Locale
|
|
plugin: PluginInfo
|
|
report?: ScanReport | null
|
|
}> = ({ locale, plugin, report }) => {
|
|
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
|
const warnText = resolvePluginApprovalNotice(plugin, report, locale)
|
|
return (
|
|
<>
|
|
{warnText && (
|
|
<div className="notice notice-warn">
|
|
<span className="notice-main">
|
|
<ShieldAlert size={15} className="notice-icon" aria-hidden="true" />
|
|
<span>{warnText}</span>
|
|
</span>
|
|
</div>
|
|
)}
|
|
<RiskList locale={locale} risks={plugin.risks} />
|
|
<div className="list">
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">{tr('pluginPublisherLicense')}</div>
|
|
<div className="row-sub">{plugin.publisher || '—'} · {plugin.license || '—'}</div>
|
|
</div>
|
|
</div>
|
|
{plugin.entry_path && (
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">{tr('pluginEntryPath')}</div>
|
|
<div className="row-sub mono selectable">{plugin.entry_path}</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
{plugin.entry_hash && (
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">SHA-256</div>
|
|
<div className="row-sub mono selectable">{plugin.entry_hash}</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
<div className="row">
|
|
<div className="row-main">
|
|
<div className="row-title">{tr('pluginRequestedPerms')}</div>
|
|
<div className="row-sub mono">
|
|
{(plugin.permissions ?? []).length > 0
|
|
? (plugin.permissions ?? []).map((p) => `${p.name} (${p.level})`).join(', ')
|
|
: '—'}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{(report?.capabilities?.length ?? 0) > 0 && (
|
|
<div className="plugin-scan-section">
|
|
<div className="plugin-scan-section-title">{tr('pluginScanCapabilitiesSection')}</div>
|
|
<div className="list">
|
|
{report!.capabilities!.map((c) => (
|
|
<div className="row" key={c.id}>
|
|
<div className="row-main">
|
|
<div className="row-title">
|
|
<span className={`badge rg-p-badge${c.level === 'high' ? ' badge-warn' : ''}`}>{c.level.toUpperCase()}</span>
|
|
<span>{locText(c.title, locale, c.id)}</span>
|
|
</div>
|
|
<div className="row-sub">{locText(c.summary, locale, '')}</div>
|
|
{(c.examples?.length ?? 0) > 0 && (
|
|
<div className="plugin-scan-examples mono">
|
|
{c.examples!.map((ex, i) => <div key={i}>· {ex}</div>)}
|
|
{(c.extra_count ?? 0) > 0 && (
|
|
<div className="muted">· {tr('pluginScanMoreItems', { count: c.extra_count! })}</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</>
|
|
)
|
|
}
|