From dab806eaecf2be1d4ba4efbfa161f8a02de73307 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Tue, 24 May 2022 15:07:31 +0300 Subject: [PATCH] pikvm/pikvm#725: sysrq confirmation --- web/kvm/index.html | 32 ++++++++++++++++++++++---------- web/kvm/navbar-shortcuts.pug | 6 ++++-- web/share/js/kvm/hid.js | 21 ++++++++++++++++++++- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/web/kvm/index.html b/web/kvm/index.html index 579b0f94..596deec3 100644 --- a/web/kvm/index.html +++ b/web/kvm/index.html @@ -653,21 +653,33 @@
- - - - + + + +

- - - - - - + + + + + +
+
+ + + + + +
Ask the magic confirmation: +
+ + +
+
  • GPIO diff --git a/web/kvm/navbar-shortcuts.pug b/web/kvm/navbar-shortcuts.pug index 0b56d611..b3463d63 100644 --- a/web/kvm/navbar-shortcuts.pug +++ b/web/kvm/navbar-shortcuts.pug @@ -42,7 +42,7 @@ li(class="right") "T": "Dump a list of current tasks and their information to the console", } each title, key in sysrq - button(data-shortcut=`AltLeft PrintScreen Key${key}` class="row25" title=`${title}`) #{key} + button(data-shortcut=`AltLeft PrintScreen Key${key}` data-shortcut-confirm="hid-sysrq-ask-switch" class="row25" style="text-align: center;" title=`${title}`) #{key} hr div(class="buttons-row") - @@ -55,4 +55,6 @@ li(class="right") "B": "Immediately reboot the system without syncing or unmounting disks", } each title, key in sysrq - button(data-shortcut=`AltLeft PrintScreen Key${key}` class="row16" title=`${title}`) #{key} + button(data-shortcut=`AltLeft PrintScreen Key${key}` data-shortcut-confirm="hid-sysrq-ask-switch" class="row16" style="text-align: center;" title=`${title}`) #{key} + hr + +menu_switch("hid-sysrq-ask-switch", "Ask the magic confirmation", true, true) diff --git a/web/share/js/kvm/hid.js b/web/share/js/kvm/hid.js index 1d7a4ff3..91300fd9 100644 --- a/web/share/js/kvm/hid.js +++ b/web/share/js/kvm/hid.js @@ -90,8 +90,27 @@ export function Hid(__getGeometry, __recorder) { tools.el.setOnClick($("hid-reset-button"), __clickResetButton); for (let el_shortcut of $$$("[data-shortcut]")) { - tools.el.setOnClick(el_shortcut, () => __emitShortcut(el_shortcut.getAttribute("data-shortcut").split(" "))); + tools.el.setOnClick(el_shortcut, function() { + let ask = false; + let confirm_id = el_shortcut.getAttribute("data-shortcut-confirm"); + if (confirm_id) { + ask = $(confirm_id).checked; + } + let codes = el_shortcut.getAttribute("data-shortcut").split(" "); + if (ask) { + let confirm_msg = `Do you want to press ${codes.join(" + ")}?`; + wm.confirm(confirm_msg).then(function(ok) { + if (ok) { + __emitShortcut(codes); + } + }); + } else { + __emitShortcut(codes); + } + }); } + + tools.storage.bindSimpleSwitch($("hid-sysrq-ask-switch"), "hid.sysrq.ask", true); }; /************************************************************************/