Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ljleb committed Oct 29, 2023
1 parent a6897d7 commit 8dc1ef3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
14 changes: 13 additions & 1 deletion javascript/compute-height.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function onComfyuiTabLoaded(callback) {
if (getClearEnabledDisplayNamesButtons().some(e => e === null) ||
getWorkflowTypeIds() === null ||
getComfyuiContainer() === null ||
getTabNav() === null
getTabNav() === null ||
getWebuiClientIdTextArea() === null
) {
// webui not yet ready, try again in a bit
setTimeout(() => { onComfyuiTabLoaded(callback); }, POLLING_TIMEOUT);
Expand All @@ -39,6 +40,7 @@ function clearEnabledDisplayNames() {
}

function setupComfyuiTabEvents() {
setupWebuiClientId();
setupResizeTabEvent();
setupToggleFooterEvent();

Expand All @@ -54,6 +56,12 @@ function reloadComfyuiIFrames() {
});
}

function setupWebuiClientId() {
const textArea = getWebuiClientIdTextArea();
textArea.value = WEBUI_CLIENT_ID;
textArea.dispatchEvent(new Event('input'));
}

function setupResizeTabEvent() {
window.addEventListener("resize", updateComfyuiTabHeight);
}
Expand Down Expand Up @@ -108,6 +116,10 @@ function getComfyuiContainer() {
return document.getElementById("comfyui_webui_container") ?? null;
}

function getWebuiClientIdTextArea() {
return document.querySelector("#comfyui_webui_client_id textarea") ?? null;
}

function getFooter() {
return document.querySelector('#footer') ?? null;
}
Expand Down
10 changes: 3 additions & 7 deletions lib_comfyui/comfyui/iframe_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class ComfyuiIFrameRequests:
finished_comfyui_queue = multiprocessing.Queue()
focused_webui_client_id = None
server_instance = None
sid_map = {}

Expand All @@ -19,12 +18,12 @@ def send(request, workflow_type, data=None):
data = {}

cls = ComfyuiIFrameRequests
if cls.focused_webui_client_id is None:
if global_state.webui_client_id is None:
raise RuntimeError('No active webui connection')

ws_client_ids = cls.sid_map[cls.focused_webui_client_id]
ws_client_ids = cls.sid_map[global_state.webui_client_id]
if workflow_type not in ws_client_ids:
raise RuntimeError(f"The workflow type {workflow_type} has not been registered by the active webui client {cls.focused_webui_client_id}")
raise RuntimeError(f"The workflow type {workflow_type} has not been registered by the active webui client {global_state.webui_client_id}")

clear_queue(cls.finished_comfyui_queue)
cls.server_instance.send_sync(request, data, ws_client_ids[workflow_type])
Expand Down Expand Up @@ -76,9 +75,6 @@ def register_client(request):
webui_client_id = request['webuiClientId']
sid = request['sid']

# TODO: generalize this
ComfyuiIFrameRequests.focused_webui_client_id = webui_client_id

if webui_client_id not in ComfyuiIFrameRequests.sid_map:
ComfyuiIFrameRequests.sid_map[webui_client_id] = {}

Expand Down
7 changes: 7 additions & 0 deletions lib_comfyui/webui/tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
from lib_comfyui.default_workflow_types import sandbox_tab_workflow_type


webui_client_id = gr.Text(
elem_id='comfyui_webui_client_id',
visible=False,
)


def create_tab():
install_location = settings.get_install_location()
with gr.Blocks() as tab:
Expand All @@ -33,6 +39,7 @@ def create_tab():
key='workflow_type_ids',
value=external_code.get_workflow_type_ids(),
)
webui_client_id.render()
return [(tab, sandbox_tab_workflow_type.display_name, 'comfyui_webui_root')]


Expand Down
8 changes: 4 additions & 4 deletions scripts/comfyui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from modules import scripts
from lib_comfyui import global_state, platform_utils, external_code, default_workflow_types, comfyui_process
from lib_comfyui.webui import callbacks, settings, patches, gradio_utils, accordion
from lib_comfyui.webui import callbacks, settings, patches, gradio_utils, accordion, tab
from lib_comfyui.comfyui import iframe_requests, type_conversion


Expand Down Expand Up @@ -39,17 +39,17 @@ def ui(self, is_img2img):
self.accordion.arrange_components()
self.accordion.connect_events()
self.accordion.setup_infotext_fields(self)
return self.accordion.get_script_ui_components()
return (tab.webui_client_id,) + self.accordion.get_script_ui_components()

def process(self, p, queue_front, enabled_workflow_type_ids, **kwargs):
def process(self, p, webui_client_id, queue_front, enabled_workflow_type_ids, *args, **kwargs):
if not getattr(global_state, 'enabled', True):
return

if not hasattr(global_state, 'enabled_workflow_type_ids'):
global_state.enabled_workflow_type_ids = {}

global_state.webui_client_id = webui_client_id
global_state.enabled_workflow_type_ids.update(enabled_workflow_type_ids)

global_state.queue_front = queue_front
patches.patch_processing(p)

Expand Down

0 comments on commit 8dc1ef3

Please sign in to comment.