diff --git a/web-plugin/index.js b/web-plugin/index.js index 9c13b62..4fcc3f7 100644 --- a/web-plugin/index.js +++ b/web-plugin/index.js @@ -107,8 +107,8 @@ function addButton() { const deploy = document.createElement("button"); deploy.style.position = "relative"; + deploy.style.display = "block"; deploy.textContent = "Deploy"; - deploy.className = "sharebtn"; deploy.onclick = async () => { /** @type {LGraph} */ const graph = app.graph; @@ -127,10 +127,15 @@ function addButton() { console.log(graph); console.log(prompt); - const endpoint = localStorage.getItem("endpoint") ?? "https://www.comfydeploy.com"; - const apiKey = localStorage.getItem("apiKey"); + // const endpoint = localStorage.getItem("endpoint") ?? ""; + // const apiKey = localStorage.getItem("apiKey"); - if (!endpoint || !apiKey) { + const { + endpoint, + apiKey, + } = getData(); + + if (!endpoint || !apiKey || apiKey === "" || endpoint === "") { configDialog.show(); return; } @@ -255,6 +260,27 @@ export class InfoDialog extends ComfyDialog { export const infoDialog = new InfoDialog() +function getData(environment) { + const deployOption = environment || localStorage.getItem("comfy_deploy_env") || "cloud"; + const data = localStorage.getItem("comfy_deploy_env_data_" + deployOption); + if (!data) { + if (deployOption == "cloud") + return { + endpoint: "https://www.comfydeploy.com", + apiKey: "", + }; + else + return { + endpoint: "http://localhost:3000", + apiKey: "", + }; + } + return { + ...JSON.parse(data), + environment: deployOption, + }; +} + export class ConfigDialog extends ComfyDialog { container = null; @@ -300,32 +326,60 @@ export class ConfigDialog extends ComfyDialog { } save() { + const deployOption = this.container.querySelector("#deployOption").value; + localStorage.setItem("comfy_deploy_env", deployOption); + const endpoint = this.container.querySelector("#endpoint").value; const apiKey = this.container.querySelector("#apiKey").value; - localStorage.setItem("endpoint", endpoint); - localStorage.setItem("apiKey", apiKey); + const data = { + endpoint, + apiKey, + } + localStorage.setItem("comfy_deploy_env_data_" + deployOption, JSON.stringify(data)); this.close(); } show() { - // this.element.style.whiteSpace = "nowrap"; - // this.textElement.style.overflow = "hidden"; this.container.style.color = "white"; - // this.textElement.style.padding = "10px"; + + const data = getData(); this.container.innerHTML = ` -