Skip to content

Commit

Permalink
Added VM restart to qui-domains
Browse files Browse the repository at this point in the history
A bit hacky, because Gtk really didn't want a big blocking function in
its loop, but it works.

fixes QubesOS/qubes-issues#6249
  • Loading branch information
marmarta committed Jan 20, 2021
1 parent 9ce263e commit 955eeb9
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion qui/tray/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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. '''

Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit 955eeb9

Please sign in to comment.