Compare commits

..

No commits in common. "a0b39365a3bd8a731094666458ac7173fc463454" and "a6c31375b0d156528bf6765b88293ec956feb68d" have entirely different histories.

8 changed files with 1055 additions and 70 deletions

View file

@ -21,6 +21,16 @@ def post_state_evaluation(result: Result):
poll_state.start_polling()
# if not result.valid and result.error_type == ResultError.ZOMBIE_SESSION and result.data:
# active_session_profiles = result.data
# logger.info("Removing Zombie Session profiles on the main thread.")
# for each_profile in active_session_profiles:
# logger.info(f"Removing this profile {active_session_profiles} from session since it's a fresh restart.")
# SessionStateController.remove(each_profile.id)
@register_action(ResultError.ZOMBIE_SYSTEM)
def evaluate_bad_state():
"""Start core's evaluation of state with a GUI observer."""
@ -54,5 +64,3 @@ def navigate_to_singbox_setup() -> Result:
connection_observer=connection_observer
)
return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="networking_setup")

View file

@ -1,8 +1,8 @@
# core
from core.models.manage.database_recovery import wipe_and_kill_entire_app
from core.infrastructure.state_management.global_state_controller import connected_system_profile_id, connected_session_profile_ids, is_connected
from core.observers.Notifications import Notifications, EventType
from core.models.enum_models import ProtocolChoice
from core.services.profiles.update_profile import update_profile
# from core.controllers.SessionStateController import SessionStateController
# from core.services.networking.systemwide.systemwide_wireguard import change_port_then_reconnect
@ -37,11 +37,9 @@ from gui.v2.infrastructure.setup_observers import (
from gui.v2.actions.error_handlers import navigate_to_new_sub_page
# generic
from typing import Optional
from typing import Callable
from functools import partial
import atexit
import sys
@type_checker
def get_profile(profile_id: int):
@ -316,7 +314,7 @@ def disconnect_many_profiles(profile_ids: list) -> Result:
return Result(valid=False, data=failed_list)
def disconnect_active(ui_caller: Optional[Callable] = None) -> Result:
def disconnect_active(ui_caller: Callable) -> Result:
"""Disconnects active session profiles first, then system."""
# SESSION
@ -344,10 +342,8 @@ def disconnect_active(ui_caller: Optional[Callable] = None) -> Result:
system_disconnected.message = error_msg
return system_disconnected
if ui_caller:
ui_caller(Result(valid=True))
else:
return Result(valid=True)
ui_caller(Result(valid=True))
def sync_now(ui_caller: Callable):
take_action(
@ -387,17 +383,19 @@ def delete_profile_action(profile_id: int, ui_caller: Callable) -> Result:
return Result(valid=True) # this doesn't mean it deleted, just that it launched.
@register_action(ResultError.DELETE_DB)
def shut_down_and_wipe() -> Result:
"""Attempt a graceful close of profiles, then wipe the database regardless."""
logger.info("Shutting down profiles, and then wiping.")
try:
disconnect_active(ui_caller=None)
return wipe_and_kill_entire_app()
except Exception as e:
logger.error(f"Wiping anyway despite {str(e)}")
return wipe_and_kill_entire_app()
def edit_profile(
profile_id: int,
key: str,
new_value: str,
ui_caller: Callable
):
"""Thread in background the updating of the profile"""
take_action(
action=update_profile,
ui_caller=ui_caller,
profile_id=profile_id,
key=key,
new_value=new_value
)
# atexit.register(disconnect_active(ui_caller=finish))

View file

@ -44,10 +44,7 @@ def load_profile(profile_id: int, on_error: StatusCallback) -> BaseProfile | Non
def load_profiles(on_error: StatusCallback) -> dict[int, BaseProfile]:
"""Load all profiles here so list rendering is not responsible for controller failures."""
try:
profile_result = ProfileController.get_all()
if not profile_result.valid:
return profile_result
return ProfileController.get_all()
except Exception as error:
_report_load_error(
error,
@ -178,16 +175,11 @@ def _enabled_profile_kind(profile: BaseProfile, enabled: bool | None = None) ->
def load_menu_profiles(
profiles: dict,
gui_config_file: str | None,
on_error: StatusCallback,
selected_id: int | None = None,
state_change: Mapping[str, Any] | None = None,
gui_config_file: str | None, on_error: StatusCallback,
selected_id: int | None = None, state_change: Mapping[str, Any] | None = None,
) -> dict[str, Any]:
"""Provide one menu-loading action so the page does not separately fetch, order, and classify profiles."""
# profiles = load_profiles(on_error)
profiles = load_profiles(on_error)
state_change = state_change or {}
changed_id = state_change.get("profile_id")
enabled_kinds = {

View file

@ -24,9 +24,3 @@ def edit_profile(profile_id: int, potential_data: dict, ui_caller: Callable):
profile_id=profile_id,
new_choices=potential_data
)
def get_all_profiles(ui_caller: Callable):
take_action(
action=ProfileController.get_all,
ui_caller=ui_caller
)

View file

@ -55,10 +55,7 @@ def read_bwrap_enabled():
def prepare(gui_config_file):
try:
profiles_result = ProfileController.get_all()
if not profiles_result.valid:
print(f"Fetch of all profiles failed: {profiles_result.message}")
profiles = profiles_result.data
profiles = ProfileController.get_all()
except Exception:
profiles = {}
profile_order = normalize_profile_order(gui_config_file, profiles.keys())

1018
gui/v2/ui/pages/editor_page.py Executable file

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,6 @@ from core.infrastructure.global_state_coordinator import evaluate_state_on_start
from core.services.networking.general_connection_tools.disconnect import kill_profile_from_grave
from gui.v2.infrastructure.take_plumbing_action import take_action
from gui.v2.actions.error_handlers import post_state_evaluation
from gui.v2.actions.profile_actions import get_all_profiles
from core.controllers.ProfileController import ProfileController
from core.models.BaseProfile import ProfileType
@ -176,12 +175,6 @@ class MenuPage(Page):
connected = is_connected(profile_id)
p_type = ProfileController.what_type_is_profile(profile_id)
if p_type is None:
error_msg = "Can't create/modify buttons with a blank profile type"
print(error_msg)
self.update_status.update_status(error_msg)
return
# if it's connected, then it can't be edited.
self.boton_edit.setEnabled(not connected)
@ -235,23 +228,11 @@ class MenuPage(Page):
@mainthread
def refresh_menu_buttons(self, state_change=None):
print("refresh_menu_buttons triggered. First, getting all profiles..")
get_all_profiles(ui_caller=self.actually_load_profiles)
def actually_load_profiles(self, result: Result):
if not result.valid:
print("Result is invalid, but core handled the error on it's own.")
return
profiles = result.data
print("Got the data. Loading all menu profiles.")
print("refresh_menu_buttons triggered")
menu_data = load_menu_profiles(
profiles=profiles,
gui_config_file=getattr(self.update_status, 'gui_config_file', None),
on_error=self.update_status.update_status,
selected_id=self.reverse_id,
state_change=None, # legacy variable to be refactored out
getattr(self.update_status, 'gui_config_file', None),
self.update_status.update_status, self.reverse_id, state_change,
)
self.profiles_data = menu_data["display_profiles"]
self.profile_info = self.profiles_data

View file

@ -75,10 +75,7 @@ class ErrorPopup(QDialog):
ok_btn = QPushButton("✓ OK")
ok_btn.setStyleSheet(CORPORATE_PUNK_DYING_ROT)
if self.end_app:
ok_btn.clicked.connect(self._terminate_app)
else:
ok_btn.clicked.connect(self.accept)
ok_btn.clicked.connect(self.accept) # Closes the dialog
main_layout.addWidget(ok_btn)
self.setLayout(main_layout)