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
@@ -0,0 +1,40 @@
|
||||
// 示例插件(P3 SDK 模板):把本文件放到
|
||||
// <资料目录>/plugins/local/hello-world/plugin.js
|
||||
// 然后在 设置 → 插件 → 打开「开发者模式」,重启应用即可生效。
|
||||
//
|
||||
// 契约:调用 window.IWBPluginHost.register(manifest, factory)
|
||||
// manifest: { id, name, version, apiVersion, capabilities }
|
||||
// factory(ctx): 注册入口;返回 { dispose } 供停用/卸载时清理
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
|
||||
global.IWBPluginHost.register({
|
||||
id: 'hello-world',
|
||||
name: '示例插件',
|
||||
version: '0.1.0',
|
||||
apiVersion: 1,
|
||||
capabilities: ['nodeActions', 'canvas'],
|
||||
}, function (ctx) {
|
||||
// 读取当前画布节点(只读)
|
||||
function countNodes () {
|
||||
try {
|
||||
return (ctx.canvas && typeof ctx.canvas.getNodes === 'function') ? ctx.canvas.getNodes().length : 0
|
||||
} catch (e) { return -1 }
|
||||
}
|
||||
|
||||
// 注册一个节点右键动作:只在参考图/输出节点上出现
|
||||
ctx.nodeActions.register({
|
||||
id: 'hello-world-count',
|
||||
title: '示例:数一下节点',
|
||||
icon: 'sparkles',
|
||||
appliesTo: function (node) { return !!(node && (node.type === 'ref' || node.type === 'out')) },
|
||||
run: function () {
|
||||
// 注意:桌面端不要用 alert/confirm(会阻塞 WebView),用 console 或宿主提供的 UI
|
||||
console.log('[hello-world] 当前画布节点数:' + countNodes())
|
||||
return true
|
||||
},
|
||||
})
|
||||
|
||||
return { dispose: function () { /* 清理定时器/监听器 */ } }
|
||||
})
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
Reference in new issue
Block a user