Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions qui/devices/device_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

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