from core.infrastructure.global_state import ProfileStateRepository from core.controllers.ProfileController import ProfileController from core.controllers.SystemStateController import SystemStateController from core.models.system.SystemProfile import SystemProfile SINGBOX_PROTOCOLS = ("hysteria2", "vless") def _connection_code(profile): connection = getattr(profile, "connection", None) return getattr(connection, "code", None) def _system_state_profile_id(): state = SystemStateController.get() if state is None: return None try: return int(state.profile_id) except (TypeError, ValueError): return None def is_profile_enabled_for_gui(profile) -> bool: """Checks Profile State Against in-memory Repo""" is_enabled = ProfileStateRepository().is_profile_active(profile.id) # print(f"profile id: {profile.id} | Enabled: {is_enabled}") return is_enabled # if isinstance(profile, SystemProfile) and _connection_code(profile) in SINGBOX_PROTOCOLS: # return _system_state_profile_id() == int(profile.id) # return ProfileController.is_enabled(profile)