Skip to content

Commit

Permalink
use global_state
Browse files Browse the repository at this point in the history
  • Loading branch information
ljleb committed Aug 16, 2023
1 parent 9844a06 commit 294616b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
4 changes: 1 addition & 3 deletions lib_comfyui/comfyui_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

@ipc.restrict_to_process('webui')
def start():
from modules import shared

if not getattr(shared.opts, 'comfyui_enabled', True):
if not global_state.enabled:
return

install_location = settings.get_install_location()
Expand Down
10 changes: 10 additions & 0 deletions lib_comfyui/global_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
from lib_comfyui import ipc


enabled: bool = True
reverse_proxy_enabled: bool = False

workflow_types: list
enabled_workflow_type_ids: dict

ipc_strategy_class: type
ipc_strategy_class_name: str


class GlobalState(ModuleType):
__state = {}

Expand Down
4 changes: 3 additions & 1 deletion lib_comfyui/webui/reverse_proxy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from lib_comfyui.webui import settings
from lib_comfyui import ipc, global_state


@ipc.restrict_to_process("webui")
def create_comfyui_proxy(fast_api):
if not settings.is_reverse_proxy_enabled():
if not (global_state.enabled and global_state.reverse_proxy_enabled):
return

comfyui_url = settings.get_comfyui_server_url()
Expand Down
19 changes: 10 additions & 9 deletions lib_comfyui/webui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def create_section():

shared.opts.add_option("comfyui_reverse_proxy_enabled", shared.OptionInfo(
next(iter(reverse_proxy_choices.keys())), "Load ComfyUI iframes through a reverse proxy (requires reload UI. Needs --api. Default is on if webui is remote)", gr.Dropdown, lambda: {"choices": list(reverse_proxy_choices.keys())}, section=section))
shared.opts.onchange("comfyui_reverse_proxy_enabled", update_reverse_proxy_enabled)
update_reverse_proxy_enabled()


@ipc.restrict_to_process('webui')
Expand All @@ -57,6 +59,13 @@ def update_comfyui_graceful_termination_timeout():
global_state.comfyui_graceful_termination_timeout = timeout if timeout >= 0 else None


@ipc.restrict_to_process("webui")
def update_reverse_proxy_enabled():
from modules import shared
reverse_proxy_enabled = shared.opts.data.get('comfyui_reverse_proxy_enabled', next(iter(reverse_proxy_choices.keys())))
global_state.reverse_proxy_enabled = reverse_proxy_choices[reverse_proxy_enabled]() and getattr(shared.cmd_opts, "api", False)


ipc_strategy_choices = {
'Default': ipc.strategies.OsFriendlyIpcStrategy,
'Shared memory': ipc.strategies.SharedMemoryIpcStrategy,
Expand Down Expand Up @@ -95,7 +104,7 @@ def get_setting_value(setting_key):

@ipc.restrict_to_process('webui')
def get_comfyui_iframe_url():
if is_reverse_proxy_enabled():
if global_state.reverse_proxy_enabled:
return get_comfyui_reverse_proxy_url()
else:
return get_comfyui_client_url()
Expand Down Expand Up @@ -147,14 +156,6 @@ def get_port():
return get_setting_value('--port') or getattr(shared.cmd_opts, 'comfyui_port', 8188)


@ipc.restrict_to_process('webui')
def is_reverse_proxy_enabled():
from modules import shared
api_enabled = getattr(shared.cmd_opts, "api", False)
reverse_proxy_enabled = reverse_proxy_choices[shared.opts.data.get('comfyui_reverse_proxy_enabled', "Default")]()
return api_enabled and reverse_proxy_enabled


@ipc.restrict_to_process('webui')
def is_webui_server_remote():
from modules import shared
Expand Down

0 comments on commit 294616b

Please sign in to comment.