Explicit connection UI graphical state updates

This commit is contained in:
SimplifiedPrivacy 2026-10-15 16:24:27 -04:00
parent f25d2aad37
commit db9553a0f5

View file

@ -1,3 +1,4 @@
from core.models.BaseProfile import ProfileType
from core.models.Result import Result, ResultError
import functools
@ -28,6 +29,11 @@ from gui.v2.ui.popups.confirmation_popup import ConfirmationPopup
from gui.v2.ui.popups.endpoint_verification_popup import EndpointVerificationPopup
from gui.v2.ui.popups.ticket_data_loss_popup import TicketDataLossPopup
from gui.v2.infrastructure.setup_observers import (
application_version_observer, connection_observer,
profile_observer
)
class MenuPage(Page):
def __init__(self, page_stack=None, main_window=None, parent=None):
@ -386,6 +392,10 @@ class MenuPage(Page):
self._render_profile_details(details)
def _render_profile_details(self, details):
print(f"details entering _render_profile_details is {details}")
self.reverse_id = details["id"]
# THIS IS UPDATING THE PROFILE ID
@ -512,35 +522,66 @@ class MenuPage(Page):
and not self.connection_manager.is_profile_connected(self.reverse_id))
def handle_result(self, result: Result):
print(f"handle error got result {result}")
def post_connect(self, result: Result):
"""Recieve the callback after a connection attempt."""
# --------------------
# BOTTOM LEFT STATUS BAR
# --------------------
if result.message:
if len(result.message) > 20:
self.update_status.enable_marquee
self.update_status.update_status(result.message)
# --------------------
# CONNECTION WORKED
# --------------------
if result.valid:
self.update_status.enable_marquee
# BACKGROUND CONNECTION IMAGE:
self.update_status.update_image(appearance_value="background_connected")
# BUTTON:
profile_type = result.data
if profile_type == ProfileType.SYSTEM:
self.disconnect_system_wide_button.setVisible(True)
elif profile_type == ProfileType.SESSION:
self.disconnect_button.setVisible(True)
else:
print("This is an error where the GUI recieved an invalid profile type, but we are enabling the systemwide by default.")
self.disconnect_system_wide_button.setVisible(True)
return
# --------------------
# FAILURE EVALUATION
# --------------------
if result.error_type == ResultError.NAVIGATE_TO:
print(f"Navigating to page {result.navigate_to}")
print(f"We are auto-navigating to page {result.navigate_to}")
self.custom_window.navigator.navigate(result.navigate_to)
elif result.error_type == ResultError.SUBSCRIPTION:
print("going to sub page")
print("We are navigating to the subscription page")
self.update_status.update_status("Select Subscription Choice")
self.custom_window.navigator.navigate("id")
else:
error_type = result.error_type.value
print(f"handle_error was called, but we do not currently have a pre-made solution for the unknown situation of {error_type}")
print(f"We do not currently have a pre-made solution for the unknown situation of {error_type}")
self.update_status.update_status(error_type)
def connect(self):
print(f"hit connect to enable profile. self.reverse_id is {self.reverse_id}")
pre_thread_result = connect_profile(profile_id=self.reverse_id, ui_caller=self.handle_result)
"""Enable the profile id tied to reverse_id"""
print("Starting to connect..")
if not pre_thread_result.valid:
print(f"Pre-thread errors: {pre_thread_result.message}")
# Step 1. Disable all buttons to prevent repeat pushing.
self.boton_just.setVisible(False)
self.boton_launch.setEnabled(False)
self.boton_just_session.setEnabled(False)
# Step 2. Connect with post_connect setup to recieve the result.
immediate_error = connect_profile(profile_id=self.reverse_id, ui_caller=self.post_connect)
# Step 3. Evaluate immediate errors (if it never even gets to the callback)
if not immediate_error.valid:
self.update_status.update_status(immediate_error.message)
return
# Temporary until moved to menu coordinator:
@ -607,19 +648,27 @@ class MenuPage(Page):
@pyqtSlot(object)
def handle_task_result(self, result: MenuResult):
print(f"result in handle_task_result is {result}")
if "sync_data" in result:
self.update_status.update_values(*result["sync_data"])
if result.get("clear_selection") and result.get("profile_id") == self.reverse_id:
self.clear_profile_details()
if result.get("refresh"):
self.refresh_menu_buttons(result)
self._set_task_busy(result.get("busy", False))
if result.get("message"):
handlers = {True: self.update_status.enable_marquee, False: self.update_status.update_status}
handlers[bool(result.get("is_enabled"))](result["message"])
handlers = {"confirmation": self._show_confirmation, "verification": self._show_verification,
"navigate": self._navigate_result, "install": self._show_install_result,
"ticket_data_loss": self._show_ticket_loss_result}
handler = handlers.get(result["status"])
if handler is not None:
handler(result)