diff --git a/gui/v2/actions/error_handlers.py b/gui/v2/actions/error_handlers.py index e056f8a..6ed5105 100644 --- a/gui/v2/actions/error_handlers.py +++ b/gui/v2/actions/error_handlers.py @@ -56,3 +56,8 @@ def navigate_to_singbox_setup() -> Result: return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="networking_setup") + +@register_action(ResultError.NODE_ERROR) +def down_location_edit_page(): + print(f"going to the edit page and boolean_value as true, for the location being down.") + return Result(valid=False, data=True, error_type=ResultError.NAVIGATE_TO, navigate_to="editor") diff --git a/gui/v2/actions/profile_actions.py b/gui/v2/actions/profile_actions.py index 417bef5..b6aa7b8 100644 --- a/gui/v2/actions/profile_actions.py +++ b/gui/v2/actions/profile_actions.py @@ -16,13 +16,14 @@ def create_profile(potential_data: dict, ui_caller: Callable): ) @type_checker -def edit_profile(profile_id: int, potential_data: dict, ui_caller: Callable): +def edit_profile(profile_id: int, location_down: bool, potential_data: dict, ui_caller: Callable): """Pass the data through the plumbing, to edit a profile.""" take_action( action=update_profile, ui_caller=ui_caller, profile_id=profile_id, - new_choices=potential_data + new_choices=potential_data, + server_location_change=location_down ) def get_all_profiles(ui_caller: Callable): diff --git a/gui/v2/infrastructure/navigator.py b/gui/v2/infrastructure/navigator.py index ac5a954..ce7837c 100755 --- a/gui/v2/infrastructure/navigator.py +++ b/gui/v2/infrastructure/navigator.py @@ -49,7 +49,7 @@ class Navigator(QObject): return getattr(module, class_name) - def _instantiate(self, name, prepared=None, profile_id=None): + def _instantiate(self, name, prepared=None, profile_id=None, location_down=None): cls = self.get_class(name) # 1. Inspect the constructor's parameters @@ -70,6 +70,10 @@ class Navigator(QObject): if "prepared" in params: kwargs["prepared"] = prepared + # Only add location_down if the class accepts it + if location_down is not None and "location_down" in params: + kwargs["location_down"] = location_down + # 3. Instantiate using the filtered dictionary return cls(**kwargs) @@ -78,7 +82,7 @@ class Navigator(QObject): self.page_stack.addWidget(page) self._instances[name] = page - def navigate(self, name, profile_id = None): + def navigate(self, name, profile_id = None, location_down = None): page = self._instances.get(name) if page is None: @@ -93,6 +97,10 @@ class Navigator(QObject): logger.info(f"Navigator is setting profile_id data of {profile_id}") page.profile_id = profile_id + if location_down is not None: + logger.info(f"Navigator is setting location_down data of {location_down}") + page.location_down = location_down + # Make it visible: self.page_stack.setCurrentIndex(self.page_stack.indexOf(page)) return page diff --git a/gui/v2/presenters/state/fast_registration_state.py b/gui/v2/presenters/state/fast_registration_state.py index 5d6cbca..1d9dba7 100644 --- a/gui/v2/presenters/state/fast_registration_state.py +++ b/gui/v2/presenters/state/fast_registration_state.py @@ -25,7 +25,7 @@ class PreEdit: class RegistrationState: - def __init__(self, btn_path, profile_id: Optional[int] = None): + def __init__(self, btn_path, profile_id: Optional[int] = None, location_down: Optional[bool] = False): self.btn_path = btn_path self.all_options = {} self.selections = {} @@ -36,6 +36,7 @@ class RegistrationState: self.proceed = False self.warnings_dict = {} self.key_choices = [] + self.location_down = location_down # Maps a category to the function that validates its current selection. self._filter_map = { @@ -341,7 +342,8 @@ class RegistrationState: # 2. Map keys to their specific warning messages WARNING_MESSAGES = { "location": lambda: "If you change the location, it wipes the subscription, proceed?" - if not profile_can_respawn(self.profile_id).valid + if not self.location_down + and not profile_can_respawn(self.profile_id).valid and profile_can_respawn(self.profile_id).error_type != ResultError.SUBSCRIPTION else None, "browser": lambda: "If you change the browser, it wipes the cookies/bookmarks, proceed?" diff --git a/gui/v2/ui/pages/create_edit/edit_page.py b/gui/v2/ui/pages/create_edit/edit_page.py index 514b452..46869a1 100644 --- a/gui/v2/ui/pages/create_edit/edit_page.py +++ b/gui/v2/ui/pages/create_edit/edit_page.py @@ -17,9 +17,10 @@ from typing import Optional class EditPage(Page): - def __init__(self, page_stack, main_window, prepared=None, profile_id: Optional[int] = None): + def __init__(self, page_stack, main_window, prepared=None, profile_id: Optional[int] = None, location_down: Optional[bool] = False): super().__init__("EditPage", page_stack, main_window) self.profile_id = profile_id + self.location_down = location_down # 1. Permanent Structure: Created once in init self.content_area = QWidget() @@ -62,7 +63,7 @@ class EditPage(Page): # 2. State Reset: Wipe old widgets and old state self.clear_ui() - self.state = RegistrationState(btn_path=self.btn_path, profile_id=profile_id) + self.state = RegistrationState(btn_path=self.btn_path, profile_id=profile_id, location_down=self.location_down) print("Created a new RegistrationState") # 3. Create groups, passing the category string and the state object @@ -143,18 +144,19 @@ class EditPage(Page): def proceed_with_edit(self, different_content): - print(f"different_content is {different_content}") + print(f"different_content is {different_content} and self.location_down is {self.location_down}") edit_profile( profile_id=self.profile_id, potential_data=different_content, + location_down=self.location_down, ui_caller=self.after_submission ) self.created_display = False def submit_edits(self): - print("submit_edits") + print(f"submit_edits with self.location as {self.location_down}") # name input_text = self.group_name.text_input.text() if not input_text: diff --git a/gui/v2/ui/pages/menu_page.py b/gui/v2/ui/pages/menu_page.py index 5f717bc..f1459f5 100755 --- a/gui/v2/ui/pages/menu_page.py +++ b/gui/v2/ui/pages/menu_page.py @@ -684,7 +684,13 @@ class MenuPage(Page): def deal_with_errors(self, result: Result): if result.error_type == ResultError.NAVIGATE_TO: print(f"We are auto-navigating to page {result.navigate_to}") - self.custom_window.navigator.navigate(result.navigate_to) + if result.navigate_to == "editor" and result.data: + print("going to editor page with a different location") + profile_id = self.reverse_id + print(f"profile_id is {profile_id}") + self.custom_window.navigator.navigate(name="editor", profile_id=profile_id, location_down=result.data) + else: + self.custom_window.navigator.navigate(name=result.navigate_to) elif result.error_type == ResultError.SUBSCRIPTION: print("We are navigating to the subscription page")