Files
zombieyang-sd-ppp/plugins/photoshop/run.js
T
2025-05-22 18:45:14 +08:00

90 lines
2.3 KiB
JavaScript

const { entrypoints } = require("uxp");
const _id = Symbol("_id");
const _root = Symbol("_root");
const _attachment = Symbol("_attachment");
const _menuItems = Symbol("_menuItems");
class PanelController {
constructor({ id, menuItems } = {}) {
this[_id] = null;
this[_root] = null;
this[_attachment] = null;
this[_menuItems] = [];
this[_id] = id;
this[_menuItems] = menuItems || [];
this.menuItems = this[_menuItems].map(menuItem => ({
id: menuItem.id,
label: menuItem.label,
enabled: menuItem.enabled || true,
checked: menuItem.checked || false
}));
["create", "show", "hide", "destroy", "invokeMenu"].forEach(fn => this[fn] = this[fn].bind(this));
}
create() {
this[_root] = document.createElement("div");
this[_root].style.height = "100vh";
this[_root].style.overflowY = "hidden";
this[_root].style.overflowX = "hidden";
// render entry
// 渲染入口
sdppp.renderPhotoshopPlugin(this[_root]);
return this[_root];
}
show(event) {
if (!this[_root]) this.create();
this[_attachment] = event;
this[_attachment].appendChild(this[_root]);
}
hide() {
if (this[_attachment] && this[_root]) {
this[_attachment].removeChild(this[_root]);
this[_attachment] = null;
}
}
destroy() { }
invokeMenu(id) {
const menuItem = this[_menuItems].find(c => c.id === id);
if (menuItem) {
const handler = menuItem.oninvoke;
if (handler) {
handler();
}
}
}
}
entrypoints.setup({
plugin: {
create(plugin) {
},
destroy() {
}
},
panels: {
'sdppp-connect': new PanelController({
id: "sdppp-connect", menuItems: [
{
id: "sdppp-connect-log",
label: "查看日志",
enabled: true,
checked: false,
oninvoke: () => {
const logs = globalThis.sdpppX.getLogs();
alert(JSON.stringify(logs));
}
}
]
}),
}
});