27 lines
839 B
Python
Executable file
27 lines
839 B
Python
Executable file
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):
|
|
if isinstance(profile, SystemProfile) and _connection_code(profile) in SINGBOX_PROTOCOLS:
|
|
return _system_state_profile_id() == int(profile.id)
|
|
return ProfileController.is_enabled(profile)
|