feat(plugins): P2 插件市场(market 索引生成 + 应用内安装/更新/卸载,sha256 校验写 plugins/)
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m10s
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m10s
This commit is contained in:
1 parent
c1b9328978
commit
51bc9c581a
8 files changed
+195
-2
No files matched your search
@@ -23,6 +23,12 @@
|
||||
getSilentSave() { return !!(state.impl && state.impl.getSilentSave()) },
|
||||
setSilentSave(on) { if (state.impl) state.impl.setSilentSave(on) },
|
||||
openDataDir() { return state.impl ? state.impl.openDataDir() : Promise.reject(new Error('仅桌面端可用')) },
|
||||
market: {
|
||||
list() { return state.impl && state.impl.marketList ? state.impl.marketList() : Promise.resolve([]) },
|
||||
installed() { return state.impl && state.impl.marketInstalled ? state.impl.marketInstalled() : Promise.resolve([]) },
|
||||
install(id) { return state.impl && state.impl.marketInstall ? state.impl.marketInstall(id) : Promise.resolve({ ok: false, error: '仅桌面端可用' }) },
|
||||
uninstall(id) { return state.impl && state.impl.marketUninstall ? state.impl.marketUninstall(id) : Promise.resolve({ ok: false, error: '仅桌面端可用' }) },
|
||||
},
|
||||
}
|
||||
global.IWBDesktop = bridge
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
+8
-1
@@ -409,6 +409,13 @@
|
||||
if (!/^[A-Za-z0-9._-]+$/.test(safe)) throw new Error('非法插件文件名')
|
||||
return fs().readTextFile(await join(dir, PLUG_DIR, safe))
|
||||
}
|
||||
async function pluginWrite(file, text) {
|
||||
const safe = String(file || '')
|
||||
if (!/^[A-Za-z0-9._-]+$/.test(safe)) throw new Error('非法插件文件名')
|
||||
await pluginDir()
|
||||
await fs().writeTextFile(await join(dir, PLUG_DIR, safe), String(text))
|
||||
return true
|
||||
}
|
||||
async function pluginRemove(file) {
|
||||
const safe = String(file || '')
|
||||
if (!/^[A-Za-z0-9._-]+$/.test(safe)) throw new Error('非法插件文件名')
|
||||
@@ -678,7 +685,7 @@
|
||||
|
||||
global.IWBStorageFile = {
|
||||
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, gcImages,
|
||||
plugins: { manifest: pluginManifest, read: pluginRead, remove: pluginRemove, dir: pluginDir },
|
||||
plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir },
|
||||
storage: () => storage,
|
||||
kv: () => kv,
|
||||
dir: () => dir,
|
||||
|
||||
@@ -16,6 +16,59 @@
|
||||
const bridge = () => ((typeof window !== 'undefined' && window.IWBDesktop) ? window.IWBDesktop : null)
|
||||
const isDesk = () => { const b = bridge(); return !!(b && b.isTauri && b.isTauri()) }
|
||||
|
||||
// 插件市场(P2,仅桌面端):从 market.maqiart.eu.org 拉索引 → 安装/更新/卸载到资料目录 plugins/
|
||||
function MarketBlock () {
|
||||
const [rows, setRows] = React.useState(null)
|
||||
const [installed, setInstalled] = React.useState({})
|
||||
const [msg, setMsg] = React.useState('')
|
||||
const [busy, setBusy] = React.useState('')
|
||||
const D = (typeof window !== 'undefined') ? window.IWBDesktop : null
|
||||
const refresh = React.useCallback(async () => {
|
||||
if (!D || !D.market) { setRows([]); 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 || ''
|
||||
setRows(list); setInstalled(map); setMsg('')
|
||||
} catch (e) { setRows([]); setMsg('市场加载失败:' + String((e && e.message) || e)) }
|
||||
}, [D])
|
||||
React.useEffect(() => { refresh() }, [refresh])
|
||||
const act = async (kind, id) => {
|
||||
if (!D || !D.market) return
|
||||
setBusy(id)
|
||||
try {
|
||||
const r = kind === 'install' ? await D.market.install(id) : await D.market.uninstall(id)
|
||||
if (!r || !r.ok) { setMsg((r && r.error) || '操作失败'); return }
|
||||
setMsg(kind === 'install' ? '已安装,重启应用后生效' : '已卸载,重启应用后生效')
|
||||
await refresh()
|
||||
if (window.confirm('需要重启应用才能生效,现在重启?')) window.location.reload()
|
||||
} finally { setBusy('') }
|
||||
}
|
||||
if (rows === null) return el('div', { className: 'iwb-hint' }, '插件市场加载中…')
|
||||
return el('div', null,
|
||||
el('div', { className: 'iwb-section-sub' }, '插件市场'),
|
||||
el('div', { className: 'iwb-row' },
|
||||
el('span', { className: 'iwb-hint', style: { flex: '1 1 auto' } }, rows.length ? ('market.maqiart.eu.org · ' + rows.length + ' 个插件') : '市场暂无插件'),
|
||||
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: refresh }, '刷新'),
|
||||
),
|
||||
rows.map((p) => {
|
||||
const have = installed[p.id]
|
||||
const need = have && have !== p.version
|
||||
const label = busy === p.id ? '处理中…' : (!have ? '安装' : (need ? '更新' : '卸载'))
|
||||
const kind = !have || need ? 'install' : 'uninstall'
|
||||
return el('div', { key: p.id, className: 'iwb-plugin-row' },
|
||||
el('div', { className: 'iwb-label iwb-grow' }, p.name || p.id,
|
||||
el('div', { className: 'iwb-hint' }, (p.desc || '') + (have ? (' · 已安装 ' + have) : '')),
|
||||
),
|
||||
el('button', { className: 'iwb-btn iwb-btn-sm', disabled: !!busy, onClick: () => act(kind, p.id) }, label),
|
||||
)
|
||||
}),
|
||||
msg ? el('div', { className: 'iwb-hint' }, msg) : null,
|
||||
el('div', { className: 'iwb-hint' }, '安装会下载到资料目录 plugins/ 并校验 sha256;卸载只移除外部副本,内置版本仍然可用。'),
|
||||
)
|
||||
}
|
||||
|
||||
function renderPluginsTab (ctx) {
|
||||
const { PluginHost, pluginBusy, pluginItems, setMsg, setPluginBusy, setPluginsRev, setTab, wEnsurePluginLoaded, wRuntimePlugins } = ctx
|
||||
const pluginsTab = (() => {
|
||||
@@ -36,6 +89,8 @@
|
||||
el('div', { className: 'iwb-hint' }, (isDesk()
|
||||
? '插件随应用发布(离线可用);外部插件放在资料目录 plugins/ 下可独立维护,不动本体。停用只隐藏其入口:既有的插件节点仍照常渲染、运行与保存。'
|
||||
: '内置插件随应用发布;带「远程」标签的插件来自同源 /plugins/index.json(KV 提供),更新只需上传到 KV、刷新即生效。停用只隐藏其入口:既有的插件节点仍照常渲染、运行与保存。')),
|
||||
isDesk() ? el(MarketBlock, null) : null,
|
||||
isDesk() ? el('div', { className: 'iwb-section-sub' }, '已装插件') : null,
|
||||
pluginItems.map((p) => {
|
||||
return el('div', { key: p.id, className: 'iwb-plugin-row' },
|
||||
el('label', { className: 'iwb-label iwb-grow' },
|
||||
|
||||
Reference in new issue
Block a user