diff --git a/__init__.py b/__init__.py index 31d30828..02ff5cac 100644 --- a/__init__.py +++ b/__init__.py @@ -1,7 +1,37 @@ -from .modules import manager_ext_server -from .modules import share_3rdparty +legacy_manager_core_path = None +manager_core_path = None -WEB_DIRECTORY = "js" -NODE_CLASS_MAPPINGS = {} -__all__ = ['NODE_CLASS_MAPPINGS'] +def is_manager_core_exists(): + global legacy_manager_core_path + global manager_core_path + import os + import folder_paths + + comfy_path = os.path.dirname(folder_paths.__file__) + legacy_manager_core_path = os.path.join(comfy_path, 'custom_nodes', 'manager-core') + manager_core_path = legacy_manager_core_path + + manager_core_path_file = os.path.join(comfy_path, 'manager_core_path.txt') + if os.path.exists(manager_core_path_file): + with open(manager_core_path_file, 'r') as f: + manager_core_path = os.path.join(f.read().strip(), 'manager-core') + + return os.path.exists(manager_core_path) or os.path.exists(legacy_manager_core_path) + + +if not is_manager_core_exists(): + from .modules import migration_server + migration_server.manager_core_path = manager_core_path + + WEB_DIRECTORY = "migration_js" + NODE_CLASS_MAPPINGS = {} +else: + # Main code + from .modules import manager_ext_server + from .modules import share_3rdparty + + WEB_DIRECTORY = "js" + + NODE_CLASS_MAPPINGS = {} + __all__ = ['NODE_CLASS_MAPPINGS'] \ No newline at end of file diff --git a/migration_js/migration.js b/migration_js/migration.js new file mode 100644 index 00000000..f063e17f --- /dev/null +++ b/migration_js/migration.js @@ -0,0 +1,34 @@ +import { app } from "../../scripts/app.js"; +import { api } from "../../scripts/api.js"; + +app.registerExtension({ + name: "Comfy.ManagerExtMenu", + init() { + $el("style", { + textContent: style, + parent: document.head, + }); + }, + async setup() { + let cmGroup = new (await import("../../scripts/ui/components/buttonGroup.js")).ComfyButtonGroup( + new(await import("../../scripts/ui/components/button.js")).ComfyButton({ + icon: "puzzle", + action: async () => { + if(confirm('As some features of ComfyUI Manager have been integrated into ComfyUI, they have been separated into manager-core.\n\nComfyUI Manager only includes additional extension features that are not provided by manager-core.\n\nWill you install manager-core?')) { + app.ui.dialog.show('Installing manager-core...'); + app.ui.dialog.element.style.zIndex = 10010; + + await api.fetchApi("/manager/install_manager_core"); + + app.ui.dialog.show('The installation of manager-core will be completed after restarting.'); + } + }, + tooltip: "Need to install manager-core", + content: "Manager (Need To Install)", + classList: "comfyui-button comfyui-menu-mobile-collapse primary" + }).element + ); + + app.menu?.settingsGroup.element.before(cmGroup.element); + } +}); \ No newline at end of file diff --git a/modules/migration_server.py b/modules/migration_server.py new file mode 100644 index 00000000..45f7d404 --- /dev/null +++ b/modules/migration_server.py @@ -0,0 +1,17 @@ +import git +from aiohttp import web +from server import PromptServer + +manager_core_path = None +manager_core_url = "https://github.com/Comfy-Org/manager-core" + +@PromptServer.instance.routes.get("/manager/install_manager_core") +def install_manager_core(request): + if manager_core_path is not None: + repo = git.Repo.clone_from(manager_core_url, manager_core_path) + repo.git.clear_cache() + repo.close() + else: + print(f"[ComfyUI Manager] Failed to install `manager-core`") + + return web.Response(status=200)