feat: 添加load default json逻辑

This commit is contained in:
joe
2024-10-11 17:41:57 +08:00
parent 3e9bf28714
commit afb9cb07f0
2 changed files with 481 additions and 7 deletions
+22 -7
View File
@@ -1,10 +1,11 @@
import { app } from "../../scripts/app.js";
import { app } from "../scripts/app.js";
app.registerExtension({
name: "Shellagent.extension",
async setup() {
window.parent.postMessage({
type: 'loaded'
}, '*');
window.parent.postMessage({
type: 'loaded'
}, '*');
window.addEventListener('message', (event) => {
if (event.data.type === 'save') {
app.graphToPrompt().then(data => {
@@ -15,9 +16,23 @@ app.registerExtension({
}, "*");
});
}
if (event.data.type === 'load') {
app.loadGraphData(event.data.data, true, false);
}
if (event.data.type === 'load') {
app.loadGraphData(event.data.data, true, false);
}
if (event.data.type === 'load_default') {
// 使用FileReader读取JSON文件
fetch('extensions/ComfyUI-ShellAgent-Plugin/shellagent_default.json')
.then(response => response.blob())
.then(blob => {
const reader = new FileReader();
reader.onload = function(e) {
const json = JSON.parse(e.target.result);
app.loadGraphData(json, true, false);
};
reader.readAsText(blob);
})
.catch(error => console.error('加载默认JSON文件时出错:', error));
}
});
},
});