fix: renderer 模块改经 IPC+Blob URL 装载(绕开 dev http 源 CORS);插件页改为全局/项目作用域切换
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
* ed25519 验签 + 开发者模式豁免)。
|
||||
*/
|
||||
import { app, BrowserWindow, net, protocol } from 'electron'
|
||||
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'
|
||||
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs'
|
||||
import { join, resolve, sep } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { getAgentDir } from '@earendil-works/pi-coding-agent'
|
||||
@@ -296,6 +296,29 @@ class PluginHost {
|
||||
return p?.componentKey
|
||||
}
|
||||
|
||||
/** 外置插件来源目录(管理页「打开目录」用) */
|
||||
pluginDirs(): { user: string[]; project: string[]; global: string[] } {
|
||||
return {
|
||||
user: [this.externalRoot],
|
||||
project: this.projectExtensionsDir ? [this.projectExtensionsDir] : [],
|
||||
global: [join(getAgentDir(), 'extensions')]
|
||||
}
|
||||
}
|
||||
|
||||
/** 读取外置插件渲染层模块源码。渲染层取回后以 Blob URL import——
|
||||
* dev 下页面源是 http://localhost,直接 import(plugin://) 会被 CORS 拦截。 */
|
||||
readRendererSource(id: string): string {
|
||||
if (!EXTERNAL_PLUGINS_ENABLED) throw new Error('第三方插件装载已关闭(用户版构建)')
|
||||
const plugin = this.resolved.get(id)
|
||||
const file =
|
||||
plugin?.source === 'external' && plugin.manifest.entry?.renderer
|
||||
? resolve(plugin.dir!, plugin.manifest.entry.renderer)
|
||||
: null
|
||||
if (!file || !existsSync(file)) throw new Error(`插件 ${id} 未提供渲染层模块`)
|
||||
if (statSync(file).size > 8 * 1024 * 1024) throw new Error('渲染层模块超过 8MB 上限')
|
||||
return readFileSync(file, 'utf8')
|
||||
}
|
||||
|
||||
uiState(): PluginsUiState {
|
||||
const status: PluginStatusEntry[] = []
|
||||
for (const [pluginId, items] of this.statusItems) {
|
||||
|
||||
Reference in New Issue
Block a user