Skip to content
Open
Show file tree
Hide file tree
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
28 changes: 14 additions & 14 deletions qui/devices/actionable_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import asyncio
import functools
import pathlib
import time
from typing import Iterable, Callable, Optional, List

import qubesadmin
Expand All @@ -38,7 +39,6 @@
from gi.repository import Gtk, GdkPixbuf, GLib # isort:skip

from . import backend
import time


def load_icon(icon_name: str, backup_name: str, size: int = 24):
Expand Down Expand Up @@ -247,7 +247,7 @@ def __init__(self, vm: backend.VM, device: backend.Device):
self.actionable = False

async def widget_action(self, *_args):
self.device.attach_to_vm(self.vm)
await asyncio.to_thread(self.device.attach_to_vm, self.vm)


class DetachWidget(ActionableWidget, SimpleActionWidget):
Expand All @@ -259,7 +259,7 @@ def __init__(self, vm: backend.VM, device: backend.Device, variant: str = "dark"
self.device = device

async def widget_action(self, *_args):
self.device.detach_from_vm(self.vm, False)
await asyncio.to_thread(self.device.detach_from_vm, self.vm, False)


class DetachWithWidget(ActionableWidget, SimpleActionWidget):
Expand All @@ -278,7 +278,7 @@ def __init__(self, vm: backend.VM, device: backend.Device, variant: str = "dark"
self.device = device

async def widget_action(self, *_args):
self.device.detach_from_vm(self.vm, True)
await asyncio.to_thread(self.device.detach_from_vm, self.vm, True)


class DetachAndShutdownWidget(ActionableWidget, SimpleActionWidget):
Expand All @@ -292,8 +292,8 @@ def __init__(self, vm: backend.VM, device: backend.Device, variant: str = "dark"
self.device = device

async def widget_action(self, *_args):
self.device.detach_from_vm(self.vm, True)
self.vm.vm_object.shutdown()
await asyncio.to_thread(self.device.detach_from_vm, self.vm, True)
await asyncio.to_thread(self.vm.vm_object.shutdown)


class DetachAndAttachWidget(ActionableWidget, VMWithIcon):
Expand All @@ -306,8 +306,8 @@ def __init__(self, vm: backend.VM, device: backend.Device, variant: str = "dark"

async def widget_action(self, *_args):
for vm in self.device.attachments:
self.device.detach_from_vm(vm, True)
self.device.attach_to_vm(self.vm)
await asyncio.to_thread(self.device.detach_from_vm, vm, True)
await asyncio.to_thread(self.device.attach_to_vm, self.vm)


class AttachDisposableWidget(ActionableWidget, VMWithIcon):
Expand All @@ -320,9 +320,9 @@ def __init__(self, vm: backend.VM, device: backend.Device, variant: str = "dark"

async def widget_action(self, *_args):
new_dispvm = qubesadmin.vm.DispVM.from_appvm(self.vm.vm_object.app, self.vm)
new_dispvm.start()
await asyncio.to_thread(new_dispvm.start)

self.device.attach_to_vm(backend.VM(new_dispvm))
await asyncio.to_thread(self.device.attach_to_vm, backend.VM(new_dispvm))


class DetachAndAttachDisposableWidget(ActionableWidget, VMWithIcon):
Expand All @@ -334,11 +334,11 @@ def __init__(self, vm: backend.VM, device: backend.Device, variant: str = "dark"
self.device = device

async def widget_action(self, *_args):
self.device.detach_from_vm(self.vm)
await asyncio.to_thread(self.device.detach_from_vm, self.vm)
new_dispvm = qubesadmin.vm.DispVM.from_appvm(self.vm.vm_object.app, self.vm)
new_dispvm.start()
await asyncio.to_thread(new_dispvm.start)

self.device.attach_to_vm(backend.VM(new_dispvm))
await asyncio.to_thread(self.device.attach_to_vm, backend.VM(new_dispvm))


class ToggleFeatureItem(ActionableWidget, SimpleActionWidget):
Expand Down Expand Up @@ -379,7 +379,7 @@ def __init__(self, usbvm: backend.VM, variant: str = "dark"):
self.usbvm = usbvm

async def widget_action(self, *_args):
self.usbvm.vm_object.start()
await asyncio.to_thread(self.usbvm.vm_object.start)


#### Configuration-related actions
Expand Down
Loading