mirror of
https://git.datalinker.icu/ltdrdata/ComfyUI-Manager
synced 2025-12-09 06:04:31 +08:00
feat: free model/cache feature on new style menu.
This commit is contained in:
parent
3e456756d8
commit
87fc538fd1
@ -23,7 +23,7 @@ sys.path.append(glob_path)
|
||||
import cm_global
|
||||
from manager_util import *
|
||||
|
||||
version = [2, 44, 3]
|
||||
version = [2, 45]
|
||||
version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '')
|
||||
|
||||
|
||||
|
||||
@ -20,6 +20,23 @@ import { SnapshotManager } from "./snapshot.js";
|
||||
|
||||
var docStyle = document.createElement('style');
|
||||
docStyle.innerHTML = `
|
||||
.comfy-toast {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
z-index: 1000;
|
||||
transition: opacity 0.5s;
|
||||
}
|
||||
|
||||
.comfy-toast-fadeout {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
#cm-manager-dialog {
|
||||
width: 1000px;
|
||||
height: 520px;
|
||||
@ -1288,18 +1305,43 @@ app.registerExtension({
|
||||
separator.style.width = "100%";
|
||||
menu.append(separator);
|
||||
|
||||
// new style Manager button
|
||||
app.menu?.saveButton.element.after(new(await import("../../scripts/ui/components/button.js")).ComfyButton({
|
||||
icon: "puzzle",
|
||||
action: () => {
|
||||
if(!manager_instance)
|
||||
setManagerInstance(new ManagerMenuDialog());
|
||||
manager_instance.show();
|
||||
},
|
||||
tooltip: "ComfyUI Manager",
|
||||
content: "ComfyUI Manager",
|
||||
classList: "comfyui-button comfyui-menu-mobile-collapse primary"
|
||||
}).element);
|
||||
try {
|
||||
// new style Manager button
|
||||
app.menu?.saveButton.element.after(new(await import("../../scripts/ui/components/button.js")).ComfyButton({
|
||||
icon: "puzzle",
|
||||
action: () => {
|
||||
if(!manager_instance)
|
||||
setManagerInstance(new ManagerMenuDialog());
|
||||
manager_instance.show();
|
||||
},
|
||||
tooltip: "ComfyUI Manager",
|
||||
content: "ComfyUI Manager",
|
||||
classList: "comfyui-button comfyui-menu-mobile-collapse primary"
|
||||
}).element);
|
||||
|
||||
// unload models button into new style Manager button
|
||||
let cmGroup = new (await import("../../scripts/ui/components/buttonGroup.js")).ComfyButtonGroup(
|
||||
new(await import("../../scripts/ui/components/button.js")).ComfyButton({
|
||||
icon: "vacuum-outline",
|
||||
action: () => {
|
||||
free_models();
|
||||
},
|
||||
tooltip: "Unload Models"
|
||||
}).element,
|
||||
new(await import("../../scripts/ui/components/button.js")).ComfyButton({
|
||||
icon: "vacuum",
|
||||
action: () => {
|
||||
free_models(true);
|
||||
},
|
||||
tooltip: "Unload Whole Cache"
|
||||
}).element
|
||||
);
|
||||
|
||||
app.menu?.settingsGroup.element.before(cmGroup.element);
|
||||
}
|
||||
catch(exception) {
|
||||
log.console('ComfyUI is outdated. New style menu based features are disabled.');
|
||||
}
|
||||
|
||||
// old style Manager button
|
||||
const managerButton = document.createElement("button");
|
||||
@ -1311,7 +1353,6 @@ app.registerExtension({
|
||||
}
|
||||
menu.append(managerButton);
|
||||
|
||||
|
||||
const shareButton = document.createElement("button");
|
||||
shareButton.id = "shareButton";
|
||||
shareButton.textContent = "Share";
|
||||
|
||||
48
js/common.js
48
js/common.js
@ -1,5 +1,6 @@
|
||||
import { app } from "../../scripts/app.js";
|
||||
import { api } from "../../scripts/api.js";
|
||||
import { $el, ComfyDialog } from "../../scripts/ui.js";
|
||||
|
||||
export function show_message(msg) {
|
||||
app.ui.dialog.show(msg);
|
||||
@ -30,6 +31,15 @@ export function setManagerInstance(obj) {
|
||||
manager_instance = obj;
|
||||
}
|
||||
|
||||
export function showToast(message, duration = 3000) {
|
||||
const toast = $el("div.comfy-toast", {textContent: message});
|
||||
document.body.appendChild(toast);
|
||||
setTimeout(() => {
|
||||
toast.classList.add("comfy-toast-fadeout");
|
||||
setTimeout(() => toast.remove(), 500);
|
||||
}, duration);
|
||||
}
|
||||
|
||||
function isValidURL(url) {
|
||||
if(url.includes('&'))
|
||||
return false;
|
||||
@ -106,18 +116,34 @@ export async function install_via_git_url(url, manager_dialog) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function free_models() {
|
||||
let res = await api.fetchApi(`/free`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: '{"unload_models": true}'
|
||||
});
|
||||
export async function free_models(free_execution_cache) {
|
||||
try {
|
||||
let mode = "";
|
||||
if(free_execution_cache) {
|
||||
mode = '{"unload_models": true, "free_memory": true}';
|
||||
}
|
||||
else {
|
||||
mode = '{"unload_models": true}';
|
||||
}
|
||||
|
||||
if(res.status == 200) {
|
||||
show_message('Models have been unloaded.')
|
||||
}
|
||||
else {
|
||||
show_message('Unloading of models failed.<BR><BR>Installed ComfyUI may be an outdated version.')
|
||||
let res = await api.fetchApi(`/free`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: mode
|
||||
});
|
||||
|
||||
if (res.status == 200) {
|
||||
if(free_execution_cache) {
|
||||
showToast("'Models' and 'Execution Cache' have been unloaded.", 3000);
|
||||
}
|
||||
else {
|
||||
showToast("Models' have been unloaded.", 3000);
|
||||
}
|
||||
} else {
|
||||
showToast('Unloading of models failed. Installed ComfyUI may be an outdated version.', 5000);
|
||||
}
|
||||
} catch (error) {
|
||||
showToast('An error occurred while trying to unload models.', 5000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
[project]
|
||||
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."
|
||||
version = "2.44.3"
|
||||
version = "2.45"
|
||||
license = "LICENSE"
|
||||
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user