diff --git a/core/infrastructure/global_state_coordinator.py b/core/infrastructure/global_state_coordinator.py index 269c98a..431c75a 100644 --- a/core/infrastructure/global_state_coordinator.py +++ b/core/infrastructure/global_state_coordinator.py @@ -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) diff --git a/core/infrastructure/plumbing.py b/core/infrastructure/plumbing.py index fc52c3a..346e722 100644 --- a/core/infrastructure/plumbing.py +++ b/core/infrastructure/plumbing.py @@ -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.""" - #---------------------------- - # Wrapper: - #---------------------------- - if not original_result.valid: - logger.error(audit(original_result)) + if not original_result: + return - result = unwrap(original_result) + 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): - return Result(valid=result, error_type=ResultError.INVALID_INPUT, message=error_msg) + 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: diff --git a/core/models/Result.py b/core/models/Result.py index 9e52acb..a83b9a4 100644 --- a/core/models/Result.py +++ b/core/models/Result.py @@ -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"