feat: redirect queue prompt to iframe event in workspace mode
This commit is contained in:
		
							parent
							
								
									409ca6f1dd
								
							
						
					
					
						commit
						3c508c7eec
					
				@ -30,6 +30,30 @@ const ext = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (workspace_mode) {
 | 
					    if (workspace_mode) {
 | 
				
			||||||
      document.querySelector(".comfy-menu").style.display = "none";
 | 
					      document.querySelector(".comfy-menu").style.display = "none";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      sendEventToCD("cd_plugin_onInit");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      app.queuePrompt = ((originalFunction) =>
 | 
				
			||||||
 | 
					        async () => {
 | 
				
			||||||
 | 
					          // const prompt = await app.graphToPrompt();
 | 
				
			||||||
 | 
					          sendEventToCD("cd_plugin_onQueuePromptTrigger");
 | 
				
			||||||
 | 
					        })(app.queuePrompt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // // Intercept the onkeydown event
 | 
				
			||||||
 | 
					      // window.addEventListener(
 | 
				
			||||||
 | 
					      //   "keydown",
 | 
				
			||||||
 | 
					      //   (event) => {
 | 
				
			||||||
 | 
					      //     // Check for specific keys if necessary
 | 
				
			||||||
 | 
					      //     console.log("hi");
 | 
				
			||||||
 | 
					      //     if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
 | 
				
			||||||
 | 
					      //       event.preventDefault();
 | 
				
			||||||
 | 
					      //       event.stopImmediatePropagation();
 | 
				
			||||||
 | 
					      //       event.stopPropagation();
 | 
				
			||||||
 | 
					      //       sendEventToCD("cd_plugin_onQueuePrompt", prompt);
 | 
				
			||||||
 | 
					      //     }
 | 
				
			||||||
 | 
					      //   },
 | 
				
			||||||
 | 
					      //   true,
 | 
				
			||||||
 | 
					      // );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const data = getData();
 | 
					    const data = getData();
 | 
				
			||||||
@ -204,7 +228,8 @@ const ext = {
 | 
				
			|||||||
      //   }
 | 
					      //   }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    app.graph.onAfterChange = ((originalFunction) => async function () {
 | 
					    app.graph.onAfterChange = ((originalFunction) =>
 | 
				
			||||||
 | 
					      async function () {
 | 
				
			||||||
        const prompt = await app.graphToPrompt();
 | 
					        const prompt = await app.graphToPrompt();
 | 
				
			||||||
        sendEventToCD("cd_plugin_onAfterChange", prompt);
 | 
					        sendEventToCD("cd_plugin_onAfterChange", prompt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -454,9 +479,7 @@ async function deployWorkflow() {
 | 
				
			|||||||
        console.log(file);
 | 
					        console.log(file);
 | 
				
			||||||
        loadingDialog.showLoading("Generating hash", file);
 | 
					        loadingDialog.showLoading("Generating hash", file);
 | 
				
			||||||
        const hash = await fetch(
 | 
					        const hash = await fetch(
 | 
				
			||||||
          `/comfyui-deploy/get-file-hash?file_path=${encodeURIComponent(
 | 
					          `/comfyui-deploy/get-file-hash?file_path=${encodeURIComponent(file)}`,
 | 
				
			||||||
            file,
 | 
					 | 
				
			||||||
          )}`,
 | 
					 | 
				
			||||||
        ).then((x) => x.json());
 | 
					        ).then((x) => x.json());
 | 
				
			||||||
        loadingDialog.showLoading("Generating hash", file);
 | 
					        loadingDialog.showLoading("Generating hash", file);
 | 
				
			||||||
        console.log(hash);
 | 
					        console.log(hash);
 | 
				
			||||||
@ -466,17 +489,14 @@ async function deployWorkflow() {
 | 
				
			|||||||
        console.log("Uploading ", file);
 | 
					        console.log("Uploading ", file);
 | 
				
			||||||
        loadingDialog.showLoading("Uploading file", file);
 | 
					        loadingDialog.showLoading("Uploading file", file);
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
          const { download_url } = await fetch(
 | 
					          const { download_url } = await fetch(`/comfyui-deploy/upload-file`, {
 | 
				
			||||||
            `/comfyui-deploy/upload-file`,
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
            method: "POST",
 | 
					            method: "POST",
 | 
				
			||||||
            body: JSON.stringify({
 | 
					            body: JSON.stringify({
 | 
				
			||||||
              file_path: file,
 | 
					              file_path: file,
 | 
				
			||||||
              token: apiKey,
 | 
					              token: apiKey,
 | 
				
			||||||
              url: endpoint + "/api/upload-url",
 | 
					              url: endpoint + "/api/upload-url",
 | 
				
			||||||
            }),
 | 
					            }),
 | 
				
			||||||
            },
 | 
					          })
 | 
				
			||||||
          )
 | 
					 | 
				
			||||||
            .then((x) => x.json())
 | 
					            .then((x) => x.json())
 | 
				
			||||||
            .catch(() => {
 | 
					            .catch(() => {
 | 
				
			||||||
              loadingDialog.close();
 | 
					              loadingDialog.close();
 | 
				
			||||||
@ -608,7 +628,7 @@ function addButton() {
 | 
				
			|||||||
  deploy.style.display = "block";
 | 
					  deploy.style.display = "block";
 | 
				
			||||||
  deploy.innerHTML = "<div id='button-title'>Deploy</div>";
 | 
					  deploy.innerHTML = "<div id='button-title'>Deploy</div>";
 | 
				
			||||||
  deploy.onclick = async () => {
 | 
					  deploy.onclick = async () => {
 | 
				
			||||||
    await deployWorkflow()
 | 
					    await deployWorkflow();
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const config = document.createElement("img");
 | 
					  const config = document.createElement("img");
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user