systray: Cleanups and improvements for --show-systray

- Add UI coverage
- Drop redundant systray_instance caching
- Tweaks help test and docs
- Show an error if the systray doesn't embed

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2024-03-03 11:54:37 -05:00
parent 2043847ade
commit a6b62a20b6
5 changed files with 53 additions and 12 deletions

View File

@ -88,6 +88,7 @@ URI.
``--show-host-summary``
Display the host/connection details window.
SYSTEM TRAY OPTION
==================
@ -95,7 +96,8 @@ Connection autostart will not be disabled and thus don't require specifying a
manual ``--connect`` URI. But it supports ``--connect`` URI as well:
``--show-systray``
Launch virt-manager in system tray
Launch virt-manager only in system tray
BUGS
====

View File

@ -80,6 +80,19 @@ def testShowDelete(app):
app.wait_for_exit()
def testShowSystray(app):
opts = ["--test-options=fake-systray", "--show-systray"]
app.open(use_uri=False,
extra_opts=opts,
window_name="vmm-fake-systray")
app.sleep(1)
app.stop()
app.open(uri="test:///default",
extra_opts=opts,
window_name="vmm-fake-systray")
def testShowRemoteDBusConnect(app):
"""
Test the remote app dbus connection

View File

@ -64,8 +64,6 @@ class vmmEngine(vmmGObject):
self._exiting = False
self.systray_instance = None
self._window_count = 0
self._gtkapplication = None
self._init_gtk_application()
@ -98,7 +96,7 @@ class vmmEngine(vmmGObject):
"""
Actual startup routines if we are running a new instance of the app
"""
self.systray_instance = vmmSystray.get_instance()
vmmSystray.get_instance()
vmmInspection.get_instance()
self.add_gsettings_handle(
@ -335,6 +333,30 @@ class vmmEngine(vmmGObject):
"""
return vmmSystray.get_instance().is_embedded()
def _show_systray_from_cli(self):
"""
Handler for --show-systray from CLI.
We force show the systray, and wait for a timeout to report if
its embedded. If not we raise an error and exit the app
"""
vmmSystray.get_instance().show_from_cli()
@_show_startup_error
def check(self, count):
count -= 1
if self._systray_is_embedded():
log.debug("systray embedded")
return
if count <= 0: # pragma: no cover
raise RuntimeError("systray did not show up")
self.timeout_add(1000, check, self, count) # pragma: no cover
startcount = 5
timeout = 1000
if self.config.CLITestOptions.fake_systray:
timeout = 1
self.timeout_add(timeout, check, self, startcount)
def _can_exit(self):
return (self._window_count <= 0 and not
self._systray_is_embedded())
@ -445,8 +467,8 @@ class vmmEngine(vmmGObject):
self.CLI_SHOW_DOMAIN_DELETE]):
self._cli_show_vm_helper(uri, clistr, show_window)
elif show_window == self.CLI_SHOW_SYSTEM_TRAY:
log.debug("Showing in the system tray")
self.systray_instance._show_systray()
# Handled elsewhere
pass
else: # pragma: no cover
raise RuntimeError("Unknown cli window command '%s'" %
show_window)
@ -466,12 +488,13 @@ class vmmEngine(vmmGObject):
log.debug("processing cli command uri=%s show_window=%s domain=%s",
uri, show_window, domain)
if not uri:
if show_window == self.CLI_SHOW_SYSTEM_TRAY:
log.debug("Launching in the system tray without --connect")
self.systray_instance._show_systray()
return
if show_window == self.CLI_SHOW_SYSTEM_TRAY:
log.debug("Launching only in the system tray")
self._show_systray_from_cli()
if not uri:
return
elif not uri:
log.debug("No cli action requested, launching default window")
self._get_manager().show()
return

View File

@ -434,6 +434,9 @@ class vmmSystray(vmmGObject):
def is_embedded(self):
return self._systray and self._systray.is_embedded()
def show_from_cli(self):
self._show_systray()
def _cleanup(self):
self._hide_systray()
self._systray = None

View File

@ -156,7 +156,7 @@ def parse_commandline():
parser.add_argument("--show-host-summary", action="store_true",
help="Show connection details window")
parser.add_argument("--show-systray", action="store_true",
help="Launch virt-manager in system tray")
help="Launch virt-manager only in system tray")
return parser.parse_known_args()