@@ -147,6 +147,7 @@ def __init__(self, app_name, qapp, dispatcher):
147147 self .dispatcher .add_handler ("domain-shutdown" , self .vm_shutdown )
148148 self .dispatcher .add_handler ("domain-start-failed" , self .vm_shutdown )
149149 self .dispatcher .add_handler ("domain-start" , self .vm_start )
150+ self .dispatcher .add_handler ("domain-unpaused" , self .vm_unpaused )
150151
151152 self .dispatcher .add_handler (
152153 "property-set:template_for_dispvms" , self .vm_dispvm_template_change
@@ -160,6 +161,13 @@ def __init__(self, app_name, qapp, dispatcher):
160161 "property-del:template_for_dispvms" , self .vm_dispvm_template_change
161162 )
162163
164+ self .dispatcher .add_handler (
165+ "domain-feature-set:internal" , self .update_internal_feature
166+ )
167+ self .dispatcher .add_handler (
168+ "domain-feature-delete:internal" , self .update_internal_feature
169+ )
170+
163171 for feature in [backend .FEATURE_HIDE_CHILDREN , backend .FEATURE_ATTACH_WITH_MIC ]:
164172
165173 self .dispatcher .add_handler (
@@ -229,10 +237,11 @@ def initialize_vm_data(self):
229237 for vm in self .qapp .domains :
230238 wrapped_vm = backend .VM (vm )
231239 try :
232- if wrapped_vm .is_attachable :
233- self .vms .add (wrapped_vm )
234- if wrapped_vm .is_dispvm_template :
235- self .dispvm_templates .add (wrapped_vm )
240+ if not vm .features .get ("internal" ):
241+ if wrapped_vm .is_attachable :
242+ self .vms .add (wrapped_vm )
243+ if wrapped_vm .is_dispvm_template :
244+ self .dispvm_templates .add (wrapped_vm )
236245 if vm .name == "sys-usb" :
237246 self .sysusb = wrapped_vm
238247 self .sysusb .is_running = vm .is_running ()
@@ -393,6 +402,36 @@ def update_single_feature(self, _vm, _event, feature, value=None, oldvalue=None)
393402 self .parent_ports_to_hide .append (dev .port )
394403 self .hide_child_devices (dev .port , False )
395404
405+ def vm_unpaused (self , vm , _event , ** _kwargs ):
406+ wrapped_vm = backend .VM (vm )
407+ try :
408+ attachable = wrapped_vm .is_attachable
409+ internal = vm .features .get ("internal" )
410+ except qubesadmin .exc .QubesException :
411+ attachable , internal = False , False
412+ if attachable and not internal :
413+ self .vms .add (wrapped_vm )
414+
415+ def update_internal_feature (
416+ self , vm , _event , feature , value = None , oldvalue = None
417+ ): # pylint: disable=unused-argument
418+ if bool (value ) == bool (oldvalue ):
419+ return
420+ wrapped_vm = backend .VM (vm )
421+ if not value :
422+ self .vms .discard (wrapped_vm )
423+ self .dispvm_templates .discard (wrapped_vm )
424+ return
425+ try :
426+ attachable = wrapped_vm .is_attachable
427+ dispvm_template = wrapped_vm .is_dispvm_template
428+ except qubesadmin .exc .QubesException :
429+ attachable , dispvm_template = False , False
430+ if attachable :
431+ self .vms .add (wrapped_vm )
432+ if dispvm_template :
433+ self .dispvm_templates .add (wrapped_vm )
434+
396435 def initialize_features (self , * _args , ** _kwargs ):
397436 """
398437 Initialize all feature-related states
@@ -487,7 +526,12 @@ def device_detached(self, vm, _event, port, **_kwargs):
487526
488527 def vm_start (self , vm , _event , ** _kwargs ):
489528 wrapped_vm = backend .VM (vm )
490- if wrapped_vm .is_attachable :
529+ try :
530+ internal = vm .features .get ("internal" )
531+ attachable = wrapped_vm .is_attachable
532+ except qubesadmin .exc .QubesException :
533+ internal , attachable = False , False
534+ if attachable and not internal :
491535 self .vms .add (wrapped_vm )
492536 if wrapped_vm == self .sysusb :
493537 self .sysusb .is_running = True
@@ -522,7 +566,12 @@ def vm_shutdown(self, vm, _event, **_kwargs):
522566 def vm_dispvm_template_change (self , vm , _event , ** _kwargs ):
523567 """Is template for dispvms property changed"""
524568 wrapped_vm = backend .VM (vm )
525- if wrapped_vm .is_dispvm_template :
569+ try :
570+ internal = vm .features .get ("internal" )
571+ dispvm_template = wrapped_vm .is_dispvm_template
572+ except qubesadmin .exc .QubesException :
573+ internal , dispvm_template = False , False
574+ if dispvm_template and not internal :
526575 self .dispvm_templates .add (wrapped_vm )
527576 else :
528577 self .dispvm_templates .discard (wrapped_vm )
0 commit comments