mirror of
https://git.datalinker.icu/ltdrdata/ComfyUI-Manager
synced 2025-12-23 04:54:24 +08:00
add update ComfyUI button
This commit is contained in:
parent
85f69e4271
commit
9deca56c1f
57
__init__.py
57
__init__.py
@ -16,7 +16,7 @@ sys.path.append('../..')
|
|||||||
from torchvision.datasets.utils import download_url
|
from torchvision.datasets.utils import download_url
|
||||||
|
|
||||||
# ensure .js
|
# ensure .js
|
||||||
print("### Loading: ComfyUI-Manager (V0.4.1)")
|
print("### Loading: ComfyUI-Manager (V0.5)")
|
||||||
|
|
||||||
comfy_path = os.path.dirname(folder_paths.__file__)
|
comfy_path = os.path.dirname(folder_paths.__file__)
|
||||||
custom_nodes_path = os.path.join(comfy_path, 'custom_nodes')
|
custom_nodes_path = os.path.join(comfy_path, 'custom_nodes')
|
||||||
@ -120,8 +120,8 @@ def setup_js():
|
|||||||
js_src_path = os.path.join(comfyui_manager_path, "js", "comfyui-manager.js")
|
js_src_path = os.path.join(comfyui_manager_path, "js", "comfyui-manager.js")
|
||||||
shutil.copy(js_src_path, js_dest_path)
|
shutil.copy(js_src_path, js_dest_path)
|
||||||
|
|
||||||
setup_js()
|
|
||||||
|
|
||||||
|
setup_js()
|
||||||
|
|
||||||
# Expand Server api
|
# Expand Server api
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ def check_a_custom_node_installed(item):
|
|||||||
except:
|
except:
|
||||||
item['installed'] = 'True'
|
item['installed'] = 'True'
|
||||||
|
|
||||||
elif os.path.exists(dir_path+".disabled"):
|
elif os.path.exists(dir_path + ".disabled"):
|
||||||
item['installed'] = 'Disabled'
|
item['installed'] = 'Disabled'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -264,7 +264,6 @@ async def fetch_externalmodel_list(request):
|
|||||||
else:
|
else:
|
||||||
uri = 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/model-list.json'
|
uri = 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/model-list.json'
|
||||||
|
|
||||||
|
|
||||||
json_obj = await get_data(uri)
|
json_obj = await get_data(uri)
|
||||||
check_model_installed(json_obj)
|
check_model_installed(json_obj)
|
||||||
|
|
||||||
@ -275,7 +274,8 @@ def unzip_install(files):
|
|||||||
temp_filename = 'manager-temp.zip'
|
temp_filename = 'manager-temp.zip'
|
||||||
for url in files:
|
for url in files:
|
||||||
try:
|
try:
|
||||||
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
|
headers = {
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
|
||||||
|
|
||||||
req = urllib.request.Request(url, headers=headers)
|
req = urllib.request.Request(url, headers=headers)
|
||||||
response = urllib.request.urlopen(req)
|
response = urllib.request.urlopen(req)
|
||||||
@ -344,8 +344,8 @@ def copy_uninstall(files, js_path_name=None):
|
|||||||
try:
|
try:
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
elif os.path.exists(file_path+".disabled"):
|
elif os.path.exists(file_path + ".disabled"):
|
||||||
os.remove(file_path+".disabled")
|
os.remove(file_path + ".disabled")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Uninstall(copy) error: {url} / {e}")
|
print(f"Uninstall(copy) error: {url} / {e}")
|
||||||
return False
|
return False
|
||||||
@ -440,6 +440,8 @@ def gitclone_install(files):
|
|||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def rmtree(path):
|
def rmtree(path):
|
||||||
retry_count = 3
|
retry_count = 3
|
||||||
|
|
||||||
@ -462,6 +464,7 @@ def rmtree(path):
|
|||||||
|
|
||||||
print(f"Uninstall retry({retry_count})")
|
print(f"Uninstall retry({retry_count})")
|
||||||
|
|
||||||
|
|
||||||
def gitclone_uninstall(files):
|
def gitclone_uninstall(files):
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
@ -479,8 +482,8 @@ def gitclone_uninstall(files):
|
|||||||
|
|
||||||
if os.path.exists(dir_path):
|
if os.path.exists(dir_path):
|
||||||
rmtree(dir_path)
|
rmtree(dir_path)
|
||||||
elif os.path.exists(dir_path+".disabled"):
|
elif os.path.exists(dir_path + ".disabled"):
|
||||||
rmtree(dir_path+".disabled")
|
rmtree(dir_path + ".disabled")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Uninstall(git-clone) error: {url} / {e}")
|
print(f"Uninstall(git-clone) error: {url} / {e}")
|
||||||
return False
|
return False
|
||||||
@ -528,7 +531,7 @@ def gitclone_set_active(files, is_disable):
|
|||||||
def gitclone_update(files):
|
def gitclone_update(files):
|
||||||
import os
|
import os
|
||||||
|
|
||||||
print(f"update: {files}")
|
print(f"Update: {files}")
|
||||||
for url in files:
|
for url in files:
|
||||||
try:
|
try:
|
||||||
repo_name = os.path.splitext(os.path.basename(url))[0].replace(".git", "")
|
repo_name = os.path.splitext(os.path.basename(url))[0].replace(".git", "")
|
||||||
@ -617,6 +620,40 @@ async def install_custom_node(request):
|
|||||||
return web.Response(status=400)
|
return web.Response(status=400)
|
||||||
|
|
||||||
|
|
||||||
|
@server.PromptServer.instance.routes.get("/comfyui_manager/update_comfyui")
|
||||||
|
async def install_custom_node(request):
|
||||||
|
print(f"Update ComfyUI")
|
||||||
|
|
||||||
|
try:
|
||||||
|
repo_path = os.path.dirname(folder_paths.__file__)
|
||||||
|
|
||||||
|
if not os.path.exists(os.path.join(repo_path, '.git')):
|
||||||
|
print(f"ComfyUI update fail: The installed ComfyUI does not have a Git repository.")
|
||||||
|
return web.Response(status=400)
|
||||||
|
|
||||||
|
# version check
|
||||||
|
repo = git.Repo(repo_path)
|
||||||
|
remote_name = 'origin'
|
||||||
|
remote = repo.remote(name=remote_name)
|
||||||
|
remote.fetch()
|
||||||
|
|
||||||
|
commit_hash = repo.head.commit.hexsha
|
||||||
|
remote_commit_hash = repo.refs[f'{remote_name}/HEAD'].object.hexsha
|
||||||
|
|
||||||
|
print(f"{commit_hash} != {remote_commit_hash}")
|
||||||
|
if commit_hash != remote_commit_hash:
|
||||||
|
git_pull(repo_path)
|
||||||
|
execute_install_script("ComfyUI", repo_path)
|
||||||
|
return web.Response(status=201)
|
||||||
|
else:
|
||||||
|
return web.Response(status=200)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ComfyUI update fail: {e}")
|
||||||
|
pass
|
||||||
|
|
||||||
|
return web.Response(status=400)
|
||||||
|
|
||||||
|
|
||||||
@server.PromptServer.instance.routes.post("/customnode/toggle_active")
|
@server.PromptServer.instance.routes.post("/customnode/toggle_active")
|
||||||
async def install_custom_node(request):
|
async def install_custom_node(request):
|
||||||
json_data = await request.json()
|
json_data = await request.json()
|
||||||
|
|||||||
@ -2,6 +2,8 @@ import { app } from "/scripts/app.js";
|
|||||||
import { ComfyDialog, $el } from "/scripts/ui.js";
|
import { ComfyDialog, $el } from "/scripts/ui.js";
|
||||||
import {ComfyWidgets} from "../../scripts/widgets.js";
|
import {ComfyWidgets} from "../../scripts/widgets.js";
|
||||||
|
|
||||||
|
var update_comfyui_button = null;
|
||||||
|
|
||||||
async function getCustomNodes() {
|
async function getCustomNodes() {
|
||||||
var mode = "url";
|
var mode = "url";
|
||||||
if(ManagerMenuDialog.instance.local_mode_checkbox.checked)
|
if(ManagerMenuDialog.instance.local_mode_checkbox.checked)
|
||||||
@ -69,6 +71,41 @@ async function install_custom_node(target, caller, mode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateComfyUI() {
|
||||||
|
update_comfyui_button.innerText = "Updating ComfyUI...";
|
||||||
|
update_comfyui_button.disabled = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/comfyui_manager/update_comfyui');
|
||||||
|
|
||||||
|
if(response.status == 400) {
|
||||||
|
app.ui.dialog.show('Failed to update ComfyUI');
|
||||||
|
app.ui.dialog.element.style.zIndex = 9999;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(response.status == 201) {
|
||||||
|
app.ui.dialog.show('ComfyUI has been successfully updated.');
|
||||||
|
app.ui.dialog.element.style.zIndex = 9999;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
app.ui.dialog.show('ComfyUI is already up to date with the latest version.');
|
||||||
|
app.ui.dialog.element.style.zIndex = 9999;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(exception) {
|
||||||
|
app.ui.dialog.show(`Failed to update ComfyUI / ${exception}`);
|
||||||
|
app.ui.dialog.element.style.zIndex = 9999;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
update_comfyui_button.disabled = false;
|
||||||
|
update_comfyui_button.innerText = "Update ComfyUI";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function install_model(target) {
|
async function install_model(target) {
|
||||||
if(ModelInstaller.instance) {
|
if(ModelInstaller.instance) {
|
||||||
ModelInstaller.instance.startInstall(target);
|
ModelInstaller.instance.startInstall(target);
|
||||||
@ -809,6 +846,14 @@ class ManagerMenuDialog extends ComfyDialog {
|
|||||||
const checkbox_text = $el("label",{},["Use local DB"])
|
const checkbox_text = $el("label",{},["Use local DB"])
|
||||||
checkbox_text.style.color = "var(--fg-color)"
|
checkbox_text.style.color = "var(--fg-color)"
|
||||||
|
|
||||||
|
update_comfyui_button =
|
||||||
|
$el("button", {
|
||||||
|
type: "button",
|
||||||
|
textContent: "Update ComfyUI",
|
||||||
|
onclick:
|
||||||
|
() => updateComfyUI()
|
||||||
|
});
|
||||||
|
|
||||||
const res =
|
const res =
|
||||||
[
|
[
|
||||||
$el("tr.td", {width:"100%"}, [$el("font", {size:6, color:"white"}, [`Manager Menu`])]),
|
$el("tr.td", {width:"100%"}, [$el("font", {size:6, color:"white"}, [`Manager Menu`])]),
|
||||||
@ -837,6 +882,8 @@ class ManagerMenuDialog extends ComfyDialog {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
update_comfyui_button,
|
||||||
|
|
||||||
$el("br", {}, []),
|
$el("br", {}, []),
|
||||||
$el("button", {
|
$el("button", {
|
||||||
type: "button",
|
type: "button",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user