fix(plugins): 加载阶段不再写启用状态;启动时先快照用户开关再双向应用(关掉的插件重启后保持关闭)
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m21s

This commit is contained in:
qiqi committed 2026-11-17 16:47:18 +08:00
1 parent d83f7f5eef
commit 5dba56363a
2 files changed
+10 -7

No files matched your search

+8 -4
View File
@@ -8579,6 +8579,8 @@ items.push(el('button', { key: 'bgc', className: 'iwb-ctx-item', onClick: (e) =>
}
} catch (e) { /* 开发者模式读取失败不影响启动 */ }
for (const e of ext) { const id = String((e && e.id) || ''); if (id) byId.set(id, Object.assign({}, e, { source: 'external' })) }
// 关键:加载前先快照「用户关掉过哪些插件」,加载过程绝不能覆盖这个状态
const persistedState = (function () { try { const v = lsGet('iwb_plugins', {}); return (v && typeof v === 'object') ? v : {} } catch (e) { return {} } })()
const manifest = Array.from(byId.values())
if (!manifest.length) return
const list = Array.isArray(manifest) ? manifest : (manifest && Array.isArray(manifest.plugins) ? manifest.plugins : [])
@@ -8608,13 +8610,15 @@ items.push(el('button', { key: 'bgc', className: 'iwb-ctx-item', onClick: (e) =>
await Promise.all(pending)
// 脚本都注册了:把持久化里明确关掉的插件停用(其余保持启用)
try {
const st = lsGet('iwb_plugins', {}) || {}
const st = persistedState || {}
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)
}
const want = !(rec && rec.enabled === false)
if (!PluginHost || typeof PluginHost.setEnabled !== 'function') continue
if (typeof PluginHost.isEnabled !== 'function') continue
if (want && !PluginHost.isEnabled(r.id)) PluginHost.setEnabled(r.id, true)
else if (!want && 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 */ }
+2 -3
View File
@@ -46,9 +46,8 @@
const H = host()
const registered = !!(H && typeof H.list === 'function' && H.list().some(function (p) { return p.id === record.id }))
record.status = registered ? 'loaded' : 'not-registered'
// 自愈:只要脚本成功注册,就把启用状态写回 true
// (此前只在「已经启用」时写,导致状态里残留的 false 永远翻不回来,界面显示已加载但开关是关的)
if (registered) { try { H.setEnabled(record.id, true) } catch (e) { /* ignore */ } }
// 不在加载阶段写启用状态:否则会把用户关掉的插件又打开
// (启用/停用由 app.js 加载完成后按持久化状态统一应用)
return record.status === 'loaded'
}