diff options
author | Devaev Maxim <[email protected]> | 2021-04-17 15:41:05 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2021-04-17 15:41:05 +0300 |
commit | be012fd38d6f6f2d269dcbffd3aafe59a2a9a40c (patch) | |
tree | 0742bf1e2934f8d882e9e7b3c81360d7204285ee | |
parent | 3a2ffcfd5c0591160333d1b347880f09eb2ee056 (diff) |
terminal window
-rw-r--r-- | kvmd/apps/kvmd/info/extras.py | 17 | ||||
-rw-r--r-- | testenv/linters/htmlhint.json | 3 | ||||
-rw-r--r-- | testenv/tox.ini | 2 | ||||
-rw-r--r-- | web/kvm/index.html | 14 | ||||
-rw-r--r-- | web/kvm/navbar-system.pug | 3 | ||||
-rw-r--r-- | web/kvm/window-webterm.pug | 8 | ||||
-rw-r--r-- | web/kvm/windows.pug | 1 | ||||
-rw-r--r-- | web/share/js/index/main.js | 2 | ||||
-rw-r--r-- | web/share/js/kvm/session.js | 21 | ||||
-rw-r--r-- | web/share/js/wm.js | 3 |
10 files changed, 63 insertions, 11 deletions
diff --git a/kvmd/apps/kvmd/info/extras.py b/kvmd/apps/kvmd/info/extras.py index 6024aebc..10d57f27 100644 --- a/kvmd/apps/kvmd/info/extras.py +++ b/kvmd/apps/kvmd/info/extras.py @@ -23,6 +23,7 @@ import os import contextlib +from typing import Tuple from typing import Dict from typing import Optional @@ -67,7 +68,7 @@ class ExtrasInfoSubmanager(BaseInfoSubmanager): def __rewrite_app_daemon(self, extras: Dict) -> None: daemon = extras.get("daemon", "") if isinstance(daemon, str) and daemon.strip(): - extras["enabled"] = self.__is_daemon_enabled(daemon) + (extras["enabled"], extras["started"]) = self.__get_daemon_status(daemon) def __rewrite_app_port(self, extras: Dict) -> None: port_path = extras.get("port", "") @@ -79,25 +80,23 @@ class ExtrasInfoSubmanager(BaseInfoSubmanager): if isinstance(config, int): extras["port"] = config - def __is_daemon_enabled(self, name: str) -> bool: + def __get_daemon_status(self, name: str) -> Tuple[bool, bool]: if not name.endswith(".service"): name += ".service" - try: with contextlib.closing(dbus.SystemBus()) as bus: systemd = bus.get_object("org.freedesktop.systemd1", "/org/freedesktop/systemd1") # pylint: disable=no-member manager = dbus.Interface(systemd, dbus_interface="org.freedesktop.systemd1.Manager") - try: unit_proxy = bus.get_object("org.freedesktop.systemd1", manager.GetUnit(name)) # pylint: disable=no-member unit_properties = dbus.Interface(unit_proxy, dbus_interface="org.freedesktop.DBus.Properties") - enabled = (unit_properties.Get("org.freedesktop.systemd1.Unit", "ActiveState") == "active") + started = (unit_properties.Get("org.freedesktop.systemd1.Unit", "ActiveState") == "active") except dbus.exceptions.DBusException as err: if "NoSuchUnit" not in str(err): raise - enabled = False - - return (enabled or (manager.GetUnitFileState(name) in ["enabled", "enabled-runtime", "static", "indirect", "generated"])) + started = False + enabled = (manager.GetUnitFileState(name) in ["enabled", "enabled-runtime", "static", "indirect", "generated"]) + return (enabled, started) except Exception as err: get_logger(0).error("Can't get info about the service %r: %s", name, tools.efmt(err)) - return True + return (True, True) diff --git a/testenv/linters/htmlhint.json b/testenv/linters/htmlhint.json new file mode 100644 index 00000000..0c5c6c11 --- /dev/null +++ b/testenv/linters/htmlhint.json @@ -0,0 +1,3 @@ +{ + "src-not-empty": false +} diff --git a/testenv/tox.ini b/testenv/tox.ini index ba50e422..e3d2a810 100644 --- a/testenv/tox.ini +++ b/testenv/tox.ini @@ -58,4 +58,4 @@ commands = eslint --cache-location=/tmp --config=testenv/linters/eslintrc.yaml - [testenv:htmlhint] whitelist_externals = htmlhint -commands = htmlhint web/*.html web/*/*.html +commands = htmlhint --config=testenv/linters/htmlhint.json web/*.html web/*/*.html diff --git a/web/kvm/index.html b/web/kvm/index.html index aa0e5fce..dc5779a5 100644 --- a/web/kvm/index.html +++ b/web/kvm/index.html @@ -205,6 +205,10 @@ <hr> <button disabled id="wol-wakeup-button">• Wake-on-LAN server</button> </div> + <div class="buttons feature-disabled" id="webterm"> + <hr> + <button data-force-hide-menu id="show-webterm-button">• Show terminal</button> + </div> </div> </li> <li class="right feature-disabled" id="atx-dropdown"><a class="menu-button" href="#"><img class="led-gray" data-dont-hide-menu id="atx-power-led" src="/share/svg/led-atx-power.svg"><img class="led-gray" data-dont-hide-menu id="atx-hdd-led" src="/share/svg/led-atx-hdd.svg">ATX</a> @@ -1744,6 +1748,16 @@ </p> </div> </div> + <div class="window window-resizable" id="webterm-window" data-show-by-button="show-webterm-button" style="width: 640px; height: 480px"> + <div class="window-header"> + <div class="window-grab">Terminal</div> + <button class="window-button-close">×</button> + <button class="window-button-maximize">☐</button> + <!-- Терминал глючит из-за зажимаемой клавиши ESC для выхода--> + <!-- button(class="window-button-full-screen") ⤢--> + </div> + <iframe id="webterm-iframe" src="" style="width: 100%; height: 100%"></iframe> + </div> <ul class="footer"> <li class="footer-left" id="kvmd-meta-server-host"></li> <li class="footer-right"><a target="_blank" href="https://pikvm.org">Pi-KVM Project</a></li> diff --git a/web/kvm/navbar-system.pug b/web/kvm/navbar-system.pug index 2f85416c..186bdef7 100644 --- a/web/kvm/navbar-system.pug +++ b/web/kvm/navbar-system.pug @@ -66,3 +66,6 @@ li(class="right") div(id="wol" class="buttons feature-disabled") hr button(disabled id="wol-wakeup-button") • Wake-on-LAN server + div(id="webterm" class="buttons feature-disabled") + hr + button(data-force-hide-menu id="show-webterm-button") • Show terminal diff --git a/web/kvm/window-webterm.pug b/web/kvm/window-webterm.pug new file mode 100644 index 00000000..e6c1d196 --- /dev/null +++ b/web/kvm/window-webterm.pug @@ -0,0 +1,8 @@ +div(id="webterm-window" class="window window-resizable" data-show-by-button="show-webterm-button" style="width: 640px; height: 480px") + div(class="window-header") + div(class="window-grab") Terminal + button(class="window-button-close") × + button(class="window-button-maximize") ☐ + // Терминал глючит из-за зажимаемой клавиши ESC для выхода + // button(class="window-button-full-screen") ⤢ + iframe(id="webterm-iframe" src="" style="width: 100%; height: 100%") diff --git a/web/kvm/windows.pug b/web/kvm/windows.pug index 898a8562..b2d32dad 100644 --- a/web/kvm/windows.pug +++ b/web/kvm/windows.pug @@ -1,3 +1,4 @@ include window-stream.pug include window-keyboard.pug include window-about.pug +include window-webterm.pug diff --git a/web/share/js/index/main.js b/web/share/js/index/main.js index ee829480..5f715007 100644 --- a/web/share/js/index/main.js +++ b/web/share/js/index/main.js @@ -80,7 +80,7 @@ function __loadKvmdInfo() { } for (let app of apps) { - if (app.enabled) { + if (app.enabled || app.started) { $("apps").innerHTML += __makeApp(null, app.path, app.icon, app.name); } } diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js index b278dd06..3dd59d12 100644 --- a/web/share/js/kvm/session.js +++ b/web/share/js/kvm/session.js @@ -107,6 +107,26 @@ export function Session() { } }; + var __setExtras = function(state) { + let show_hook = null; + let close_hook = null; + let has_webterm = (state.webterm && state.webterm.started); + if (has_webterm) { + let path = "/" + state.webterm.path; + show_hook = function() { + tools.info("Terminal opened: ", path); + $("webterm-iframe").src = path; + }; + close_hook = function() { + tools.info("Terminal closed"); + $("webterm-iframe").src = ""; + }; + } + tools.featureSetEnabled($("webterm"), has_webterm); + $("webterm-window").show_hook = show_hook; + $("webterm-window").close_hook = close_hook; + }; + var __formatTemp = function(temp) { let pairs = []; for (let field of Object.keys(temp).sort()) { @@ -218,6 +238,7 @@ export function Session() { case "info_meta_state": __setAboutInfoMeta(data.event); break; case "info_hw_state": __setAboutInfoHw(data.event); break; case "info_system_state": __setAboutInfoSystem(data.event); break; + case "info_extras_state": __setExtras(data.event); break; case "wol_state": __wol.setState(data.event); break; case "gpio_model_state": __gpio.setModel(data.event); break; case "gpio_state": __gpio.setState(data.event); break; diff --git a/web/share/js/wm.js b/web/share/js/wm.js index 7e4105da..44238447 100644 --- a/web/share/js/wm.js +++ b/web/share/js/wm.js @@ -263,6 +263,9 @@ function __WindowManager() { el_window.focus(); el_window.blur(); el_window.style.visibility = "hidden"; + if (el_window.close_hook) { + el_window.close_hook(); + } }; var __toggleMenu = function(el_a) { |