Add hibernate option and using new menu

This commit is contained in:
syllebra
2025-09-17 09:44:29 -10:00
parent 1d265a39bd
commit 789263f7df
2 changed files with 127 additions and 108 deletions
+8 -5
View File
@@ -26,15 +26,18 @@ async def fetch_customnode_mappings(request):
print("BilboX:", type)
json_obj = {"server_op": type}
if(type == "shutdown"):
if type == "shutdown":
os.system("shutdown /s") # Shutdown
if(type == "reboot"):
if type == "hibernate":
os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") # hibernate
if type == "reboot":
os.system("shutdown /r") # Restart
if(type == "logout"):
if type == "logout":
os.system("shutdown /l") # logout
if(type == "lock"):
if type == "lock":
os.system("rundll32.exe user32.dll,LockWorkStation") # logout
return web.json_response(json_obj, content_type='application/json')
return web.json_response(json_obj, content_type="application/json")
WEB_DIRECTORY = "./web"
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
+93 -77
View File
@@ -1,111 +1,127 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
app.registerExtension({
name: "Comfy.BilboXReboot",
init() {
},
async setup() {
function toggle_menu(el) {
if ( el.style.display == "block"){
el.style.display = "none" ;
}else{
el.style.display = 'block';
}
}
function apiReboot(type) {
api.fetchApi('/bilbox/reboot?mode='+type)
.then(response => response.json())
.then(async data => {
api
.fetchApi("/bilbox/reboot?mode=" + type)
.then((response) => response.json())
.then(async (data) => {
try {
console.log(data["server_op"]);
}
catch (exception) {
} catch (exception) {
console.log("Problem when sending " + type + " to server...");
}
});
}
function create_menu(el, id, isnew=false) {
app.registerExtension({
name: "Comfy.BilboXReboot",
commands: [
{
id: "reboot_lock",
label: "Lock Session",
function: () => {
apiReboot("lock");
},
},
{
id: "reboot_logout",
label: "Logout",
function: () => {
apiReboot("logout");
},
},
{
id: "reboot_reboot",
label: "Reboot",
function: () => {
apiReboot("reboot");
},
},
{
id: "reboot_hibernate",
label: "Hibernate",
function: () => {
apiReboot("hibernate");
},
},
{
id: "reboot_shutdown",
label: "Shutdown",
function: () => {
apiReboot("shutdown");
},
},
],
menuCommands: [
// Create a nested menu structure
{
path: ["Server..."],
commands: ["reboot_lock", "reboot_logout", "reboot_reboot", "reboot_hibernate", "reboot_shutdown"],
},
],
init() {},
async setup() {
function toggle_menu(el) {
if (el.style.display == "block") {
el.style.display = "none";
} else {
el.style.display = "block";
}
}
function create_menu(el, id, isnew = false) {
let cl = "bx-reboot-context-menu";
if(isnew)
cl = "bx-reboot-cm-new " + cl;
el.insertAdjacentHTML('beforeend',' \
<div id="'+id+'" class="'+cl+'" style="display: none"> \
if (isnew) cl = "bx-reboot-cm-new " + cl;
el.insertAdjacentHTML(
"beforeend",
' \
<div id="' +
id +
'" class="' +
cl +
'" style="display: none"> \
<ul class="menu"> \
<li class="lock"><a href="#">Lock Session</a></li> \
<li class="logout"><a href="#">Logout</a></li> \
<li class="reboot"><a href="#">Reboot</a></li> \
<li class="hibernate"><a href="#">Hibernate</a></li> \
<li class="shutdown"><a href="#">Shutdown</a></li> \
</ul> \
</div> ');
</div> '
);
el.querySelector(".lock").onclick = () => { apiReboot("lock");}
el.querySelector(".logout").onclick = () => { apiReboot("logout");}
el.querySelector(".reboot").onclick = () => { apiReboot("reboot");}
el.querySelector(".shutdown").onclick = () => { apiReboot("shutdown");}
el.querySelector(".lock").onclick = () => {
apiReboot("lock");
};
el.querySelector(".logout").onclick = () => {
apiReboot("logout");
};
el.querySelector(".reboot").onclick = () => {
apiReboot("reboot");
};
el.querySelector(".hibernate").onclick = () => {
apiReboot("hibernate");
};
el.querySelector(".shutdown").onclick = () => {
apiReboot("shutdown");
};
}
// Old Interface
const menu = document.querySelector(".comfy-menu");
if(menu)
{
if (menu) {
const rebootButton = document.createElement("button");
rebootButton.id = "bxRebootButtonOld";
rebootButton.textContent = "Server...";
rebootButton.onclick = () => { toggle_menu(document.getElementById("bxRebootContextMenuOld")) }
rebootButton.onclick = () => {
toggle_menu(document.getElementById("bxRebootContextMenuOld"));
};
rebootButton.style.background = "linear-gradient(90deg, #442222 0%, #222222 100%)";
menu.append(rebootButton);
create_menu(menu, "bxRebootContextMenuOld")
create_menu(menu, "bxRebootContextMenuOld");
}
// New interface
function add_button_new_interface() {
const side_tb = document.querySelector(".side-tool-bar-end");
const params_button = document.querySelector(".pi-cog");
if(side_tb && params_button)
{
const shutButton = params_button.parentElement.cloneNode(true);
shutButton.id = "bxRebootButtonNew";
let shuticon = shutButton.querySelector(".pi-cog");
shuticon.classList.remove("pi-cog");
shuticon.classList.add("pi-power-off");
side_tb.append(shutButton);
shutButton.onclick = () => { toggle_menu(document.getElementById("bxRebootContextMenuNew")) }
create_menu(document.querySelector(".side-tool-bar-container"), "bxRebootContextMenuNew", true)
}
else
setTimeout(add_button_new_interface, 1000);
}
add_button_new_interface();
const setting = app.ui.settings.addSetting({
id: "BilboX.DistantShutdownMenu",
name: "Show distant server shutdown menu",
defaultValue: false,
type: "boolean",
onChange: async (v) => {
let b_old = document.getElementById("bxRebootButtonOld");
let m_old = document.getElementById("bxRebootContextMenuOld");
if(b_old)
b_old.style.display = v ? "block":"none";
if(!v && m_old)
m_old.style.display = "none";
let b_new = document.getElementById("bxRebootButtonNew");
let m_new = document.getElementById("bxRebootContextMenuNew");
if(b_new)
b_new.style.display = v ? "block":"none";
if(!v && m_new)
m_new.style.display = "none";
}
});
},
});