diff --git a/qui/devices/device_widget.py b/qui/devices/device_widget.py index d5f8fe7e..d17f0cc1 100644 --- a/qui/devices/device_widget.py +++ b/qui/devices/device_widget.py @@ -64,10 +64,6 @@ _ = t.gettext -# FUTURE: this should be moved to backend with new API changes -DEV_TYPES = ["block", "usb", "mic", "webcam"] - - class DeviceMenu(Gtk.Menu): """Menu for handling a single device""" @@ -117,6 +113,7 @@ def __init__(self, app_name, qapp, dispatcher): self.dormant_usbvms: Set[backend.VM] = set() self.dev_update_queue: Set = set() self.vm_update_queue: Set = set() + self.dev_types: List[str] = [] self.dispatcher: qubesadmin.events.EventsDispatcher = dispatcher self.qapp: qubesadmin.Qubes = qapp @@ -128,7 +125,7 @@ def __init__(self, app_name, qapp, dispatcher): self.initialize_dev_data() self.initialize_features() - for devclass in DEV_TYPES: + for devclass in self.dev_types: self.dispatcher.add_handler( "device-attach:" + devclass, self.device_attached ) @@ -339,9 +336,14 @@ def device_removed(self, vm, _event, port): del self.devices[dev_id] def initialize_dev_data(self): + self.dev_types = self.qapp.list_deviceclass() + # Exclude PCI devices, as those can't be dynamically attached + if "pci" in self.dev_types: + self.dev_types.remove("pci") + # list all devices for domain in self.qapp.domains: - for devclass in DEV_TYPES: + for devclass in self.dev_types: try: for device in domain.devices[devclass]: dev_id = backend.Device.id_from_device(device) @@ -359,7 +361,7 @@ def initialize_dev_data(self): # list existing device attachments and assignments for domain in self.qapp.domains: - for devclass in DEV_TYPES: + for devclass in self.dev_types: try: for device in domain.devices[devclass].get_attached_devices(): dev = backend.Device.id_from_device(device) @@ -600,7 +602,7 @@ def hide_child_devices( def device_attached(self, vm, _event, device, **_kwargs): try: - if not vm.is_running() or device.devclass not in DEV_TYPES: + if not vm.is_running() or device.devclass not in self.dev_types: return except qubesadmin.exc.QubesPropertyAccessError: # we don't have access to VM state @@ -642,7 +644,7 @@ def vm_start(self, vm, _event, **_kwargs): self.dormant_usbvms.discard(wrapped_vm) self.active_usbvms.add(wrapped_vm) - for devclass in DEV_TYPES: + for devclass in self.dev_types: try: for device in vm.devices[devclass].get_attached_devices(): dev_id = backend.Device.id_from_device(device)