Skip to content

Commit

Permalink
q-dev: update common part with admin-core
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 21, 2024
1 parent dcd8580 commit 6013161
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
8 changes: 8 additions & 0 deletions qubesusbproxy/core3ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,14 @@ async def attach_and_notify(self, vm, assignment):
"device-attach:usb", device=device, options=assignment.options
)

def ensure_detach(self, vm, port):
"""
Run this method if device is no longer detected.
No additional action required in case of USB devices.
"""
pass

@qubes.ext.handler("domain-qdb-change:/qubes-usb-devices")
def on_qdb_change(self, vm, event, path):
"""A change in QubesDB means a change in a device list."""
Expand Down
21 changes: 12 additions & 9 deletions qubesusbproxy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def device_list_change(
# send events about devices detached/attached outside by themselves
for port_id, front_vm in detached.items():
dev = device_class(vm, port_id)
ext.ensure_detach(front_vm, dev.port)
asyncio.ensure_future(
front_vm.fire_event_async(
f"device-detach:{devclass}", port=dev.port
Expand All @@ -63,8 +64,8 @@ def device_list_change(
for port_id in added:
device = device_class(vm, port_id)
vm.fire_event(f"device-added:{devclass}", device=device)
for dev_ident, front_vm in attached.items():
dev = device_class(vm, dev_ident)
for port_id, front_vm in attached.items():
dev = device_class(vm, port_id)
# options are unknown, device already attached
asyncio.ensure_future(
front_vm.fire_event_async(
Expand Down Expand Up @@ -167,6 +168,7 @@ async def confirm_device_attachment(device, frontends) -> str:
print(str(exc.__class__.__name__) + ":", str(exc), file=sys.stderr)
return ""


async def _do_confirm_device_attachment(device, frontends):
socket = "device-agent.GUI"

Expand All @@ -189,23 +191,24 @@ async def _do_confirm_device_attachment(device, frontends):
"targets": front_names,
"default_target": front_names[0] if number_of_targets == 1 else "",
"icons": {
dom.name
if dom.klass != "DispVM" else f'@dispvm:{dom.name}':
dom.icon for dom in doms.values()
(
dom.name if dom.klass != "DispVM" else f"@dispvm:{dom.name}"
): dom.icon
for dom in doms.values()
},
}

socked_call = asyncio.create_task(call_socket_service(
guivm, socket, "dom0", params, SOCKET_PATH
))
socked_call = asyncio.create_task(
call_socket_service(guivm, socket, "dom0", params, SOCKET_PATH)
)

while not socked_call.done():
await asyncio.sleep(0.1)

ask_response = await socked_call

if ask_response.startswith("allow:"):
chosen = ask_response[len("allow:"):]
chosen = ask_response[len("allow:") :]
if chosen in front_names:
return chosen
return ""

0 comments on commit 6013161

Please sign in to comment.