From ea3e7ad3d1849d71ec095aa84ad8ecf6cc7e2251 Mon Sep 17 00:00:00 2001 From: alfrix Date: Sun, 15 May 2022 10:55:59 -0300 Subject: [PATCH] splash_screen: use moonraker for actions if connected, hide system panel if it isn't connected use systemctl if moonraker isn't available close #615 --- ks_includes/defaults.conf | 1 + panels/menu.py | 4 ++++ panels/splash_screen.py | 18 ++++++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ks_includes/defaults.conf b/ks_includes/defaults.conf index af596e31..a976535a 100644 --- a/ks_includes/defaults.conf +++ b/ks_includes/defaults.conf @@ -268,6 +268,7 @@ panel: network name: {{ gettext('System') }} icon: info panel: system +enable: {{ moonraker_connected }} [menu __splashscreen settings] name: {{ gettext('Settings') }} diff --git a/panels/menu.py b/panels/menu.py index bbd0a9ab..bb08f4b6 100644 --- a/panels/menu.py +++ b/panels/menu.py @@ -104,6 +104,10 @@ class MenuPanel(ScreenPanel): if enable is False: return False + if enable == "{{ moonraker_connected }}": + logging.info("moonraker is_connected %s", self._screen._ws.is_connected()) + return self._screen._ws.is_connected() + if not self.j2_data: self.j2_data = self._printer.get_printer_status_data() try: diff --git a/panels/splash_screen.py b/panels/splash_screen.py index b2369d45..9045b16f 100644 --- a/panels/splash_screen.py +++ b/panels/splash_screen.py @@ -131,7 +131,21 @@ class SplashScreenPanel(ScreenPanel): def shutdown(self, widget): - os.system("sudo shutdown -P now") + _ = self.lang.gettext + if self._screen._ws.is_connected(): + self._screen._confirm_send_action(widget, + _("Are you sure you wish to shutdown the system?"), + "machine.shutdown") + else: + logging.info("OS Shutdown") + os.system("systemctl poweroff") def restart_system(self, widget): - os.system("sudo reboot now") + _ = self.lang.gettext + if self._screen._ws.is_connected(): + self._screen._confirm_send_action(widget, + _("Are you sure you wish to reboot the system?"), + "machine.reboot") + else: + logging.info("OS Reboot") + os.system("systemctl reboot")