forked from Support/sp-hydra-veil-gui
Compare commits
2 commits
a6c31375b0
...
a0b39365a3
| Author | SHA1 | Date | |
|---|---|---|---|
| a0b39365a3 | |||
| 72f9f0b97d |
8 changed files with 70 additions and 1055 deletions
|
|
@ -21,16 +21,6 @@ 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."""
|
||||
|
|
@ -64,3 +54,5 @@ def navigate_to_singbox_setup() -> Result:
|
|||
connection_observer=connection_observer
|
||||
)
|
||||
return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="networking_setup")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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,9 +37,11 @@ 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):
|
||||
|
|
@ -314,7 +316,7 @@ def disconnect_many_profiles(profile_ids: list) -> Result:
|
|||
return Result(valid=False, data=failed_list)
|
||||
|
||||
|
||||
def disconnect_active(ui_caller: Callable) -> Result:
|
||||
def disconnect_active(ui_caller: Optional[Callable] = None) -> Result:
|
||||
"""Disconnects active session profiles first, then system."""
|
||||
|
||||
# SESSION
|
||||
|
|
@ -342,8 +344,10 @@ def disconnect_active(ui_caller: Callable) -> Result:
|
|||
system_disconnected.message = error_msg
|
||||
return system_disconnected
|
||||
|
||||
ui_caller(Result(valid=True))
|
||||
|
||||
if ui_caller:
|
||||
ui_caller(Result(valid=True))
|
||||
else:
|
||||
return Result(valid=True)
|
||||
|
||||
def sync_now(ui_caller: Callable):
|
||||
take_action(
|
||||
|
|
@ -383,19 +387,17 @@ 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.
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
@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()
|
||||
|
||||
|
||||
|
||||
# atexit.register(disconnect_active(ui_caller=finish))
|
||||
|
|
|
|||
|
|
@ -44,7 +44,10 @@ 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:
|
||||
return ProfileController.get_all()
|
||||
profile_result = ProfileController.get_all()
|
||||
if not profile_result.valid:
|
||||
return profile_result
|
||||
|
||||
except Exception as error:
|
||||
_report_load_error(
|
||||
error,
|
||||
|
|
@ -175,11 +178,16 @@ def _enabled_profile_kind(profile: BaseProfile, enabled: bool | None = None) ->
|
|||
|
||||
|
||||
def load_menu_profiles(
|
||||
gui_config_file: str | None, on_error: StatusCallback,
|
||||
selected_id: int | None = None, state_change: Mapping[str, Any] | None = None,
|
||||
profiles: dict,
|
||||
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 = {
|
||||
|
|
|
|||
|
|
@ -24,3 +24,9 @@ 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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -55,7 +55,10 @@ def read_bwrap_enabled():
|
|||
|
||||
def prepare(gui_config_file):
|
||||
try:
|
||||
profiles = ProfileController.get_all()
|
||||
profiles_result = ProfileController.get_all()
|
||||
if not profiles_result.valid:
|
||||
print(f"Fetch of all profiles failed: {profiles_result.message}")
|
||||
profiles = profiles_result.data
|
||||
except Exception:
|
||||
profiles = {}
|
||||
profile_order = normalize_profile_order(gui_config_file, profiles.keys())
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -3,6 +3,7 @@ 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
|
||||
|
|
@ -175,6 +176,12 @@ 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)
|
||||
|
||||
|
|
@ -228,11 +235,23 @@ class MenuPage(Page):
|
|||
@mainthread
|
||||
def refresh_menu_buttons(self, state_change=None):
|
||||
|
||||
print("refresh_menu_buttons triggered")
|
||||
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.")
|
||||
|
||||
menu_data = load_menu_profiles(
|
||||
getattr(self.update_status, 'gui_config_file', None),
|
||||
self.update_status.update_status, self.reverse_id, state_change,
|
||||
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
|
||||
)
|
||||
self.profiles_data = menu_data["display_profiles"]
|
||||
self.profile_info = self.profiles_data
|
||||
|
|
|
|||
|
|
@ -75,7 +75,10 @@ class ErrorPopup(QDialog):
|
|||
ok_btn = QPushButton("✓ OK")
|
||||
ok_btn.setStyleSheet(CORPORATE_PUNK_DYING_ROT)
|
||||
|
||||
ok_btn.clicked.connect(self.accept) # Closes the dialog
|
||||
if self.end_app:
|
||||
ok_btn.clicked.connect(self._terminate_app)
|
||||
else:
|
||||
ok_btn.clicked.connect(self.accept)
|
||||
main_layout.addWidget(ok_btn)
|
||||
|
||||
self.setLayout(main_layout)
|
||||
|
|
|
|||
Loading…
Reference in a new issue