from gui.v2.infrastructure.thread_singleton import get_main_thread_dispatcher from core.infrastructure.state_management.state_poll_loop import PollState from core.services.helpers.install_dependencies import setup_singbox_binary from core.utils.basic_operations.does_file_exist import does_file_exist from core.services.helpers.install_dependencies import SUDO_SINGBOX_LOCATION from gui.v2.infrastructure.action_registry import register_action from core.infrastructure.global_state_coordinator import coordinate_evaluation from core.models.Result import Result, ResultError from core.errors.logger import logger from gui.v2.infrastructure.setup_observers import connection_observer, application_version_observer from gui.v2.infrastructure.take_plumbing_action import take_action def post_state_evaluation(result: Result): """Success path for initial state evaluation""" print("Initial State evaluation complete, starting to poll..") poll_state = PollState(ui_dispatcher=get_main_thread_dispatcher()) poll_state.start_polling() # if not result.valid and result.error_type == ResultError.ZOMBIE_SESSION and result.data: # active_session_profiles = result.data # logger.info("Removing Zombie Session profiles on the main thread.") # 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) @register_action(ResultError.ZOMBIE_SYSTEM) def evaluate_bad_state(): """Start core's evaluation of state with a GUI observer.""" take_action( action=coordinate_evaluation, ui_caller=post_state_evaluation, connection_observer=connection_observer ) @register_action(ResultError.SUBSCRIPTION) def navigate_to_new_sub_page() -> Result: return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="id") def generic_result_reciever(result: Result) -> Result: if not result.valid: return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="menu") @register_action(ResultError.SETUP_SINGBOX) def navigate_to_singbox_setup() -> Result: if not does_file_exist(SUDO_SINGBOX_LOCATION): logger.info("Installing Singbox Binary.") take_action( action=setup_singbox_binary, ui_caller=generic_result_reciever, application_version_observer=application_version_observer, connection_observer=connection_observer ) return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="networking_setup")