Main menu options to shutdown/reboot a windows server from ui

This commit is contained in:
syllebra
2023-12-08 14:56:31 -10:00
parent 9680e0eb9b
commit f8b7684d60
3 changed files with 128 additions and 1 deletions
+31 -1
View File
@@ -15,6 +15,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
# ensure .js and web copy
print("### Copying: BilboX web...")
@@ -24,4 +25,33 @@ import folder_paths
bx_path = os.path.dirname(__file__)
comfy_path = os.path.dirname(folder_paths.__file__)
dest_path = os.path.join(comfy_path, "web", "extensions")
shutil.copytree(os.path.join(bx_path,"web_to_copy"), os.path.join(dest_path,"bilbox"), dirs_exist_ok=True) # Fin
shutil.copytree(os.path.join(bx_path,"web_to_copy"), os.path.join(dest_path,"bilbox"), dirs_exist_ok=True) # Fin
# Expand Server api
import server
from aiohttp import web
import aiohttp
import json
import zipfile
import urllib.request
@server.PromptServer.instance.routes.get("/bilbox/reboot")
async def fetch_customnode_mappings(request):
type = request.rel_url.query["mode"]
print("BilboX:",type)
json_obj = {"server_op": type}
if(type == "shutdown"):
os.system("shutdown /s") # Shutdown
if(type == "reboot"):
os.system("shutdown /r") # Restart
if(type == "logout"):
os.system("shutdown /l") # logout
if(type == "lock"):
os.system("rundll32.exe user32.dll,LockWorkStation") # logout
return web.json_response(json_obj, content_type='application/json')
WEB_DIRECTORY = "reboot"
+61
View File
@@ -0,0 +1,61 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
app.registerExtension({
name: "Comfy.BilboXReboot",
init() {
},
async setup() {
const menu = document.querySelector(".comfy-menu");
const separator = document.createElement("hr");
separator.style.margin = "20px 0";
separator.style.width = "100%";
menu.append(separator);
const rebootButton = document.createElement("button");
rebootButton.textContent = "Server...";
rebootButton.onclick = () => {
if (document.getElementById("bxRebootContextMenu") .style.display == "block"){
document.getElementById("bxRebootContextMenu").style.display = "none" ;
}else{
var menu = document.getElementById("bxRebootContextMenu")
menu.style.display = 'block';
}
}
menu.append(rebootButton);
menu.insertAdjacentHTML('beforeend',' \
<div id="bxRebootContextMenu" class="bx-reboot-context-menu" 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="shutdown"><a href="#">Shutdown</a></li> \
</ul> \
</div> ');
function apiReboot(type) {
api.fetchApi('/bilbox/reboot?mode='+type)
.then(response => response.json())
.then(async data => {
try {
console.log(data["server_op"]);
}
catch (exception) {
console.log("Problem when sending "+type+" to server...");
}
});
}
menu.querySelector(".lock").onclick = () => { apiReboot("lock");}
menu.querySelector(".logout").onclick = () => { apiReboot("logout");}
menu.querySelector(".reboot").onclick = () => { apiReboot("reboot");}
menu.querySelector(".shutdown").onclick = () => { apiReboot("shutdown");}
rebootButton.style.background = "linear-gradient(90deg, #442222 0%, #222222 100%)";
//rebootButton.style.color = "black";
},
});
+36
View File
@@ -301,4 +301,40 @@ textarea:read-only::selection {
text-transform: capitalize;
font-style: italic;
}
.menu {
list-style: none;
display: flex;
flex-direction: column;
background-color: var(--comfy-input-bg);
border-radius: 10px;
box-shadow: 0 10px 20px rgb(64 64 64 / 5%);
padding: 10px 0;
}
.menu > li > a {
font: inherit;
border: 0;
padding: 10px 30px 10px 15px;
display: flex;
align-items: center;
position: relative;
text-decoration: unset;
color: var(--border-color);
font-weight: 500;
transition: 0.5s linear;
-webkit-transition: 0.5s linear;
-moz-transition: 0.5s linear;
-ms-transition: 0.5s linear;
-o-transition: 0.5s linear;
}
.menu > li > a:hover {
background:#161616;
color: #97a9c4;
}
.menu > li > a > i {
padding-right: 10px;
}
.menu > li.shutdown > a:hover {
color: red;
}