@@ -629,6 +629,14 @@ def _load_spice_store(self):
629629 enabled_extensions .add (extension )
630630 enabled_spices .add ((extension , 'extensions' , None ))
631631
632+ # Build set of enabled instance IDs per uuid, so we only process
633+ # config files for instances that are actually running.
634+ enabled_ids = {}
635+ for uuid , _type , instance_id in enabled_spices :
636+ enabled_ids .setdefault (uuid , set ())
637+ if instance_id is not None :
638+ enabled_ids [uuid ].add (instance_id )
639+
632640 keyboard_spices = sorted (enabled_spices )
633641 spice_keybinds = {}
634642 spice_properties = {}
@@ -638,11 +646,10 @@ def _load_spice_store(self):
638646 config_path = Path .joinpath (settings_dir , uuid )
639647 if Path .exists (config_path ):
640648 configs = [x for x in os .listdir (config_path ) if x .endswith (".json" )]
641- # If we encounted numbered and non-numbered, config files, filter out the uuid-named one
642- if not all (x .split (".json" )[0 ].isdigit () for x in configs ) and any (x .split (".json" )[0 ].isdigit () for x in configs ):
643- for index , value in enumerate (configs ):
644- if not value .split (".json" )[0 ].isdigit ():
645- configs .pop (index )
649+ # Filter out config files for instances that aren't running
650+ ids_for_uuid = enabled_ids .get (uuid , set ())
651+ configs = [x for x in configs
652+ if not x .split (".json" )[0 ].isdigit () or x .split (".json" )[0 ] in ids_for_uuid ]
646653 for config in configs :
647654 config_json = Path .joinpath (config_path , config )
648655 _id = config .split (".json" )[0 ]
@@ -687,7 +694,7 @@ def _load_spice_store(self):
687694 with open (system_metadata_path , encoding = "utf-8" ) as metadata :
688695 json_data = json .load (metadata )
689696 category_label = _ (json_data ["name" ])
690- if not _id :
697+ if not _id or len ( enabled_ids . get ( uuid , set ())) <= 1 :
691698 cat_label = category_label if category_label else uuid
692699 new_categories .append ([cat_label , uuid , "spices" , None , spice_props ])
693700 instance_num = 1
@@ -717,7 +724,7 @@ def _load_spice_store(self):
717724 gettext .textdomain (uuid )
718725 binding_label = gettext .gettext (list (binding_values .keys ())[0 ])
719726 binding_schema = spice_properties [spice ]["path" ]
720- binding_category = f"{ uuid } _{ instance_num - 1 } " if _id else uuid
727+ binding_category = f"{ uuid } _{ instance_num - 1 } " if _id and len ( enabled_ids . get ( uuid , set ())) > 1 else uuid
721728 new_keybindings .append ([binding_label , binding_schema , binding_key , binding_category , dbus_info ])
722729 self ._spice_categories [binding_category ] = category_label
723730
0 commit comments