]> git.proxmox.com Git - novnc-pve.git/blob - debian/patches/0018-show-start-button-on-not-running-vm-ct.patch
don't require confirmation for starting a stopped vm from button
[novnc-pve.git] / debian / patches / 0018-show-start-button-on-not-running-vm-ct.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Dominik Csapak <d.csapak@proxmox.com>
3 Date: Wed, 9 Feb 2022 14:50:35 +0100
4 Subject: [PATCH] show start button on not running vm/ct
5
6 by querying the 'status' api first and showing a simple startbutton
7 if the status is not 'running'
8
9 adds a play icon from fontawesome, since novnc had none itself
10
11 css style is mostly copied from novnc "connect dialog", only the
12 colors were adapted
13
14 Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
15 ---
16 app/pve.js | 38 ++++++++++++++++++++++++++----
17 app/styles/pve.css | 58 ++++++++++++++++++++++++++++++++++++++++++++++
18 vnc.html | 9 +++++++
19 3 files changed, 101 insertions(+), 4 deletions(-)
20
21 diff --git a/app/pve.js b/app/pve.js
22 index 583a406..3eeaa47 100644
23 --- a/app/pve.js
24 +++ b/app/pve.js
25 @@ -231,7 +231,7 @@ PVEUI.prototype = {
26
27 },
28
29 - pve_vm_command: function(cmd, params, reload) {
30 + pve_vm_command: function(cmd, params, reload, mustConfirm = true) {
31 var me = this;
32 var baseUrl;
33 var confirmMsg = "";
34 @@ -255,7 +255,7 @@ PVEUI.prototype = {
35
36 confirmMsg = confirmMsg.replace('{0}', me.vmid);
37
38 - if (confirmMsg !== "" && confirm(confirmMsg) !== true) {
39 + if (confirmMsg !== "" && mustConfirm && confirm(confirmMsg) !== true) {
40 return;
41 }
42
43 @@ -320,6 +320,11 @@ PVEUI.prototype = {
44 .classList.add('pve_hidden');
45 }
46
47 + document.getElementById("pve_start_button")
48 + .addEventListener('click', function() {
49 + me.pve_vm_command('start', {}, undefined, false);
50 + });
51 +
52 // add command logic
53 var commandArray = [
54 { cmd: 'start', kvm: 1, lxc: 1},
55 @@ -368,8 +373,8 @@ PVEUI.prototype = {
56 return { width: ow, height: oh };
57 },
58
59 - pveStart: function(callback) {
60 - var me = this;
61 + initConnection: function(callback) {
62 + let me = this;
63 me.API2Request({
64 url: me.url,
65 method: 'POST',
66 @@ -391,6 +396,31 @@ PVEUI.prototype = {
67 });
68 },
69
70 + pveStart: function(callback) {
71 + var me = this;
72 + if (me.consoletype === 'kvm' || me.consoletype === 'lxc') {
73 + // check status for vms first
74 + me.API2Request({
75 + url: `${me.baseUrl}/status/current`,
76 + method: 'GET',
77 + success: function(result) {
78 + let status = result.data.status;
79 + if (status === 'running') {
80 + me.initConnection(callback);
81 + } else {
82 + document.getElementById('pve_start_dlg')
83 + .classList.add("noVNC_open");
84 + }
85 + },
86 + failure: function(msg) {
87 + me.UI.showStatus(msg, 'error');
88 + }
89 + });
90 + } else {
91 + me.initConnection(callback);
92 + }
93 + },
94 +
95 updateFBSize: function(rfb, width, height) {
96 var me = this;
97 try {
98 diff --git a/app/styles/pve.css b/app/styles/pve.css
99 index 18126b0..e0ca61f 100644
100 --- a/app/styles/pve.css
101 +++ b/app/styles/pve.css
102 @@ -44,3 +44,61 @@
103 .noVNC_button.pve_hidden {
104 display: none;
105 }
106 +
107 +/* start button */
108 +#pve_start_dlg {
109 + transition: 0.2s ease-in-out;
110 + transform: scale(0, 0);
111 + visibility: hidden;
112 + opacity: 0;
113 +}
114 +
115 +#pve_start_dlg.noVNC_open {
116 + transform: scale(1, 1);
117 + visibility: visible;
118 + opacity: 1;
119 +}
120 +
121 +#pve_start_info {
122 + color: white;
123 + text-align: center;
124 + font-size: 20px;
125 + padding: 6px;
126 +}
127 +
128 +#pve_start_button {
129 + cursor: pointer;
130 + padding: 6px;
131 + color: white;
132 + background:#4c4c4c;;
133 + border-radius: 8px;
134 + text-align: center;
135 + font-size: 20px;
136 + box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.5);
137 +}
138 +
139 +#pve_start_button div {
140 + margin: 2px;
141 + padding: 5px 30px;
142 + border: 1px solid #2f2f2f;
143 + border-bottom-width: 2px;
144 + border-radius: 5px;
145 + background:#4c4c4c;;
146 +
147 + /* This avoids it jumping around when :active */
148 + vertical-align: middle;
149 +}
150 +
151 +#pve_start_button div:active {
152 + border-bottom-width: 1px;
153 + margin-top: 3px;
154 +}
155 +
156 +:root:not(.noVNC_touch) #pve_start_button div:hover {
157 + background: rgba(255, 255, 255, 0.2);
158 +}
159 +
160 +#pve_start_button img {
161 + vertical-align: bottom;
162 + padding: 0 5px 2px 0;
163 +}
164 diff --git a/vnc.html b/vnc.html
165 index 3e63087..f0488b1 100644
166 --- a/vnc.html
167 +++ b/vnc.html
168 @@ -281,6 +281,15 @@
169 </div>
170 </div>
171
172 + <div class="noVNC_center">
173 + <div id="pve_start_dlg">
174 + <div id="pve_start_info">Guest not running</div>
175 + <div id="pve_start_button"><div>
176 + <img alt="" src="/novnc/app/images/power.svg"> Start Now
177 + </div></div>
178 + </div>
179 + </div>
180 +
181 <!-- Password Dialog -->
182 <div class="noVNC_center noVNC_connect_layer">
183 <div id="noVNC_credentials_dlg" class="noVNC_panel"><form>