1
mirror of https://github.com/comfyanonymous/ComfyUI.git synced 2025-08-04 07:52:46 +08:00

Added dynamic loading of extensions

This commit is contained in:
pythongosssss
2023-03-03 19:05:39 +00:00
parent c23af92baf
commit 592b377ac4
5 changed files with 34 additions and 13 deletions

View File

@@ -11,14 +11,6 @@ class ComfyApp {
this.nodeOutputs = {};
}
#log(message, ...other) {
console.log("[comfy]", message, ...other);
}
#error(message, ...other) {
console.error("[comfy]", message, ...other);
}
/**
* Invoke an extension callback
* @param {string} method The extension callback to execute
@@ -32,7 +24,7 @@ class ComfyApp {
try {
results.push(ext[method](...args, this));
} catch (error) {
this.#error(
console.error(
`Error calling extension '${ext.name}' method '${method}'`,
{ error },
{ extension: ext },
@@ -58,7 +50,7 @@ class ComfyApp {
try {
return await ext[method](...args, this);
} catch (error) {
this.#error(
console.error(
`Error calling extension '${ext.name}' method '${method}'`,
{ error },
{ extension: ext },
@@ -413,10 +405,26 @@ class ComfyApp {
api.init();
}
/**
* Loads all extensions from the API into the window
*/
async #loadExtensions() {
const extensions = await api.getExtensions();
for (const ext of extensions) {
try {
await import(ext);
} catch (error) {
console.error("Error loading extension", ext, error);
}
}
}
/**
* Set up the app on the page
*/
async setup() {
await this.#loadExtensions();
// Create and mount the LiteGraph in the DOM
const canvasEl = Object.assign(document.createElement("canvas"), { id: "graph-canvas" });
document.body.prepend(canvasEl);