fix(plugins): 启动一律加载脚本(注册≠启用),加载后按持久化状态激活;修「关闭后再也打不开/未加载」
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m22s
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m22s
This commit is contained in:
1 parent
9b24749481
commit
d83f7f5eef
1 file changed
+14
-1
@@ -8600,10 +8600,23 @@ items.push(el('button', { key: 'bgc', className: 'iwb-ctx-item', onClick: (e) =>
|
||||
// 只下载已启用的;未启用记 idle(不注入脚本),插件管理里勾选时经 wEnsurePluginLoaded 按需下载
|
||||
// 收进 pending 而非逐个 await:wLoadPluginEntry 在首个 await 前已 append ⇒ 并发抓取;async=false 保证执行顺序不变(冷启动 3 RTT → 1)
|
||||
// 本地开发插件默认启用(没有持久化状态,不应被当作已关闭的插件)
|
||||
if (PluginHost && typeof PluginHost.isEnabled === 'function' && (isLocalEntry || PluginHost.isEnabled(id))) pending.push(isLocalEntry ? wLoadLocalPluginEntry(record) : (isExt ? wLoadExternalPluginEntry(record) : wLoadPluginEntry(record)))
|
||||
// 一律加载脚本(注册 ≠ 启用):脚本注册后才能被开关随时启停;
|
||||
// 之前按 enabled 预筛,导致状态里残留 false 的插件永远进不了注册表,开关也打不开。
|
||||
if (PluginHost) pending.push(isLocalEntry ? wLoadLocalPluginEntry(record) : (isExt ? wLoadExternalPluginEntry(record) : wLoadPluginEntry(record)))
|
||||
else record.status = 'idle'
|
||||
}
|
||||
await Promise.all(pending)
|
||||
// 脚本都注册了:把持久化里明确关掉的插件停用(其余保持启用)
|
||||
try {
|
||||
const st = lsGet('iwb_plugins', {}) || {}
|
||||
for (const r of (wRuntimePlugins || [])) {
|
||||
if (!r || r.status !== 'loaded') continue
|
||||
const rec = st[r.id]
|
||||
if (rec && rec.enabled === false && PluginHost && typeof PluginHost.setEnabled === 'function') {
|
||||
if (typeof PluginHost.isEnabled === 'function' && PluginHost.isEnabled(r.id)) PluginHost.setEnabled(r.id, false)
|
||||
}
|
||||
}
|
||||
} catch (e) { /* 状态应用失败不影响加载 */ }
|
||||
try { lsSet('iwb_plugin_load_status', JSON.stringify(wRuntimePlugins.map((r) => ({ id: r.id, status: r.status, source: r.source, error: r.error || '' })))) } catch (e2) { /* probe */ }
|
||||
try { if (PluginHost && typeof PluginHost.emit === 'function') PluginHost.emit('runtime-plugins-loaded') } catch (e) { /* 通知失败不影响启动 */ }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user