diff --git a/gui/v2/actions/error_handlers.py b/gui/v2/actions/error_handlers.py index 89dc5cc..146536e 100644 --- a/gui/v2/actions/error_handlers.py +++ b/gui/v2/actions/error_handlers.py @@ -1,12 +1,13 @@ +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 +from gui.v2.infrastructure.setup_observers import connection_observer, application_version_observer -# from gui.v2.infrastructure.ThreadSafetyTool import ThreadSafetyTool -# mainthread = ThreadSafetyTool() from gui.v2.infrastructure.take_plumbing_action import take_action @@ -36,3 +37,23 @@ def evaluate_bad_state(): @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")