5
0
mirror of git://git.proxmox.com/git/novnc-pve.git synced 2024-12-21 13:34:08 +03:00

don't automatically connect to not running vms/cts

this patch adds a check for the guests status, and show a start button
instead of connecting to a non-started guest

this should reduce confusion when a guest is not running, and also
reduce the number of false-positive failed console tasks

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
 [ T: re-use existing power symbol, change VM/CT to Guest ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Dominik Csapak 2022-02-10 10:33:12 +01:00 committed by Thomas Lamprecht
parent 7f0a51607e
commit 5fe42a7f91
2 changed files with 166 additions and 0 deletions

View File

@ -0,0 +1,165 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dominik Csapak <d.csapak@proxmox.com>
Date: Wed, 9 Feb 2022 14:50:35 +0100
Subject: [PATCH] show start button on not running vm/ct
by querying the 'status' api first and showing a simple startbutton
if the status is not 'running'
adds a play icon from fontawesome, since novnc had none itself
css style is mostly copied from novnc "connect dialog", only the
colors were adapted
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
app/pve.js | 34 ++++++++++++++++++++++++--
app/styles/pve.css | 58 +++++++++++++++++++++++++++++++++++++++++++++
vnc.html | 9 +++++++
3 files changed, 99 insertions(+), 2 deletions(-)
diff --git a/app/pve.js b/app/pve.js
index 042eb7c..9da23ed 100644
--- a/app/pve.js
+++ b/app/pve.js
@@ -311,6 +311,11 @@ PVEUI.prototype = {
.classList.add('pve_hidden');
}
+ document.getElementById("pve_start_button")
+ .addEventListener('click', function() {
+ me.pve_vm_command('start');
+ });
+
// add command logic
var commandArray = [
{ cmd: 'start', kvm: 1, lxc: 1},
@@ -359,8 +364,8 @@ PVEUI.prototype = {
return { width: ow, height: oh };
},
- pveStart: function(callback) {
- var me = this;
+ initConnection: function(callback) {
+ let me = this;
me.API2Request({
url: me.url,
method: 'POST',
@@ -382,6 +387,31 @@ PVEUI.prototype = {
});
},
+ pveStart: function(callback) {
+ var me = this;
+ if (me.consoletype === 'kvm' || me.consoletype === 'lxc') {
+ // check status for vms first
+ me.API2Request({
+ url: `${me.baseUrl}/status/current`,
+ method: 'GET',
+ success: function(result) {
+ let status = result.data.status;
+ if (status === 'running') {
+ me.initConnection(callback);
+ } else {
+ document.getElementById('pve_start_dlg')
+ .classList.add("noVNC_open");
+ }
+ },
+ failure: function(msg) {
+ me.UI.showStatus(msg, 'error');
+ }
+ });
+ } else {
+ me.initConnection(callback);
+ }
+ },
+
updateFBSize: function(rfb, width, height) {
var me = this;
try {
diff --git a/app/styles/pve.css b/app/styles/pve.css
index 18126b0..f2e7484 100644
--- a/app/styles/pve.css
+++ b/app/styles/pve.css
@@ -44,3 +44,61 @@
.noVNC_button.pve_hidden {
display: none;
}
+
+/* start button */
+#pve_start_dlg {
+ transition: 0.5s ease-in-out;
+ transform: scale(0, 0);
+ visibility: hidden;
+ opacity: 0;
+}
+
+#pve_start_dlg.noVNC_open {
+ transform: scale(1, 1);
+ visibility: visible;
+ opacity: 1;
+}
+
+#pve_start_info {
+ color: white;
+ text-align: center;
+ font-size: 20px;
+ padding: 6px;
+}
+
+#pve_start_button {
+ cursor: pointer;
+ padding: 6px;
+ color: white;
+ background:#4c4c4c;;
+ border-radius: 8px;
+ text-align: center;
+ font-size: 20px;
+ box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.5);
+}
+
+#pve_start_button div {
+ margin: 2px;
+ padding: 5px 30px;
+ border: 1px solid #2f2f2f;
+ border-bottom-width: 2px;
+ border-radius: 5px;
+ background:#4c4c4c;;
+
+ /* This avoids it jumping around when :active */
+ vertical-align: middle;
+}
+
+#pve_start_button div:active {
+ border-bottom-width: 1px;
+ margin-top: 3px;
+}
+
+:root:not(.noVNC_touch) #pve_start_button div:hover {
+ background: rgba(255, 255, 255, 0.2);
+}
+
+#pve_start_button img {
+ vertical-align: bottom;
+ padding: 0 5px 2px 0;
+}
diff --git a/vnc.html b/vnc.html
index d94fd99..72efa89 100644
--- a/vnc.html
+++ b/vnc.html
@@ -283,6 +283,15 @@
</div>
</div>
+ <div class="noVNC_center">
+ <div id="pve_start_dlg">
+ <div id="pve_start_info">Guest not running</div>
+ <div id="pve_start_button"><div>
+ <img alt="" src="/novnc/app/images/power.svg"> Start Now
+ </div></div>
+ </div>
+ </div>
+
<!-- Password Dialog -->
<div class="noVNC_center noVNC_connect_layer">
<div id="noVNC_credentials_dlg" class="noVNC_panel"><form>

View File

@ -15,3 +15,4 @@
0015-create-own-class-for-hidden-buttons.patch
0016-hide-fullscreen-button-on-isFullscreen-get-variable.patch
0017-make-error-hideable.patch
0018-show-start-button-on-not-running-vm-ct.patch