From 955eeb93dbd03a71bbe757ed150bbf800a4c6d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Wed, 20 Jan 2021 15:31:21 +0100 Subject: [PATCH] Added VM restart to qui-domains A bit hacky, because Gtk really didn't want a big blocking function in its loop, but it works. fixes QubesOS/qubes-issues#6249 --- qui/tray/domains.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/qui/tray/domains.py b/qui/tray/domains.py index a1b3b04a..4abe7743 100644 --- a/qui/tray/domains.py +++ b/qui/tray/domains.py @@ -48,7 +48,8 @@ def __init__(self): 'kill': 'media-record', 'shutdown': 'media-playback-stop', 'unpause': 'media-playback-start', - 'files': 'system-file-manager' + 'files': 'system-file-manager', + 'restart': 'edit-redo' } self.icons = {} @@ -144,6 +145,39 @@ def perform_shutdown(self, *_args, **_kwargs): self.vm.name, str(ex))) +class RestartItem(Gtk.ImageMenuItem): + ''' Restart menu Item. When activated shutdowns the domain and + then starts it again. ''' + + def __init__(self, vm, app, icon_cache): + super().__init__() + self.vm = vm + self.app = app + + img = Gtk.Image.new_from_pixbuf(icon_cache.get_icon('restart')) + + self.set_image(img) + self.set_label(_('Restart')) + self.restart_thread = None + + self.connect('activate', self.restart) + + def restart(self, *_args, **_kwargs): + asyncio.ensure_future(self.perform_restart()) + + async def perform_restart(self): + try: + self.vm.shutdown() + while self.vm.is_running(): + await asyncio.sleep(1) + subprocess.Popen(['qvm-start', self.vm.name]) + except exc.QubesException as ex: + show_error(_("Error restarting qube"), + _("The following error occurred on an attempt to " + "restart qube {0}:\n{1}").format( + self.vm.name, str(ex))) + + class KillItem(Gtk.ImageMenuItem): ''' Kill domain menu Item. When activated kills the domain. ''' @@ -261,6 +295,7 @@ def __init__(self, vm, app, icon_cache): self.add(PreferencesItem(self.vm, icon_cache)) self.add(PauseItem(self.vm, icon_cache)) self.add(ShutdownItem(self.vm, self.app, icon_cache)) + self.add(RestartItem(self.vm, self.app, icon_cache)) self.add(RunTerminalItem(self.vm, icon_cache)) self.add(OpenFileManagerItem(self.vm, icon_cache))