From 636b0158f90cbbbaf3b318c0b429fb4e82235f2c Mon Sep 17 00:00:00 2001 From: miro Date: Tue, 3 Dec 2024 21:54:23 +0000 Subject: [PATCH] feat: status events split feedback events to allow GUI integration via systemdhooks --- ovos_PHAL_plugin_system/__init__.py | 58 ++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/ovos_PHAL_plugin_system/__init__.py b/ovos_PHAL_plugin_system/__init__.py index cfdb2a5..2232740 100644 --- a/ovos_PHAL_plugin_system/__init__.py +++ b/ovos_PHAL_plugin_system/__init__.py @@ -48,14 +48,17 @@ def __init__(self, bus=None, config=None): self.bus.on("system.ssh.status", self.handle_ssh_status) self.bus.on("system.ssh.enable", self.handle_ssh_enable_request) self.bus.on("system.ssh.disable", self.handle_ssh_disable_request) + self.bus.on("system.ssh.enabled", self.handle_ssh_enabled) + self.bus.on("system.ssh.disabled", self.handle_ssh_disabled) self.bus.on("system.reboot", self.handle_reboot_request) + self.bus.on("system.reboot.start", self.handle_rebooting) self.bus.on("system.shutdown", self.handle_shutdown_request) + self.bus.on("system.shutdown.start", self.handle_shutting_down) self.bus.on("system.factory.reset", self.handle_factory_reset_request) self.bus.on("system.factory.reset.register", self.handle_reset_register) - self.bus.on("system.configure.language", - self.handle_configure_language_request) - self.bus.on("system.mycroft.service.restart", - self.handle_mycroft_restart_request) + self.bus.on("system.configure.language", self.handle_configure_language_request) + self.bus.on("system.mycroft.service.restart", self.handle_mycroft_restart_request) + self.bus.on("system.mycroft.service.restart.start", self.handle_mycroft_restarting) self.core_service_name = config.get("core_service") or "ovos.service" # In Debian, ssh stays active, but sshd is removed when ssh is disabled @@ -194,6 +197,9 @@ def on_done(message): def handle_ssh_enable_request(self, message): subprocess.call(f"systemctl enable {self.ssh_service}", shell=True) subprocess.call(f"systemctl start {self.ssh_service}", shell=True) + self.bus.emit(message.forward("system.ssh.enabled", message.data)) + + def handle_ssh_enabled(self, message): # ovos-shell does not want to display if message.data.get("display", True): self.gui["status"] = "Enabled" @@ -203,20 +209,28 @@ def handle_ssh_enable_request(self, message): def handle_ssh_disable_request(self, message): subprocess.call(f"systemctl stop {self.ssh_service}", shell=True) subprocess.call(f"systemctl disable {self.ssh_service}", shell=True) + self.bus.emit(message.forward("system.ssh.disabled", message.data)) + + def handle_ssh_disabled(self, message): # ovos-shell does not want to display if message.data.get("display", True): self.gui["status"] = "Disabled" self.gui["label"] = "SSH Disabled" self.gui.show_page("Status") - def handle_reboot_request(self, message): + def handle_rebooting(self, message): """ - Shut down and restart the system + reboot has started """ if message.data.get("display", True): self.gui.show_page("Reboot", override_animations=True, override_idle=True) + def handle_reboot_request(self, message: Message): + """ + Shut down and restart the system + """ + self.bus.emit(message.forward("system.reboot.start", message.data)) script = os.path.expanduser(self.config.get("reboot_script") or "") LOG.info(f"Reboot requested. script={script}") if script and os.path.isfile(script): @@ -224,13 +238,19 @@ def handle_reboot_request(self, message): else: subprocess.call("systemctl reboot -i", shell=True) - def handle_shutdown_request(self, message): + def handle_shutting_down(self, message): """ - Turn the system completely off (with no option to inhibit it) + shutdown has started """ if message.data.get("display", True): self.gui.show_page("Shutdown", override_animations=True, override_idle=True) + + def handle_shutdown_request(self, message): + """ + Turn the system completely off (with no option to inhibit it) + """ + self.bus.emit(message.forward("system.shutdown.start", message.data)) script = os.path.expanduser(self.config.get("shutdown_script") or "") LOG.info(f"Shutdown requested. script={script}") if script and os.path.isfile(script): @@ -259,11 +279,14 @@ def handle_configure_language_request(self, message): self.bus.emit(Message('system.configure.language.complete', {"lang": language_code})) - def handle_mycroft_restart_request(self, message): + def handle_mycroft_restarting(self, message): if message.data.get("display", True): self.gui.show_page("Restart", override_animations=True, override_idle=True) + + def handle_mycroft_restart_request(self, message): service = self.core_service_name + self.bus.emit(message.forward("system.mycroft.service.restart.start", message.data)) # TODO - clean up this mess try: restart_service(service, sudo=False, user=True) @@ -284,16 +307,17 @@ def handle_ssh_status(self, message): def shutdown(self): self.bus.remove("system.ssh.enable", self.handle_ssh_enable_request) self.bus.remove("system.ssh.disable", self.handle_ssh_disable_request) + self.bus.remove("system.ssh.enabled", self.handle_ssh_enabled) + self.bus.remove("system.ssh.disabled", self.handle_ssh_disabled) self.bus.remove("system.reboot", self.handle_reboot_request) + self.bus.remove("system.reboot.start", self.handle_rebooting) self.bus.remove("system.shutdown", self.handle_shutdown_request) - self.bus.remove("system.factory.reset", - self.handle_factory_reset_request) - self.bus.remove("system.factory.reset.register", - self.handle_reset_register) - self.bus.remove("system.configure.language", - self.handle_configure_language_request) - self.bus.remove("system.mycroft.service.restart", - self.handle_mycroft_restart_request) + self.bus.remove("system.shutdown.start", self.handle_shutting_down) + self.bus.remove("system.factory.reset", self.handle_factory_reset_request) + self.bus.remove("system.factory.reset.register", self.handle_reset_register) + self.bus.remove("system.configure.language", self.handle_configure_language_request) + self.bus.remove("system.mycroft.service.restart", self.handle_mycroft_restart_request) + self.bus.remove("system.mycroft.service.restarting", self.handle_mycroft_restarting) super().shutdown()