diff --git a/src/runtime-plugin-market.js b/src/runtime-plugin-market.js index 0d84f9e..851e1df 100644 --- a/src/runtime-plugin-market.js +++ b/src/runtime-plugin-market.js @@ -29,11 +29,31 @@ } } + // 本地缓存:上次成功拉到的市场列表(毫秒级出图,后台再刷新) + const CACHE_KEY = 'iwb_market_cache' + function localStore () { + const L = global.IWBStorageLocal || null + return (L && typeof L.getStore === 'function') ? L.getStore() : null + } + function cached () { + try { + const st = localStore() + if (!st) return null + const v = st.get(CACHE_KEY) + return (Array.isArray(v) && v.length) ? v : null + } catch (e) { return null } + } + function saveCache (list) { + try { const st = localStore(); if (st && Array.isArray(list) && list.length) st.set(CACHE_KEY, list) } catch (e) { /* ignore */ } + } + async function list () { const resp = await marketFetch(MARKET_URL) if (!resp.ok) throw new Error('市场不可达:HTTP ' + resp.status) const j = await resp.json() - return Array.isArray(j && j.plugins) ? j.plugins : [] + const items = Array.isArray(j && j.plugins) ? j.plugins : [] + saveCache(items) + return items } async function installed () { @@ -78,5 +98,5 @@ } catch (e) { return { ok: false, error: String((e && e.message) || e) } } } - global.IWBRuntimePluginMarket = { list: list, installed: installed, install: install, uninstall: uninstall } + global.IWBRuntimePluginMarket = { list: list, cached: cached, installed: installed, install: install, uninstall: uninstall } })(typeof window !== 'undefined' ? window : globalThis) diff --git a/src/ui-settings-modal.js b/src/ui-settings-modal.js index 97395a9..c84de99 100644 --- a/src/ui-settings-modal.js +++ b/src/ui-settings-modal.js @@ -566,7 +566,7 @@ function SettingsModal(props) { }, I(SET_NAV_ICONS[t[0]] || 'settings'), el('span', null, t[1]))), el('div', { className: 'iwb-set-nav-group' }, '插件'), el('button', { key: 'nav-plugins', className: 'iwb-tab iwb-set-nav-item' + (tab === 'plugins' ? ' iwb-tab-active' : ''), onClick: () => setTab('plugins') }, I('panel'), el('span', null, '插件管理')), - pluginItems.map((p) => el('button', { key: 'nav-plugin:' + p.id, className: 'iwb-tab iwb-set-nav-item' + (tab === 'plugin:' + p.id ? ' iwb-tab-active' : ''), onClick: () => setTab('plugin:' + p.id) }, I('star'), el('span', null, p.name))), + pluginItems.filter((p) => p && p.enabled).map((p) => el('button', { key: 'nav-plugin:' + p.id, className: 'iwb-tab iwb-set-nav-item' + (tab === 'plugin:' + p.id ? ' iwb-tab-active' : ''), onClick: () => setTab('plugin:' + p.id) }, I('star'), el('span', null, p.name))), ), el('div', { className: 'iwb-modal-body' }, tab === 'gen' ? genTab : tab === 'llm' ? llmTab : tab === 'img' ? imgTab : tab === 'backup' ? backupTab : tab === 'hotkeys' ? hotkeyTab : tab === 'sizes' ? sizePresetTab : tab === 'plugins' ? pluginsTab : (typeof tab === 'string' && tab.indexOf('plugin:') === 0) ? pluginSettingsPage : tab === 'diag' ? diagTab : generalTab, diff --git a/src/ui-settings-sections.js b/src/ui-settings-sections.js index a0355eb..11e6c27 100644 --- a/src/ui-settings-sections.js +++ b/src/ui-settings-sections.js @@ -127,7 +127,9 @@ function DesktopPluginsTab (props) { const { PluginHost, pluginItems, setPluginsRev, setTab, wRuntimePlugins } = props const [view, setView] = React.useState('manage') - const [market, setMarket] = React.useState(null) + const [market, setMarket] = React.useState(function () { + try { const M = (typeof window !== 'undefined') ? window.IWBRuntimePluginMarket : null; return M && M.cached ? M.cached() : null } catch (e) { return null } + }) const [inst, setInst] = React.useState({}) const [q, setQ] = React.useState('') const [msg, setMsg] = React.useState('') @@ -139,13 +141,17 @@ const D = (typeof window !== 'undefined') ? window.IWBDesktop : null const refresh = React.useCallback(async () => { if (!D || !D.market) { setMarket([]); return } + // 先读本地清单(毫秒级)→ 立刻把「已安装」渲染出来;市场列表(网络)随后补上 try { - const list = await D.market.list() const cur = await D.market.installed() const map = {} for (const p of (cur || [])) if (p && p.id) map[p.id] = p.version || '' - setMarket(list); setInst(map); setMsg('') - } catch (e) { setMarket([]); setMsg('市场加载失败:' + String((e && e.message) || e)) } + setInst(map) + } catch (e) { /* 本地清单失败不阻塞市场请求 */ } + try { + const list = await D.market.list() + setMarket(list); setMsg('') + } catch (e) { setMsg('市场加载失败:' + String((e && e.message) || e)) } }, [D]) React.useEffect(function () { refresh() }, [refresh]) const act = async function (kind, id) { @@ -334,7 +340,7 @@ ), ), ) - })) : el('div', { className: 'iwb-hint' }, kw ? '没有匹配的插件' : '还没有安装插件——点上面的「浏览」进入市场'), + })) : el('div', { className: 'iwb-hint' }, kw ? '没有匹配的插件' : (market === null ? '读取插件清单中…' : '还没有安装插件——点上面的「浏览」进入市场')), restart ? el('div', { className: 'iwb-mk-setrow' }, el('div', { className: 'iwb-mk-setrow-main' }, el('div', { className: 'iwb-mk-setrow-title' }, '需要重启应用才能生效'),