1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

feat(instances): the VM page shows the VM's screen

A running or paused VM with a VNC or SPICE console shows its screen
beside the summary (virDomainScreenshot, PNG), read again every 10 s
while the page is in view; clicking it opens the console. It is for
those who may open the console (the screen shows what the console
does) and is left out while there is none to show, also on a host whose
libvirt gives PPM. The VM list does not read screens: one a VM would
cost too much.
This commit is contained in:
catborise 2026-11-25 11:44:35 +03:00
parent 8625d6250a
commit d5cc696d73
18 changed files with 205 additions and 9 deletions

View file

@ -382,3 +382,20 @@ td .tag-more {
.run-none { background: var(--bs-secondary-bg); }
/* high contrast themes would drop the marks' colours, which carry their meaning */
@media (forced-colors: active) { .run-mark { forced-color-adjust: none; } }
/* the VM page's screen thumbnail (instance.html): the console's picture, a button that opens it */
.vm-screen {
display: block;
padding: 0;
width: 100%;
max-width: 16rem;
aspect-ratio: 4 / 3;
overflow: hidden;
background: #000;
border: 1px solid var(--bs-border-color);
border-radius: var(--bs-border-radius);
}
.vm-screen[hidden] { display: none; }
.vm-screen img { display: block; width: 100%; height: 100%; object-fit: contain; }
.vm-screen:focus-visible { outline: 0; box-shadow: var(--bs-focus-ring-x, 0) var(--bs-focus-ring-y, 0) 0 var(--bs-focus-ring-width) var(--bs-focus-ring-color); }
@media (min-width: 768px) { .vm-screen { flex: none; width: 13rem; align-self: flex-start; } }

View file

@ -20,6 +20,25 @@
if (element) element.addEventListener(event, handler);
}
// the VM's screen: read now and every 10 s while the page is in view, one read at a time; a frame
// replaces the shown one once it has fully come, and the screen is hidden while there is none
var screen = document.getElementById("vm-screen");
if (screen) {
var shown = screen.querySelector("img");
var reading = false;
var read_screen = function () {
if (reading || document.hidden) return;
reading = true;
var frame = new Image();
frame.alt = shown.alt;
frame.onload = function () { shown.replaceWith(frame); shown = frame; screen.hidden = false; reading = false; };
frame.onerror = function () { screen.hidden = true; reading = false; };
frame.src = screen.dataset.screenUrl + "?t=" + Date.now();
};
read_screen();
setInterval(read_screen, 10000);
}
// the guest OS details, read through the guest agent
function load_osinfo() {
var error = $('#osinfo-error');