Skip to content

Instantly share code, notes, and snippets.

@pixelass
Last active August 1, 2023 10:36
Show Gist options
  • Save pixelass/0518d56d62d7b8ad19281eb032bde330 to your computer and use it in GitHub Desktop.
Save pixelass/0518d56d62d7b8ad19281eb032bde330 to your computer and use it in GitHub Desktop.
ComfyUI setting for link render mode
import { app } from "../scripts/app.js";
const name = "Pixelass.Settings.LinkRenderMode";
class Store {
links_render_mode = 0;
key = `Comfy.extension`;
defaultState = {};
constructor(key, defaultState) {
this.key = `Comfy.${key}`;
this.defaultState = defaultState;
}
get(key) {
try {
return JSON.parse(window.localStorage.getItem(this.key))[key];
} catch {
this.set(this.defaultState);
return this.defaultState[key];
}
}
set(key, value) {
const state = JSON.parse(
window.localStorage.getItem(this.key) ?? JSON.stringify(this.defaultState)
);
state[key] = value;
return window.localStorage.setItem(this.key, JSON.stringify(state));
}
merge(state) {
return window.localStorage.setItem(
this.key,
JSON.stringify({
...this.this.get(),
...state,
})
);
}
}
const renderModes = ["straight", "small curve", "curve"];
const ext = {
name,
async setup(app) {
const store = new Store(name, {
links_render_mode: 2,
});
// Setup elements
const row = document.createElement("tr");
const select = document.createElement("select");
const cell1 = document.createElement("td");
const cell2 = document.createElement("td");
const label = document.createElement("label");
// Populate elements
row.append(cell1, cell2);
cell1.append(label);
cell2.append(select);
select.append(
...renderModes.map((mode, index) => {
const option = document.createElement("option");
option.value = index;
option.label = mode;
option.innerText = mode;
return option;
})
);
label.innerText = "Links Render Mode";
// Configure elements
const inputId = "Comfy-linksRenderNode";
label.setAttribute("for", inputId);
select.setAttribute("id", inputId);
// Event listeners
select.oninput = (event) => {
const links_render_mode = Number.parseInt(event.target.value, 10);
store.set("links_render_mode", links_render_mode);
app.canvas.links_render_mode = links_render_mode;
app.graph.change();
};
// Add setting to panel
app.ui.settings.settings.push({
render() {
return row;
},
});
// Init (load from storage)
const links_render_mode = store.get("links_render_mode");
select.value = links_render_mode;
app.canvas.links_render_mode = links_render_mode;
},
};
app.registerExtension(ext);
@pixelass
Copy link
Author

Add to ComfyUI/web/extensions as ComfyUI/web/extensions/linsRenderMode.js

Reload browser window to activate plugin:

The option is in the settings:

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment