fix: 插件市场直接安装推荐版本(#195)
This commit is contained in:
1 parent
1e1649ed03
commit
c7419e7196
7 files changed
+12
-145
No files matched your search
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"group": "improvements",
|
||||
"order": 0,
|
||||
"authors": ["cosimawei"],
|
||||
"zh": "在插件市场点击安装或更新时直接使用市场推荐的最新版本。",
|
||||
"en": "Install or update directly to the latest version offered by the plugin market."
|
||||
}
|
||||
@@ -34,20 +34,6 @@ function formatCompactCount(n: number): string {
|
||||
return String(n)
|
||||
}
|
||||
|
||||
function formatByteSize(bytes?: number): string {
|
||||
if (!bytes || bytes <= 0) return ''
|
||||
if (bytes >= 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
|
||||
if (bytes >= 1024) return `${Math.max(1, Math.round(bytes / 1024))} KB`
|
||||
return `${bytes} B`
|
||||
}
|
||||
|
||||
function formatShortDate(iso?: string): string {
|
||||
if (!iso) return ''
|
||||
const ms = Date.parse(iso)
|
||||
if (Number.isNaN(ms)) return ''
|
||||
return new Date(ms).toISOString().slice(0, 10)
|
||||
}
|
||||
|
||||
function parseTimestamp(iso?: string): number {
|
||||
if (!iso) return 0
|
||||
const ms = Date.parse(iso)
|
||||
@@ -62,20 +48,6 @@ function compositeScore(item: MarketCatalogItem, nowMs: number): number {
|
||||
return recency + downloads
|
||||
}
|
||||
|
||||
function entryReleases(item: MarketCatalogItem) {
|
||||
const e = item.entry
|
||||
if (e.releases && e.releases.length > 0) return e.releases
|
||||
return [{
|
||||
version: e.version,
|
||||
channel: e.channel || 'stable',
|
||||
download_url: e.download_url,
|
||||
sha256: e.sha256,
|
||||
size_bytes: e.size_bytes,
|
||||
published_at: e.updated_at,
|
||||
changelog: e.changelog,
|
||||
}]
|
||||
}
|
||||
|
||||
interface Props {
|
||||
locale: Locale
|
||||
safeMode?: boolean
|
||||
@@ -102,7 +74,6 @@ export const PluginMarket: React.FC<Props> = ({
|
||||
const [query, setQuery] = useState('')
|
||||
const [kind, setKind] = useState('')
|
||||
const [sortBy, setSortBy] = useState<MarketSortMode>('composite')
|
||||
const [versionPick, setVersionPick] = useState<{ item: MarketCatalogItem; selected: string } | null>(null)
|
||||
const [result, setResult] = useState<MarketBrowseResult | null>(null)
|
||||
const [syncing, setSyncing] = useState(false)
|
||||
const [refreshing, setRefreshing] = useState(false)
|
||||
@@ -277,22 +248,13 @@ export const PluginMarket: React.FC<Props> = ({
|
||||
advancePrompt()
|
||||
}
|
||||
|
||||
const openVersionPicker = (item: MarketCatalogItem) => {
|
||||
const list = entryReleases(item)
|
||||
const defaultVer = list.find((r) => r.version === item.entry.version)?.version ?? list[0]?.version ?? item.entry.version
|
||||
setVersionPick({ item, selected: defaultVer })
|
||||
}
|
||||
|
||||
const install = async (item: MarketCatalogItem, version?: string) => {
|
||||
const install = async (item: MarketCatalogItem) => {
|
||||
const id = item.entry.id
|
||||
if (installingRef.current.has(id)) return
|
||||
installingRef.current.add(id)
|
||||
const rel = entryReleases(item).find((r) => r.version === version)
|
||||
setProgress((prev) => ({ ...prev, [id]: { id, phase: 'download', done: 0, total: rel?.size_bytes ?? item.entry.size_bytes ?? 0 } }))
|
||||
setProgress((prev) => ({ ...prev, [id]: { id, phase: 'download', done: 0, total: item.entry.size_bytes ?? 0 } }))
|
||||
try {
|
||||
const info = version
|
||||
? await api.InstallMarketPluginVersion(id, version)
|
||||
: await api.InstallMarketPlugin(id, true)
|
||||
const info = await api.InstallMarketPluginVersion(id, item.entry.version)
|
||||
await onChanged({})
|
||||
if (info && !info.enabled) {
|
||||
if (promptTargetIDRef.current) {
|
||||
@@ -372,7 +334,7 @@ export const PluginMarket: React.FC<Props> = ({
|
||||
return (
|
||||
<Tip label={tr('pluginMarketVersionTip', { installed: item.installed_version ?? '', version: e.version })}>
|
||||
<span>
|
||||
<Button className="market-btn" variant="primary" disabled={!!safeMode} icon={<Download size={13} aria-hidden="true" />} onClick={() => openVersionPicker(item)}>
|
||||
<Button className="market-btn" variant="primary" disabled={!!safeMode} icon={<Download size={13} aria-hidden="true" />} onClick={() => void install(item)}>
|
||||
{tr('pluginMarketUpdateShort')}
|
||||
</Button>
|
||||
</span>
|
||||
@@ -380,7 +342,7 @@ export const PluginMarket: React.FC<Props> = ({
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Button className="market-btn" disabled={!!safeMode} icon={<Download size={13} aria-hidden="true" />} onClick={() => openVersionPicker(item)}>
|
||||
<Button className="market-btn" disabled={!!safeMode} icon={<Download size={13} aria-hidden="true" />} onClick={() => void install(item)}>
|
||||
{tr('pluginMarketInstall')}
|
||||
</Button>
|
||||
)
|
||||
@@ -536,73 +498,6 @@ export const PluginMarket: React.FC<Props> = ({
|
||||
</>
|
||||
)}
|
||||
|
||||
{versionPick && (
|
||||
<Modal
|
||||
title={tr('pluginMarketPickVersionTitle')}
|
||||
subtitle={locText(versionPick.item.entry.name, locale, versionPick.item.entry.id)}
|
||||
closeLabel={tr('close')}
|
||||
onClose={() => setVersionPick(null)}
|
||||
>
|
||||
<div className="dialog-body">
|
||||
<div className="market-version-list" role="radiogroup" aria-label={tr('pluginMarketPickVersionTitle')}>
|
||||
{entryReleases(versionPick.item).map((rel) => {
|
||||
const selected = versionPick.selected === rel.version
|
||||
const isCurrent = versionPick.item.installed && versionPick.item.installed_version === rel.version
|
||||
const notes = locText(rel.changelog, locale, '')
|
||||
const date = formatShortDate(rel.published_at)
|
||||
const size = formatByteSize(rel.size_bytes)
|
||||
return (
|
||||
<label
|
||||
key={rel.version}
|
||||
className={`market-version-opt${selected ? ' is-selected' : ''}`}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
name="market-version"
|
||||
checked={selected}
|
||||
onChange={() => setVersionPick({ ...versionPick, selected: rel.version })}
|
||||
/>
|
||||
<div className="market-version-main">
|
||||
<div className="market-version-head">
|
||||
<span className="market-card-version">v{rel.version}</span>
|
||||
{rel.channel === 'alpha' && (
|
||||
<span className="market-alpha-badge">{tr('pluginMarketAlphaTag')}</span>
|
||||
)}
|
||||
{isCurrent && (
|
||||
<span className="market-version-current">{tr('pluginMarketCurrentVersion')}</span>
|
||||
)}
|
||||
<span className="market-version-meta">
|
||||
{[date, size].filter(Boolean).join(' · ')}
|
||||
</span>
|
||||
</div>
|
||||
{notes && <p className="market-version-notes">{notes}</p>}
|
||||
</div>
|
||||
</label>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="dialog-foot">
|
||||
<span />
|
||||
<span className="hstack">
|
||||
<Button variant="ghost" onClick={() => setVersionPick(null)}>{tr('cancel')}</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
disabled={!versionPick.selected || !!safeMode}
|
||||
icon={<Download size={13} aria-hidden="true" />}
|
||||
onClick={() => {
|
||||
const target = versionPick
|
||||
setVersionPick(null)
|
||||
void install(target.item, target.selected)
|
||||
}}
|
||||
>
|
||||
{tr('pluginMarketPickVersionInstall')}
|
||||
</Button>
|
||||
</span>
|
||||
</div>
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{prompt && (
|
||||
<Modal
|
||||
title={tr('pluginEnablePromptTitle', { name: locText(prompt.name, locale, prompt.id) })}
|
||||
|
||||
@@ -48,7 +48,6 @@ export const pluginsZh: Record<string, string> = {
|
||||
"pluginLinkDevBtn": "链接插件开发目录",
|
||||
"pluginLinkDevTitle": "链接本地开发插件目录",
|
||||
"pluginMarketAlphaTag": "Alpha",
|
||||
"pluginMarketCurrentVersion": "当前已安装",
|
||||
"pluginMarketDownloading": "下载中",
|
||||
"pluginMarketEmpty": "当前插件市场暂无可用条目,你仍可导入本地 .zip 插件包或配置自定义市场索引地址",
|
||||
"pluginMarketFeedEnd": "共 {count} 个插件",
|
||||
@@ -64,8 +63,6 @@ export const pluginsZh: Record<string, string> = {
|
||||
"pluginMarketKindTheme": "主题",
|
||||
"pluginMarketKindTool": "工具",
|
||||
"pluginMarketLoading": "正在读取插件市场",
|
||||
"pluginMarketPickVersionInstall": "安装此版本",
|
||||
"pluginMarketPickVersionTitle": "选择安装版本",
|
||||
"pluginMarketRefresh": "刷新索引",
|
||||
"pluginMarketSearchPlaceholder": "搜索市场插件、作者或标签",
|
||||
"pluginMarketSortComposite": "综合排序",
|
||||
@@ -173,7 +170,6 @@ export const pluginsEn: Record<string, string> = {
|
||||
"pluginLinkDevBtn": "Link plugin dev folder",
|
||||
"pluginLinkDevTitle": "Link local dev plugin folder",
|
||||
"pluginMarketAlphaTag": "Alpha",
|
||||
"pluginMarketCurrentVersion": "Installed",
|
||||
"pluginMarketDownloading": "Downloading",
|
||||
"pluginMarketEmpty": "No plugins available in the market index yet. You can still import local .zip packages or configure a custom index URL.",
|
||||
"pluginMarketFeedEnd": "{count} plugins",
|
||||
@@ -189,8 +185,6 @@ export const pluginsEn: Record<string, string> = {
|
||||
"pluginMarketKindTheme": "Themes",
|
||||
"pluginMarketKindTool": "Tools",
|
||||
"pluginMarketLoading": "Loading the plugin market",
|
||||
"pluginMarketPickVersionInstall": "Install version",
|
||||
"pluginMarketPickVersionTitle": "Select version",
|
||||
"pluginMarketRefresh": "Refresh index",
|
||||
"pluginMarketSearchPlaceholder": "Search market plugins, publishers, or tags",
|
||||
"pluginMarketSortComposite": "Recommended",
|
||||
|
||||
@@ -799,7 +799,6 @@ export type I18nKey =
|
||||
| "pluginLinkDevBtn"
|
||||
| "pluginLinkDevTitle"
|
||||
| "pluginMarketAlphaTag"
|
||||
| "pluginMarketCurrentVersion"
|
||||
| "pluginMarketDownloading"
|
||||
| "pluginMarketEmpty"
|
||||
| "pluginMarketFeedEnd"
|
||||
@@ -815,8 +814,6 @@ export type I18nKey =
|
||||
| "pluginMarketKindTheme"
|
||||
| "pluginMarketKindTool"
|
||||
| "pluginMarketLoading"
|
||||
| "pluginMarketPickVersionInstall"
|
||||
| "pluginMarketPickVersionTitle"
|
||||
| "pluginMarketRefresh"
|
||||
| "pluginMarketSearchPlaceholder"
|
||||
| "pluginMarketSortComposite"
|
||||
|
||||
@@ -1878,26 +1878,6 @@ button.status-issue + .status-metric { margin-left: 6px; }
|
||||
border-radius: 4px; font-size: 10px; font-weight: 600; flex-shrink: 0;
|
||||
color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, transparent);
|
||||
}
|
||||
.market-version-list { display: flex; flex-direction: column; gap: 8px; }
|
||||
.market-version-opt {
|
||||
display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
|
||||
border-radius: var(--r-md); border: 1px solid var(--border);
|
||||
background: var(--surface-1); cursor: pointer;
|
||||
}
|
||||
.market-version-opt.is-selected {
|
||||
border-color: var(--accent);
|
||||
background: color-mix(in srgb, var(--accent) 6%, var(--surface-1));
|
||||
}
|
||||
.market-version-opt input[type='radio'] { margin-top: 3px; flex-shrink: 0; }
|
||||
.market-version-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
|
||||
.market-version-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: var(--fs-13); }
|
||||
.market-version-current {
|
||||
display: inline-flex; align-items: center; padding: 0 5px; height: 16px;
|
||||
border-radius: 4px; font-size: 10px; font-weight: 600;
|
||||
color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
|
||||
}
|
||||
.market-version-meta { margin-left: auto; font-size: var(--fs-12); color: var(--text-3); font-variant-numeric: tabular-nums; }
|
||||
.market-version-notes { margin: 0; font-size: var(--fs-12); color: var(--text-2); line-height: 1.45; }
|
||||
.plugin-title-link { color: inherit; text-decoration: none; }
|
||||
.plugin-title-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
|
||||
.market-card-action { flex-shrink: 0; }
|
||||
|
||||
@@ -108,9 +108,6 @@
|
||||
"pluginMarketSortDownloads": "Most downloads",
|
||||
"pluginMarketSortRecent": "Recently updated",
|
||||
"pluginMarketAlphaTag": "Alpha",
|
||||
"pluginMarketPickVersionTitle": "Select version",
|
||||
"pluginMarketPickVersionInstall": "Install version",
|
||||
"pluginMarketCurrentVersion": "Installed",
|
||||
"pluginEnablePromptTitle": "“{name}” is installed",
|
||||
"pluginEnablePromptBody": "Enable it now? Here is what it can do:",
|
||||
"pluginEnablePromptNoRisk": "This plugin declares no extra capabilities.",
|
||||
|
||||
@@ -108,9 +108,6 @@
|
||||
"pluginMarketSortDownloads": "最多下载",
|
||||
"pluginMarketSortRecent": "最新发布",
|
||||
"pluginMarketAlphaTag": "Alpha",
|
||||
"pluginMarketPickVersionTitle": "选择安装版本",
|
||||
"pluginMarketPickVersionInstall": "安装此版本",
|
||||
"pluginMarketCurrentVersion": "当前已安装",
|
||||
"pluginEnablePromptTitle": "「{name}」已安装",
|
||||
"pluginEnablePromptBody": "要现在启用吗?启用前请了解它会做什么:",
|
||||
"pluginEnablePromptNoRisk": "此插件没有声明额外能力,可以放心启用。",
|
||||
|
||||
Reference in new issue
Block a user