From 40961968494d75792518e9c89bea7e07c2dc417a Mon Sep 17 00:00:00 2001 From: SimplifiedPrivacy Date: Mon, 2 Nov 2026 20:22:21 -0500 Subject: [PATCH] Moved UI state update on restore systemwide verification from the repo to the controller --- core/controllers/SystemStateController.py | 16 ++++++++++++++-- core/infrastructure/global_state.py | 14 ++------------ core/infrastructure/global_state_coordinator.py | 16 ++++++++++++++-- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/core/controllers/SystemStateController.py b/core/controllers/SystemStateController.py index d22601a..f53f9e4 100644 --- a/core/controllers/SystemStateController.py +++ b/core/controllers/SystemStateController.py @@ -67,9 +67,21 @@ class SystemStateController: def verify(profile_id: int) -> bool: """Flip on Verification (which updates the UI), if it passes the check on state""" - state_repo = ProfileStateRepository() - return state_repo.verify_its_up(profile_id=profile_id) + print(f"Verifying profile {profile_id}") + state_repo = ProfileStateRepository() + if state_repo.global_state.systemwide_profile_id != profile_id: + logger.error(f"Trying to verify that {profile_id} is systemwide, but {self.global_state.systemwide_profile_id} is the current one") + return False + + logger.info("Passed screening that there's no state mismatch. Syncing to repo..") + state_repo.verify_its_up(profile_id=profile_id) + + notification = f"Connected {profile_id}." + Notifications.emit(EventType.STATUS_UPDATE, notification) + Notifications.emit(EventType.SYSTEM_ENABLE, profile_id) + print(notification) + return True # old version: diff --git a/core/infrastructure/global_state.py b/core/infrastructure/global_state.py index b0da987..6eeb323 100644 --- a/core/infrastructure/global_state.py +++ b/core/infrastructure/global_state.py @@ -96,20 +96,10 @@ class ProfileStateRepository: self.global_state.systemwide_active = True - def verify_its_up(self, profile_id: int) -> bool: + def verify_its_up(self, profile_id: int): """Flips on Verification for Systemwide, if the rest of the state matches""" - - if not self.global_state.systemwide_active: - return False - - if self.global_state.systemwide_profile_id != profile_id: - return False - + self.global_state.systemwide_active = True self.global_state.verified_working = True - notification = "Connected." - Notifications.emit(EventType.STATUS_UPDATE, notification) - Notifications.emit(EventType.SYSTEM_ENABLE, profile_id) - return True def is_profile_active(self, profile_id: int) -> bool: # Check system profile diff --git a/core/infrastructure/global_state_coordinator.py b/core/infrastructure/global_state_coordinator.py index 4328270..aa113a6 100644 --- a/core/infrastructure/global_state_coordinator.py +++ b/core/infrastructure/global_state_coordinator.py @@ -27,6 +27,8 @@ SINGBOX_PROTOCOLS = (ProtocolChoice.HYSTERIA2, ProtocolChoice.VLESS) def coordinate_evaluation(connection_observer: ConnectionObserver) -> Result: """See if a connection can be salvaged. If not, rip it down & start over.""" + logger.info("Starting an evaluation of the systemwide profile.") + # Claimed JSON state: if not SystemStateController.exists(): error_msg = "State vanished inbetween the previous error prompt and now. That state is an external file, so that is technically possible, but a critical error." @@ -69,6 +71,8 @@ def coordinate_evaluation(connection_observer: ConnectionObserver) -> Result: logger.info("Doing a new connection due to the interface being down") return establish_connection(profile, ignore={}, connection_observer=connection_observer) + logger.info("The Interface is up") + #----------------------- # FIREWALL #----------------------- @@ -82,9 +86,12 @@ def coordinate_evaluation(connection_observer: ConnectionObserver) -> Result: else: if firewalled: firewall_on = killswitch.status() + logger.info(f"Current firewall status is {firewall_on}") else: firewall_on = False + logger.info(f"Is the firewall on? {firewall_on}") + #----------------------- # # DNS #----------------------- @@ -107,12 +114,17 @@ def coordinate_evaluation(connection_observer: ConnectionObserver) -> Result: test_result = test_ip_systemwide_for_any_protocol(profile_id=profile_id, protocol=protocol, connection_observer=connection_observer) if not test_result.valid: - logger.info("IP address check was not valid, so we're doing a new connection.") + logger.error("IP address check was not valid, so we're doing a new connection.") return establish_connection(profile, ignore={}, connection_observer=connection_observer) + + print("IP address matches, proceeding with firewall & DNS tests..") if firewall_dns_in_line_with_expectations(firewalled=firewall_on, dns_set=dns_on, protocol=protocol): - logger.info("IP address is connected and firewall & DNS expectations match reality. Update/Verify Global State that it's on") + + print("IP address is connected and firewall & DNS expectations match reality. Update/Verify Global State that it's on") + SystemStateController.sync_system_state(current_state=json_state) + if SystemStateController.verify(profile_id=profile_id): # this notifies the UI: return Result(valid=True) else: