feat: 设置「插件」页落地——外置插件按来源分组(商店/项目/全局)展示与启停

This commit is contained in:
Rick Ye
2026-09-11 01:03:28 +08:00
parent 8b94d42930
commit 71c91563e8
3 changed files with 98 additions and 16 deletions
+11 -5
View File
@@ -37,6 +37,8 @@ export const EXTERNAL_PLUGINS_ENABLED = !app.isPackaged || process.env.ASO_EXTER
interface ResolvedPlugin {
manifest: PluginManifest
source: 'builtin' | 'external'
/** 外置来源目录类别(管理页分组展示用) */
origin?: 'user' | 'project' | 'global'
/** 外置插件根目录(plugin:// 映射根) */
dir?: string
/** 内置:第一方工厂 / 渲染层组件 key */
@@ -145,10 +147,12 @@ class PluginHost {
}
if (EXTERNAL_PLUGINS_ENABLED) {
const roots = [this.externalRoot]
if (this.projectExtensionsDir) roots.push(this.projectExtensionsDir)
roots.push(join(getAgentDir(), 'extensions'))
for (const root of roots) {
const roots: Array<{ root: string; origin: 'user' | 'project' | 'global' }> = [
{ root: this.externalRoot, origin: 'user' }
]
if (this.projectExtensionsDir) roots.push({ root: this.projectExtensionsDir, origin: 'project' })
roots.push({ root: join(getAgentDir(), 'extensions'), origin: 'global' })
for (const { root, origin } of roots) {
if (!existsSync(root)) continue
let entries: import('node:fs').Dirent[]
try {
@@ -177,11 +181,12 @@ class PluginHost {
manifest,
source: 'external',
dir,
origin,
error: `需要契约版本 >= ${manifest.minContract}(当前 ${HARNESS_CONTRACT_VERSION})`
})
continue
}
byId.set(manifest.id, { manifest, source: 'external', dir })
byId.set(manifest.id, { manifest, source: 'external', dir, origin })
}
}
}
@@ -275,6 +280,7 @@ class PluginHost {
.map((p) => ({
manifest: p.manifest,
source: p.source,
origin: p.origin,
enabled: this.isEnabled(p.manifest.id),
hasMain: Boolean(p.builtinFactory ?? p.externalFactory),
hasPage: Boolean(p.source === 'external' && p.manifest.entry?.page),