diff --git a/README.md b/README.md index d3d38a50..b3c957ab 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ You can execute ComfyUI by running either `./run_gpu.sh` or `./run_cpu.sh` depen # Changes +* **0.17** Support preview method setting feature * **0.14** Support robust update * **0.13** Support additional 'pip' section for install spec * **0.12** Better installation support for Windows. @@ -51,7 +52,7 @@ You can execute ComfyUI by running either `./run_gpu.sh` or `./run_cpu.sh` depen 2. If you click on 'Install Custom Nodes' or 'Install Models', an installer dialog will open. -![menu](misc/menu.png) +![menu](misc/menu.jpg) * When the 'Use local DB' feature is enabled, the application will utilize the data stored locally on your device, rather than retrieving node/model information over the internet diff --git a/__init__.py b/__init__.py index fd2e899e..1d7bc7f9 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,4 @@ +import configparser import shutil import folder_paths import os, sys @@ -32,7 +33,7 @@ sys.path.append('../..') from torchvision.datasets.utils import download_url # ensure .js -print("### Loading: ComfyUI-Manager (V0.16)") +print("### Loading: ComfyUI-Manager (V0.17)") comfy_ui_revision = "Unknown" @@ -48,6 +49,71 @@ local_db_extension_node_mappings = os.path.join(comfyui_manager_path, "extension git_script_path = os.path.join(os.path.dirname(__file__), "git_helper.py") startup_script_path = os.path.join(comfyui_manager_path, "startup-scripts") +config_path = os.path.join(os.path.dirname(__file__), "config.ini") +cached_config = None + + +from comfy.cli_args import args +import latent_preview + + +def write_config(): + config = configparser.ConfigParser() + config['default'] = { + 'preview_method': get_current_preview_method(), + } + with open(config_path, 'w') as configfile: + config.write(configfile) + + +def read_config(): + try: + config = configparser.ConfigParser() + config.read(config_path) + default_conf = config['default'] + + return { + 'preview_method': default_conf['preview_method'] + } + + except Exception: + return {'preview_method': get_current_preview_method()} + + +def get_config(): + global cached_config + + if cached_config is None: + cached_config = read_config() + + return cached_config + + +def get_current_preview_method(): + if args.preview_method == latent_preview.LatentPreviewMethod.Auto: + return "auto" + elif args.preview_method == latent_preview.LatentPreviewMethod.Latent2RGB: + return "latent2rgb" + elif args.preview_method == latent_preview.LatentPreviewMethod.TAESD: + return "taesd" + else: + return "none" + + +def set_preview_method(method): + if method == 'auto': + args.preview_method = latent_preview.LatentPreviewMethod.Auto + elif method == 'latent2rgb': + args.preview_method = latent_preview.LatentPreviewMethod.Latent2RGB + elif method == 'taesd': + args.preview_method = latent_preview.LatentPreviewMethod.TAESD + else: + args.preview_method = latent_preview.LatentPreviewMethod.NoPreviews + + get_config()['preview_method'] = args.preview_method + + +set_preview_method(get_config()['preview_method']) def try_install_script(url, repo_path, install_cmd): @@ -855,5 +921,16 @@ async def install_model(request): return web.Response(status=400) +@server.PromptServer.instance.routes.get("/manager/preview_method") +async def preview_method(request): + if "value" in request.rel_url.query: + set_preview_method(request.rel_url.query['value']) + write_config() + else: + return web.Response(text=get_current_preview_method(), status=200) + + return web.Response(status=200) + + NODE_CLASS_MAPPINGS = {} __all__ = ['NODE_CLASS_MAPPINGS'] diff --git a/js/comfyui-manager.js b/js/comfyui-manager.js index 5d75c0c3..44fc04c9 100644 --- a/js/comfyui-manager.js +++ b/js/comfyui-manager.js @@ -1338,6 +1338,20 @@ class ManagerMenuDialog extends ComfyDialog { () => fetchUpdates() }); + let preview_combo = document.createElement("select"); + preview_combo.appendChild($el('option', {value:'auto', text:'Preview method: Auto'}, [])); + preview_combo.appendChild($el('option', {value:'taesd', text:'Preview method: TAESD'}, [])); + preview_combo.appendChild($el('option', {value:'latent2rgb', text:'Preview method: Latent2RGB'}, [])); + preview_combo.appendChild($el('option', {value:'none', text:'Preview method: None'}, [])); + + fetch('/manager/preview_method') + .then(response => response.text()) + .then(data => { preview_combo.value = data; }) + + preview_combo.addEventListener('change', function(event) { + fetch(`/manager/preview_method?value=${event.target.value}`); + }); + const res = [ $el("tr.td", {width:"100%"}, [$el("font", {size:6, color:"white"}, [`ComfyUI Manager Menu`])]), @@ -1400,7 +1414,12 @@ class ManagerMenuDialog extends ComfyDialog { onclick: () => { window.open("https://blenderneko.github.io/ComfyUI-docs/", "comfyui-community-manual"); } }), - $el("br", {}, []), + $el("br", {}, []), + $el("hr", {width: "100%"}, []), + preview_combo, + $el("hr", {width: "100%"}, []), + $el("br", {}, []), + $el("button", { type: "button", textContent: "Close", diff --git a/misc/menu.png b/misc/menu.png deleted file mode 100644 index 03660c99..00000000 Binary files a/misc/menu.png and /dev/null differ