From 5dba56363a316f4c5e9b6f28a8195013465c02bc Mon Sep 17 00:00:00 2001 From: qiqi Date: Tue, 17 Nov 2026 16:47:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(plugins):=20=E5=8A=A0=E8=BD=BD=E9=98=B6?= =?UTF-8?q?=E6=AE=B5=E4=B8=8D=E5=86=8D=E5=86=99=E5=90=AF=E7=94=A8=E7=8A=B6?= =?UTF-8?q?=E6=80=81=EF=BC=9B=E5=90=AF=E5=8A=A8=E6=97=B6=E5=85=88=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E7=94=A8=E6=88=B7=E5=BC=80=E5=85=B3=E5=86=8D=E5=8F=8C?= =?UTF-8?q?=E5=90=91=E5=BA=94=E7=94=A8=EF=BC=88=E5=85=B3=E6=8E=89=E7=9A=84?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E9=87=8D=E5=90=AF=E5=90=8E=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E5=85=B3=E9=97=AD=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 12 ++++++++---- src/runtime-plugin-loader.js | 5 ++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index c0fb9fe..b403822 100644 --- a/app.js +++ b/app.js @@ -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 */ } diff --git a/src/runtime-plugin-loader.js b/src/runtime-plugin-loader.js index d8234a9..4043e93 100644 --- a/src/runtime-plugin-loader.js +++ b/src/runtime-plugin-loader.js @@ -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' }