feat(plugins): P3 开发者模式(plugins/local/<id>/plugin.js 免签名加载)+ SDK 文档与示例插件
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
1008370733
commit
49b8cb3abd
7 files changed
+225
-7
No files matched your search
+18
-1
@@ -421,6 +421,23 @@
|
||||
if (!/^[A-Za-z0-9._-]+$/.test(safe)) throw new Error('非法插件文件名')
|
||||
try { await fs().remove(await join(dir, PLUG_DIR, safe)); return true } catch (e) { return false }
|
||||
}
|
||||
// 开发者模式:<资料目录>/plugins/local/<id>/plugin.js(未签名,只在开关打开时加载)
|
||||
async function pluginListLocal() {
|
||||
try {
|
||||
const ldir = await join(dir, PLUG_DIR, 'local')
|
||||
const entries = await fs().readDir(ldir)
|
||||
const out = []
|
||||
for (const e of entries) {
|
||||
if (!e || !e.isDirectory) continue
|
||||
try {
|
||||
const code = await fs().readTextFile(await join(ldir, e.name, 'plugin.js'))
|
||||
out.push({ id: e.name, file: 'local/' + e.name + '/plugin.js', code: code })
|
||||
} catch (err) { /* 该目录没有 plugin.js,跳过 */ }
|
||||
}
|
||||
return out
|
||||
} catch (e) { return [] }
|
||||
}
|
||||
|
||||
async function pluginDir() {
|
||||
const p = await join(dir, PLUG_DIR)
|
||||
try { await fs().mkdir(p, { recursive: true }) } catch (e) { /* 已存在 */ }
|
||||
@@ -685,7 +702,7 @@
|
||||
|
||||
global.IWBStorageFile = {
|
||||
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, gcImages,
|
||||
plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir },
|
||||
plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir, listLocal: pluginListLocal },
|
||||
storage: () => storage,
|
||||
kv: () => kv,
|
||||
dir: () => dir,
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
const [msg, setMsg] = React.useState('')
|
||||
const [busy, setBusy] = React.useState('')
|
||||
const [restart, setRestart] = React.useState(false)
|
||||
|
||||
const D = (typeof window !== 'undefined') ? window.IWBDesktop : null
|
||||
const refresh = React.useCallback(async () => {
|
||||
if (!D || !D.market) { setRows([]); return }
|
||||
@@ -110,6 +111,18 @@
|
||||
return Promise.resolve(window.confirm(text))
|
||||
}
|
||||
|
||||
// 开发者模式开关(走统一存储门面,src 不得直调 localStorage)
|
||||
function pluginDevStore () {
|
||||
const L = (typeof window !== 'undefined') ? window.IWBStorageLocal : null
|
||||
return (L && typeof L.getStore === 'function') ? L.getStore() : null
|
||||
}
|
||||
function pluginDevGet () {
|
||||
try { const st = pluginDevStore(); return !!(st && st.get('iwb_plugin_dev') === true) } catch (e) { return false }
|
||||
}
|
||||
function pluginDevSet (on) {
|
||||
try { const st = pluginDevStore(); if (st) st.set('iwb_plugin_dev', !!on) } catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
// 桌面端插件管理(参考 Obsidian):搜索 + 已安装(开关/设置)+ 可安装(市场)
|
||||
function DesktopPluginsTab (props) {
|
||||
const { PluginHost, pluginItems, setPluginsRev, setTab, wRuntimePlugins } = props
|
||||
@@ -119,6 +132,9 @@
|
||||
const [msg, setMsg] = React.useState('')
|
||||
const [busy, setBusy] = React.useState('')
|
||||
const [restart, setRestart] = React.useState(false)
|
||||
const [devMode, setDevMode] = React.useState(function () {
|
||||
return pluginDevGet()
|
||||
})
|
||||
const D = (typeof window !== 'undefined') ? window.IWBDesktop : null
|
||||
const refresh = React.useCallback(async () => {
|
||||
if (!D || !D.market) { setMarket([]); return }
|
||||
@@ -177,6 +193,33 @@
|
||||
return el('div', { className: 'iwb-set-page' },
|
||||
el('div', { className: 'iwb-set-page-title' }, '插件'),
|
||||
el('div', { className: 'iwb-hint' }, '插件从市场安装到:' + dirHint + '(应用本体不再自带插件)'),
|
||||
el('div', { className: 'iwb-row' },
|
||||
el('label', { className: 'iwb-check', title: '本地开发用:把插件放到 plugins/local/<id>/plugin.js' },
|
||||
el('input', {
|
||||
type: 'checkbox',
|
||||
checked: devMode,
|
||||
onChange: function (e) {
|
||||
const on = e.target.checked
|
||||
setDevMode(on)
|
||||
pluginDevSet(on)
|
||||
setMsg(on ? '已开启开发者模式,重启后加载 plugins/local/ 下的插件' : '已关闭开发者模式,重启后只加载市场安装的插件')
|
||||
},
|
||||
}),
|
||||
' 开发者模式(加载 plugins/local/<id>/plugin.js,未签名)'),
|
||||
),
|
||||
el('div', { className: 'iwb-row' },
|
||||
el('label', { className: 'iwb-check', title: '用于本地开发:把插件放到 plugins/local/<id>/plugin.js' },
|
||||
el('input', {
|
||||
type: 'checkbox', checked: devMode,
|
||||
onChange: (e) => {
|
||||
const on = e.target.checked
|
||||
setDevMode(on)
|
||||
pluginDevSet(on)
|
||||
setMsg(on ? '已开启开发者模式,重启后加载 plugins/local/ 下的插件' : '已关闭开发者模式,重启后只加载市场安装的插件')
|
||||
},
|
||||
}),
|
||||
' 开发者模式(加载 plugins/local/<id>/plugin.js,未签名)'),
|
||||
),
|
||||
el('div', { className: 'iwb-row' },
|
||||
el('input', { className: 'iwb-input iwb-grow', placeholder: '搜索已安装的插件…', value: q, onChange: (e) => setQ(e.target.value) }),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user