Moved UI state update on restore systemwide verification from the repo to the controller
This commit is contained in:
parent
b073ce2fa5
commit
4096196849
3 changed files with 30 additions and 16 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue