Improved initial load state management for evaluation on background, but kill sessions on mainthread
This commit is contained in:
parent
0b065fb025
commit
9948ac0454
3 changed files with 28 additions and 15 deletions
|
|
@ -20,7 +20,7 @@ from core.errors.logger import logger
|
|||
|
||||
# generic
|
||||
from functools import partial
|
||||
|
||||
import time
|
||||
|
||||
SINGBOX_PROTOCOLS = (ProtocolChoice.HYSTERIA2, ProtocolChoice.VLESS)
|
||||
|
||||
|
|
@ -215,7 +215,7 @@ def evaluate_state_on_startup() -> Result:
|
|||
if systemwide_state:
|
||||
error_msg = "The previous system-wide connection was not correctly turned off before the app was killed. Do you want to evaluate it? (no blindly kills it)"
|
||||
no_option = partial(kill_any_protocol, current_state=systemwide_state, active_protocol=systemwide_state.protocol)
|
||||
return Result(valid=False, no_option=no_option, error_type=ResultError.ZOMBIE_CONNECTION, message=error_msg)
|
||||
return Result(valid=False, no_option=no_option, error_type=ResultError.ZOMBIE_SYSTEM, message=error_msg)
|
||||
|
||||
|
||||
#-----------------------
|
||||
|
|
@ -223,8 +223,9 @@ def evaluate_state_on_startup() -> Result:
|
|||
#-----------------------
|
||||
active_session_profiles = SessionStateController.all()
|
||||
if active_session_profiles:
|
||||
for each_profile in active_session_profiles:
|
||||
logger.info(f"Removing this profile {active_session_profiles} from session since it's a fresh restart.")
|
||||
SessionStateController.remove(each_profile.id)
|
||||
for each_session in active_session_profiles:
|
||||
logger.info(f"Killing profile {each_session}")
|
||||
Notifications.emit(EventType.SESSION_PROFILE_KILL, each_session)
|
||||
time.sleep(4)
|
||||
|
||||
return Result(valid=True)
|
||||
|
|
|
|||
|
|
@ -66,13 +66,18 @@ class ThreadPlumbing:
|
|||
def _on_complete(self, original_result: Result):
|
||||
"""Get a potential function prescription and return it to the main thread."""
|
||||
|
||||
#----------------------------
|
||||
if not original_result:
|
||||
return
|
||||
|
||||
if isinstance(original_result, Result):
|
||||
# Wrapper:
|
||||
#----------------------------
|
||||
if not original_result.valid:
|
||||
logger.error(audit(original_result))
|
||||
|
||||
result = unwrap(original_result)
|
||||
else:
|
||||
# Convert:
|
||||
result = convert_to_result(original_result)
|
||||
|
||||
#----------------------------
|
||||
# Went Right with a New Function Prescription to Run Right Now:
|
||||
|
|
@ -229,13 +234,19 @@ def convert_to_result(result: Any) -> Result:
|
|||
logger.error(error_msg)
|
||||
|
||||
if isinstance(result, bool):
|
||||
if result:
|
||||
return Result(valid=True)
|
||||
else:
|
||||
return Result(valid=result, error_type=ResultError.INVALID_INPUT, message=error_msg)
|
||||
|
||||
elif isinstance(result, dict):
|
||||
valid = result.get('valid', False)
|
||||
message = result.get('message', False)
|
||||
if not message:
|
||||
message = error_msg
|
||||
if valid:
|
||||
return Result(valid=True)
|
||||
|
||||
if message:
|
||||
error_msg = message
|
||||
return Result(valid=valid, error_type=ResultError.INVALID_INPUT, message=error_msg)
|
||||
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ class ResultError(Enum):
|
|||
BILLING_CONFLICT = "billing_conflict"
|
||||
STATE_CONFLICT = "state_conflict" # with actions to kill
|
||||
STATE = "state"
|
||||
ZOMBIE_CONNECTION = "zombie_connection"
|
||||
ZOMBIE_SYSTEM = "zombie_system"
|
||||
ZOMBIE_SESSION = "zombie_session"
|
||||
TICKET = "ticket"
|
||||
NO_TICKET = "no_ticket"
|
||||
RANDOM_TICKETS_OFF = "random_tickets_off"
|
||||
|
|
|
|||
Loading…
Reference in a new issue