feat: 添加load default json逻辑
This commit is contained in:
+22
-7
@@ -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));
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user