improve: update all - background updating

modified: update all - don't update ComfyUI
This commit is contained in:
Dr.Lt.Data 2025-02-13 22:04:33 +09:00
parent aaf569ca8c
commit 6ff6e05408
6 changed files with 257 additions and 231 deletions

View File

@ -42,7 +42,7 @@ import manager_downloader
from node_package import InstalledNodePackage from node_package import InstalledNodePackage
version_code = [3, 19, 1] version_code = [3, 20]
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')

View File

@ -419,7 +419,10 @@ async def task_worker():
manager_util.clear_pip_cache() manager_util.clear_pip_cache()
if res.result: if res.result:
return 'success' if res.action == 'skip':
return 'skip'
else:
return 'success'
logging.error(f"\nERROR: An error occurred while updating '{node_name}'.") logging.error(f"\nERROR: An error occurred while updating '{node_name}'.")
except Exception: except Exception:
@ -427,6 +430,25 @@ async def task_worker():
return f"An error occurred while updating '{node_name}'." return f"An error occurred while updating '{node_name}'."
async def do_update_comfyui() -> str:
try:
repo_path = os.path.dirname(folder_paths.__file__)
res = core.update_path(repo_path)
if res == "fail":
logging.error("ComfyUI update fail: The installed ComfyUI does not have a Git repository.")
return "The installed ComfyUI does not have a Git repository."
elif res == "updated":
logging.info("ComfyUI is updated.")
return "success"
else: # skipped
logging.info("ComfyUI is up-to-date.")
return "skip"
except Exception:
traceback.print_exc()
return f"An error occurred while updating 'comfyui'."
async def do_fix(item) -> str: async def do_fix(item) -> str:
ui_id, node_name, node_ver = item ui_id, node_name, node_ver = item
@ -550,6 +572,10 @@ async def task_worker():
msg = await do_install_model(item) msg = await do_install_model(item)
elif kind == 'update': elif kind == 'update':
msg = await do_update(item) msg = await do_update(item)
elif kind == 'update-main':
msg = await do_update(item)
elif kind == 'update-comfyui':
msg = await do_update_comfyui()
elif kind == 'fix': elif kind == 'fix':
msg = await do_fix(item) msg = await do_fix(item)
elif kind == 'uninstall': elif kind == 'uninstall':
@ -569,6 +595,11 @@ async def task_worker():
if kind == 'install-model': if kind == 'install-model':
model_result[ui_id] = msg model_result[ui_id] = msg
ui_target = "model_manager" ui_target = "model_manager"
elif kind == 'update-main':
nodepack_result[ui_id] = msg
ui_target = "main"
elif kind == 'update-comfyui':
ui_target = "main"
else: else:
nodepack_result[ui_id] = msg nodepack_result[ui_id] = msg
ui_target = "nodepack_manager" ui_target = "nodepack_manager"
@ -643,49 +674,37 @@ async def fetch_updates(request):
return web.Response(status=400) return web.Response(status=400)
@routes.get("/customnode/update_all") @routes.get("/manager/queue/update_all")
async def update_all(request): async def update_all(request):
if not is_allowed_security_level('middle'): if not is_allowed_security_level('middle'):
logging.error(SECURITY_MESSAGE_MIDDLE_OR_BELOW) logging.error(SECURITY_MESSAGE_MIDDLE_OR_BELOW)
return web.Response(status=403) return web.Response(status=403)
try: with task_worker_lock:
await core.save_snapshot_with_postfix('autosave') is_processing = task_worker_thread is not None and task_worker_thread.is_alive()
if is_processing:
return web.Response(status=401)
await core.save_snapshot_with_postfix('autosave')
if request.rel_url.query["mode"] == "local": if request.rel_url.query["mode"] == "local":
channel = 'local' channel = 'local'
else: else:
channel = core.get_config()['channel_url'] channel = core.get_config()['channel_url']
await core.unified_manager.reload(request.rel_url.query["mode"]) await core.unified_manager.reload(request.rel_url.query["mode"])
await core.unified_manager.get_custom_nodes(channel, request.rel_url.query["mode"]) await core.unified_manager.get_custom_nodes(channel, request.rel_url.query["mode"])
updated_cnr = [] for k, v in core.unified_manager.active_nodes.items():
for k, v in core.unified_manager.active_nodes.items(): if k == 'comfyui-manager':
if v[0] != 'nightly': # skip updating comfyui-manager if desktop version
res = core.unified_manager.unified_update(k, v[0]) if os.environ.get('__COMFYUI_DESKTOP_VERSION__'):
if res.action == 'switch-cnr' and res: continue
updated_cnr.append(k)
res = core.unified_manager.fetch_or_pull_git_repo(is_pull=True) update_item = k, k, v[0]
task_queue.put(("update-main", update_item))
res['updated'] += updated_cnr return web.Response(status=200)
for x in res['failed']:
logging.error(f"PULL FAILED: {x}")
if len(res['updated']) == 0 and len(res['failed']) == 0:
status = 200
else:
status = 201
logging.info("\nDone.")
return web.json_response(res, status=status, content_type='application/json')
except:
traceback.print_exc()
return web.Response(status=400)
finally:
manager_util.clear_pip_cache()
def convert_markdown_to_html(input_text): def convert_markdown_to_html(input_text):
@ -1281,26 +1300,10 @@ async def update_custom_node(request):
return web.Response(status=200) return web.Response(status=200)
@routes.get("/comfyui_manager/update_comfyui") @routes.get("/manager/queue/update_comfyui")
async def update_comfyui(request): async def update_comfyui(request):
logging.info("Update ComfyUI") task_queue.put(("update-comfyui", ('comfyui',)))
return web.Response(status=200)
try:
repo_path = os.path.dirname(folder_paths.__file__)
res = core.update_path(repo_path)
if res == "fail":
logging.error("ComfyUI update fail: The installed ComfyUI does not have a Git repository.")
return web.Response(status=400)
elif res == "updated":
logging.info("ComfyUI is updated.")
return web.Response(status=201)
else: # skipped
logging.info("ComfyUI is up-to-date.")
return web.Response(status=200)
except Exception as e:
logging.error(f"ComfyUI update fail: {e}", file=sys.stderr)
return web.Response(status=400)
@routes.get("/comfyui_manager/comfyui_versions") @routes.get("/comfyui_manager/comfyui_versions")

View File

@ -13,7 +13,9 @@ import {
import { OpenArtShareDialog } from "./comfyui-share-openart.js"; import { OpenArtShareDialog } from "./comfyui-share-openart.js";
import { import {
free_models, install_pip, install_via_git_url, manager_instance, free_models, install_pip, install_via_git_url, manager_instance,
rebootAPI, migrateAPI, setManagerInstance, show_message, customAlert, customPrompt } from "./common.js"; rebootAPI, migrateAPI, setManagerInstance, show_message, customAlert, customPrompt,
infoToast, showTerminal, setNeedRestart
} from "./common.js";
import { ComponentBuilderDialog, getPureName, load_components, set_component_policy } from "./components-manager.js"; import { ComponentBuilderDialog, getPureName, load_components, set_component_policy } from "./components-manager.js";
import { CustomNodesManager } from "./custom-nodes-manager.js"; import { CustomNodesManager } from "./custom-nodes-manager.js";
import { ModelManager } from "./model-manager.js"; import { ModelManager } from "./model-manager.js";
@ -225,7 +227,11 @@ var update_comfyui_button = null;
var switch_comfyui_button = null; var switch_comfyui_button = null;
var fetch_updates_button = null; var fetch_updates_button = null;
var update_all_button = null; var update_all_button = null;
var restart_stop_button = null;
let share_option = 'all'; let share_option = 'all';
var is_updating_all = false;
// copied style from https://github.com/pythongosssss/ComfyUI-Custom-Scripts // copied style from https://github.com/pythongosssss/ComfyUI-Custom-Scripts
const style = ` const style = `
@ -424,102 +430,54 @@ async function init_notice(notice) {
await init_share_option(); await init_share_option();
async function fetchNicknames() {
const response1 = await api.fetchApi(`/customnode/getmappings?mode=nickname`);
const mappings = await response1.json();
let result = {}; async function set_inprogress_mode() {
let nickname_patterns = []; update_comfyui_button.disabled = true;
update_comfyui_button.style.backgroundColor = "gray";
for (let i in mappings) { update_all_button.disabled = true;
let item = mappings[i]; update_all_button.style.backgroundColor = "gray";
var nickname;
if (item[1].nickname) {
nickname = item[1].nickname;
}
else if (item[1].title) {
nickname = item[1].title;
}
else {
nickname = item[1].title_aux;
}
for (let j in item[0]) { switch_comfyui_button.disabled = true;
result[item[0][j]] = nickname; switch_comfyui_button.style.backgroundColor = "gray";
}
if(item[1].nodename_pattern) { restart_stop_button.innerText = 'Stop';
nickname_patterns.push([item[1].nodename_pattern, nickname]);
}
}
return [result, nickname_patterns];
} }
const [nicknames, nickname_patterns] = await fetchNicknames();
function getNickname(node, nodename) { async function reset_action_buttons() {
if(node.nickname) { const isElectron = 'electronAPI' in window;
return node.nickname;
if(isElectron) {
update_all_button.innerText = "Update All Custom Nodes";
} }
else { else {
if (nicknames[nodename]) { update_all_button.innerText = "Update All";
node.nickname = nicknames[nodename];
}
else if(node.getInnerNodes) {
let pure_name = getPureName(node);
let groupNode = app.graph.extra?.groupNodes?.[pure_name];
if(groupNode) {
let packname = groupNode.packname;
node.nickname = packname;
}
return node.nickname;
}
else {
for(let i in nickname_patterns) {
let item = nickname_patterns[i];
if(nodename.match(item[0])) {
node.nickname = item[1];
}
}
}
return node.nickname;
} }
update_comfyui_button.innerText = "Update ComfyUI";
switch_comfyui_button.innerText = "Switch ComfyUI";
restart_stop_button.innerText = 'Restart';
update_comfyui_button.disabled = false;
update_all_button.disabled = false;
switch_comfyui_button.disabled = false;
update_comfyui_button.style.backgroundColor = "";
update_all_button.style.backgroundColor = "";
switch_comfyui_button.style.backgroundColor = "";
} }
async function updateComfyUI() { async function updateComfyUI() {
let prev_text = update_comfyui_button.innerText; let prev_text = update_comfyui_button.innerText;
update_comfyui_button.innerText = "Updating ComfyUI..."; update_comfyui_button.innerText = "Updating ComfyUI...";
update_comfyui_button.disabled = true;
update_comfyui_button.style.backgroundColor = "gray";
try { set_inprogress_mode();
const response = await api.fetchApi('/comfyui_manager/update_comfyui');
if (response.status == 400) { const response = await api.fetchApi('/manager/queue/update_comfyui');
show_message('Failed to update ComfyUI.');
return false;
}
if (response.status == 201) { showTerminal();
show_message('ComfyUI has been successfully updated.'); await api.fetchApi('/manager/queue/start');
}
else {
show_message('ComfyUI is already up to date with the latest version.');
}
return true;
}
catch (exception) {
show_message(`Failed to update ComfyUI / ${exception}`);
return false;
}
finally {
update_comfyui_button.disabled = false;
update_comfyui_button.innerText = prev_text;
update_comfyui_button.style.backgroundColor = "";
}
} }
function showVersionSelectorDialog(versions, current, onSelect) { function showVersionSelectorDialog(versions, current, onSelect) {
@ -647,26 +605,32 @@ function showVersionSelectorDialog(versions, current, onSelect) {
} }
async function switchComfyUI() { async function switchComfyUI() {
let res = await api.fetchApi(`/comfyui_manager/comfyui_versions`, { cache: "no-store" }); let res = await api.fetchApi(`/comfyui_manager/comfyui_versions`, { cache: "no-store" });
if(res.status == 200) { if(res.status == 200) {
let obj = await res.json(); let obj = await res.json();
let versions = []; let versions = [];
let default_version; let default_version;
for(let v of obj.versions) { for(let v of obj.versions) {
default_version = v; default_version = v;
versions.push(v); versions.push(v);
} }
showVersionSelectorDialog(versions, obj.current, (selected_version) => { showVersionSelectorDialog(versions, obj.current, async (selected_version) => {
api.fetchApi(`/comfyui_manager/comfyui_switch_version?ver=${selected_version}`, { cache: "no-store" }); let response = await api.fetchApi(`/comfyui_manager/comfyui_switch_version?ver=${selected_version}`, { cache: "no-store" });
}); if (response.status == 200) {
} infoToast(`ComfyUI version is switched to ${selected_version}`);
else { }
show_message('Failed to fetch ComfyUI versions.'); else {
} customAlert('Failed to switch ComfyUI version.');
}
});
}
else {
customAlert('Failed to fetch ComfyUI versions.');
}
} }
@ -720,70 +684,100 @@ async function fetchUpdates(update_check_checkbox) {
} }
} }
async function updateAll(update_check_checkbox, manager_dialog) { async function onQueueStatus(event) {
let prev_text = update_all_button.innerText; const isElectron = 'electronAPI' in window;
update_all_button.innerText = "Updating all...(ComfyUI)";
update_all_button.disabled = true;
update_all_button.style.backgroundColor = "gray";
try { if(event.detail.status == 'in_progress') {
var mode = manager_instance.datasrc_combo.value; set_inprogress_mode();
update_all_button.innerText = `in progress.. (${event.detail.done_count}/${event.detail.total_count})`;
}
else if(event.detail.status == 'done') {
reset_action_buttons();
update_all_button.innerText = "Updating all..."; if(!is_updating_all) {
const response1 = await api.fetchApi('/comfyui_manager/update_comfyui'); return;
const response2 = await api.fetchApi(`/customnode/update_all?mode=${mode}`);
if (response2.status == 403) {
show_message('This action is not allowed with this security level configuration.');
return false;
} }
if (response1.status == 400 || response2.status == 400) { let success_list = [];
show_message('Failed to update ComfyUI or several extensions.<BR><BR>See terminal log.<BR>'); let failed_list = [];
return false;
for(let k in event.detail.nodepack_result){
let v = event.detail.nodepack_result[k];
if(v == 'success')
success_list.push(k);
else if(v == 'skip') {
// do nothing
}
else
failed_list.push(k);
} }
if(response1.status == 201 || response2.status == 201) { let msg = "";
const update_info = await response2.json();
if(success_list.length == 0) {
let failed_list = ""; if(failed_list.length == 0) {
if(update_info.failed.length > 0) { msg += "All custom nodes are already up to date.";
failed_list = "<BR>FAILED: "+update_info.failed.join(", ");
} }
let updated_list = "";
if(update_info.updated.length > 0) {
updated_list = "<BR>UPDATED: "+update_info.updated.join(", ");
}
show_message(
"ComfyUI and all extensions have been updated to the latest version.<BR>To apply the updated custom node, please <button class='cm-small-button' id='cm-reboot-button5'>RESTART</button> ComfyUI. And refresh browser.<BR>"
+failed_list
+updated_list
);
const rebootButton = document.getElementById('cm-reboot-button5');
rebootButton.addEventListener("click",
function() {
if(rebootAPI()) {
manager_dialog.close();
}
});
} }
else { else {
show_message('ComfyUI and all extensions are already up-to-date with the latest versions.'); msg = "To apply the updates, you need to <button class='cm-small-button' id='cm-reboot-button5'>RESTART</button> ComfyUI.<hr>";
msg += "The following custom nodes have been updated:<ul>";
for(let x in success_list) {
msg += '<li>'+success_list[x]+'</li>';
}
msg += "</ul>";
setNeedRestart(true);
}
if(failed_list.length > 0) {
msg += '<br>The update for the following custom nodes has failed:<ul>';
for(let x in failed_list) {
msg += '<li>'+failed_list[x]+'</li>';
}
msg += '</ul>'
} }
return true; show_message(msg);
const rebootButton = document.getElementById('cm-reboot-button5');
rebootButton?.addEventListener("click",
function() {
if(rebootAPI()) {
manager_dialog.close();
}
});
} }
catch (exception) { }
show_message(`Failed to update ComfyUI or several extensions / ${exception}`);
return false; api.addEventListener("cm-queue-status", onQueueStatus);
async function updateAll(update_comfyui, manager_dialog) {
let prev_text = update_all_button.innerText;
update_all_button.innerText = "Updating...";
set_inprogress_mode();
var mode = manager_instance.datasrc_combo.value;
showTerminal();
if(update_comfyui) {
update_all_button.innerText = "Updating ComfyUI...";
await api.fetchApi('/manager/queue/update_comfyui');
} }
finally {
update_all_button.disabled = false; const response = await api.fetchApi(`/manager/queue/update_all?mode=${mode}`);
update_all_button.innerText = prev_text;
update_all_button.style.backgroundColor = ""; if (response.status == 401) {
customAlert('Another task is already in progress. Please stop the ongoing task first.');
}
else if(response.status == 200) {
is_updating_all = true;
await api.fetchApi('/manager/queue/start');
} }
} }
@ -807,6 +801,16 @@ const isOutputNode = (node) => {
return SUPPORTED_OUTPUT_NODE_TYPES.includes(node.type); return SUPPORTED_OUTPUT_NODE_TYPES.includes(node.type);
} }
function restartOrStop() {
if(restart_stop_button.innerText == 'Restart'){
rebootAPI();
}
else {
api.fetchApi('/manager/queue/reset');
infoToast('Cancel', 'Remaining tasks will stop after completing the current task.');
}
}
// ----------- // -----------
class ManagerMenuDialog extends ComfyDialog { class ManagerMenuDialog extends ComfyDialog {
createControlsMid() { createControlsMid() {
@ -843,14 +847,32 @@ class ManagerMenuDialog extends ComfyDialog {
() => fetchUpdates(this.update_check_checkbox) () => fetchUpdates(this.update_check_checkbox)
}); });
update_all_button = restart_stop_button =
$el("button.cm-button", { $el("button.cm-button-red", {
type: "button", type: "button",
textContent: "Update All", textContent: "Restart",
onclick: onclick: () => restartOrStop()
() => updateAll(this.update_check_checkbox, self)
}); });
if(isElectron) {
update_all_button =
$el("button.cm-button", {
type: "button",
textContent: "Update All Custom Nodes",
onclick:
() => updateAll(false, self)
});
}
else {
update_all_button =
$el("button.cm-button", {
type: "button",
textContent: "Update All",
onclick:
() => updateAll(true, self)
});
}
const res = const res =
[ [
$el("button.cm-button", { $el("button.cm-button", {
@ -909,11 +931,7 @@ class ManagerMenuDialog extends ComfyDialog {
fetch_updates_button, fetch_updates_button,
$el("br", {}, []), $el("br", {}, []),
$el("button.cm-button-red", { restart_stop_button,
type: "button",
textContent: "Restart",
onclick: () => rebootAPI()
}),
]; ];
let migration_btn = let migration_btn =

View File

@ -431,4 +431,25 @@ export function showTerminal() {
catch(exception) { catch(exception) {
// do nothing // do nothing
} }
} }
let need_restart = false;
export function setNeedRestart(value) {
need_restart = value;
}
async function onReconnected(event) {
if(need_restart) {
setNeedRestart(false);
const confirmed = await customConfirm("To apply the changes to the node pack's installation status, you need to refresh the browser. Would you like to refresh?");
if (!confirmed) {
return;
}
window.location.reload(true);
}
}
api.addEventListener('reconnected', onReconnected);

View File

@ -5,7 +5,7 @@ import { api } from "../../scripts/api.js";
import { import {
manager_instance, rebootAPI, install_via_git_url, manager_instance, rebootAPI, install_via_git_url,
fetchData, md5, icons, show_message, customConfirm, customAlert, customPrompt, fetchData, md5, icons, show_message, customConfirm, customAlert, customPrompt,
sanitizeHTML, infoToast, showTerminal sanitizeHTML, infoToast, showTerminal, setNeedRestart
} from "./common.js"; } from "./common.js";
// https://cenfun.github.io/turbogrid/api.html // https://cenfun.github.io/turbogrid/api.html
@ -401,7 +401,6 @@ export class CustomNodesManager {
this.init(); this.init();
api.addEventListener("cm-queue-status", this.onQueueStatus); api.addEventListener("cm-queue-status", this.onQueueStatus);
api.addEventListener('reconnected', this.onReconnected);
} }
init() { init() {
@ -1403,21 +1402,6 @@ export class CustomNodesManager {
} }
} }
async onReconnected(event) {
let self = CustomNodesManager.instance;
if(self.need_restart) {
self.need_restart = false;
const confirmed = await customConfirm("To apply the changes to the node pack's installation status, you need to refresh the browser. Would you like to refresh?");
if (!confirmed) {
return;
}
window.location.reload(true);
}
}
async onQueueStatus(event) { async onQueueStatus(event) {
let self = CustomNodesManager.instance; let self = CustomNodesManager.instance;
if(event.detail.status == 'in_progress' && event.detail.ui_target == 'nodepack_manager') { if(event.detail.status == 'in_progress' && event.detail.ui_target == 'nodepack_manager') {
@ -1457,7 +1441,7 @@ export class CustomNodesManager {
for(let hash in result){ for(let hash in result){
let v = result[hash]; let v = result[hash];
if(v != 'success') if(v != 'success' && v != 'skip')
errorMsg += v+'\n'; errorMsg += v+'\n';
} }
@ -1898,7 +1882,7 @@ export class CustomNodesManager {
showRestart() { showRestart() {
this.element.querySelector(".cn-manager-restart").style.display = "block"; this.element.querySelector(".cn-manager-restart").style.display = "block";
this.need_restart = true; setNeedRestart(true);
} }
showStop() { showStop() {

View File

@ -1,7 +1,7 @@
[project] [project]
name = "comfyui-manager" name = "comfyui-manager"
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI." description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
version = "3.19.1" version = "3.20"
license = { file = "LICENSE.txt" } license = { file = "LICENSE.txt" }
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"] dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]