feat(plugin): 插件目录化 M1 —— 目录插件加载 + 旧单文件兼容 v3.25.41

- loader 新增 loadFolder():manifest → main.js(逐文件 sha256,内置信随包 index.json)→ blob 注入;
  样式文本暂存,激活时注入、停用时移除(配合 host 新增 onActivate/onDeactivate 钩子)
- storage-file 增加 plugins.listDirs/readFile/writeFile/writeBinary/mkdir/removeDir(按段校验,禁 ..)
- app.js:三路合并支持目录条目(dir/main/style/files),失败隔离 + 按 id 排序
- 修复:无 iwb_plugins 记录时插件永不激活(首次安装面板显示「未加载」)
- 备份模块兼容目录形态;市场暂时跳过目录插件(M3 zip 后恢复)
- 试点:image-annotate 转为 plugins/image-annotate/{manifest.json,main.js}
- 方案文档 docs/PLUGIN-ARCHITECTURE-PLAN.md 一并入库
This commit is contained in:
qiqi committed 2026-11-20 09:08:56 +08:00
1 parent 8dbc0c0603
commit 7ed3ba6738
17 files changed
+673 -22

No files matched your search

+7
View File
@@ -77,6 +77,11 @@
if (!Number.isInteger(manifest.apiVersion) || manifest.apiVersion < 1) return '清单 apiVersion 必须是正整数'
if (!Array.isArray(manifest.capabilities)) return '清单 capabilities 必须是数组'
if (manifest.settings !== undefined && (typeof manifest.settings !== 'object' || manifest.settings === null || Array.isArray(manifest.settings))) return '清单 settings 必须是对象'
// v3.25.41 目录插件(可选字段):入口/样式/权限/数据声明
if (manifest.main !== undefined && (typeof manifest.main !== 'string' || !/\.js$/.test(manifest.main))) return '清单 main 必须是 .js 文件名'
if (manifest.style !== undefined && (typeof manifest.style !== 'string' || !/\.css$/.test(manifest.style))) return '清单 style 必须是 .css 文件名'
if (manifest.permissions !== undefined && (!Array.isArray(manifest.permissions) || manifest.permissions.some((x) => typeof x !== 'string'))) return '清单 permissions 必须是字符串数组'
if (manifest.data !== undefined && (typeof manifest.data !== 'object' || manifest.data === null || Array.isArray(manifest.data))) return '清单 data 必须是对象'
for (const name of manifest.capabilities) {
if (CAPABILITIES.indexOf(name) < 0) return '未知能力 ' + name
}
@@ -192,6 +197,7 @@
record.active = true
record.instance = instance || null
record.error = null
if (deps && typeof deps.onActivate === 'function') { try { deps.onActivate(id) } catch (error) { log('plugin-activate-hook-failed', id, error && error.message) } }
notify({ kind: 'lifecycle', id, active: true })
return { ok: true, id }
}
@@ -215,6 +221,7 @@
for (const api of record.capabilityApis.splice(0)) {
try { if (api && typeof api.dispose === 'function') api.dispose() } catch (error) { log('plugin-capability-dispose-failed', id, error && error.message) }
}
if (deps && typeof deps.onDeactivate === 'function') { try { deps.onDeactivate(id) } catch (error) { log('plugin-deactivate-hook-failed', id, error && error.message) } }
notify({ kind: 'lifecycle', id, active: false })
return { ok: true, id }
}