Improved Connection Observer support for Tor bootstrap feedback, and error handling of the sudo setup

This commit is contained in:
SimplifiedPrivacy 2026-08-13 08:22:25 -04:00
parent f527b39e26
commit 56b2836ecf

View file

@ -2,6 +2,7 @@ from core.services.helpers.setup_sudo_scripts import auto_install_sudo_script, t
from core.services.helpers.install_dependencies import setup_singbox_binary from core.services.helpers.install_dependencies import setup_singbox_binary
from core.services.helpers.manage_assets import sudo_assets_folder_setup from core.services.helpers.manage_assets import sudo_assets_folder_setup
from core.observers.ApplicationVersionObserver import ApplicationVersionObserver from core.observers.ApplicationVersionObserver import ApplicationVersionObserver
from core.observers.ConnectionObserver import ConnectionObserver
from core.models.Result import Result, ResultError from core.models.Result import Result, ResultError
import sys import sys
@ -73,24 +74,38 @@ b) Get an automated installer.
print("Now we are now setting up the singbox binary, also in a sudo folder.") print("Now we are now setting up the singbox binary, also in a sudo folder.")
# OBSERVER # OBSERVERS
application_version_observer = ApplicationVersionObserver() application_version_observer = ApplicationVersionObserver()
connection_observer = ConnectionObserver()
application_version_observer.subscribe('downloading', lambda event: update_status( application_version_observer.subscribe('downloading', lambda event: update_status(
f'{event.subject if event.subject else "Downloading.."}')) f'{event.subject if event.subject else "Downloading.."}'))
application_version_observer.subscribe('download_progressing', lambda event: update_status( application_version_observer.subscribe('download_progressing', lambda event: update_status(
f'{event.subject if event.subject else "Downloading.."}')) f'{event.subject if event.subject else "Downloading.."}'))
application_version_observer.subscribe('downloaded', lambda event: update_status( application_version_observer.subscribe('downloaded', lambda event: update_status(
f'{event.subject if event.subject else "Downloaded"}')) f'{event.subject if event.subject else "Downloaded"}'))
connection_observer.subscribe('connecting', lambda event: update_status(
f'[{event.subject.get("attempt_count")}/{event.subject.get("maximum_number_of_attempts")}] Performing connection attempt...'))
connection_observer.subscribe('tor_bootstrapping', lambda event: update_status(
'Establishing Tor connection...'))
connection_observer.subscribe(
'tor_bootstrap_progressing', lambda event: update_status(f'{event.subject if event.subject else "Tor Bootstrapping.."}'))
connection_observer.subscribe(
'message', lambda event: update_status(f'{event.subject if event.subject else "Connecting.."}'))
connection_observer.subscribe(
'tor_bootstrapped', lambda event: update_status('Tor connection established.'))
# Actual Binary Setup: # Actual Binary Setup:
try: try:
setup_result = setup_singbox_binary(application_version_observer) setup_result = setup_singbox_binary(application_version_observer, connection_observer)
except ConnectionError as e: except ConnectionError as e:
print(f"{connection_error}: {str(e)}") print(f"{connection_error}: {str(e)}")
sys.exit()
except ValueError as e: except ValueError as e:
print(f"Your configuration files may be corrupted, or a server-side error giving bad data: {str(e)}") print(f"Your configuration files may be corrupted, or a server-side error giving bad data: {str(e)}")
sys.exit()
except Exception as e: except Exception as e:
print(f"Unknown error: {str(e)}") print(f"Unknown error: {str(e)}")
sys.exit()
# Error handling: # Error handling:
if not setup_result.valid: if not setup_result.valid: