Refactor to allow editing of systemwide protocol choice

This commit is contained in:
SimplifiedPrivacy 2026-10-03 10:49:29 -04:00
parent ac51a01dd9
commit 7d6d03367a

View file

@ -12,12 +12,14 @@ from core.controllers.ProfileController import ProfileController
from core.controllers.LocationController import LocationController
from core.models.Result import Result, ResultError
from core.controllers.profile_state.update_profile import update_profile
from core.models.BaseProfile import ProfileType
from gui.v2.ui.pages.Page import Page
from gui.v2.ui.pages.browser_page import BrowserPage
from gui.v2.ui.pages.location_page import LocationPage
from gui.v2.ui.pages.screen_page import ScreenPage
from gui.v2.ui.popups.confirmation_popup import ConfirmationPopup
from gui.v2.ui.popups.error_popup import ErrorPopup
from gui.v2.workers.page_data_worker import PageDataWorker
from gui.v2.actions.menu_profiles import match_core_profiles
@ -201,46 +203,59 @@ class EditorPage(Page):
self.data_profile[key] = value
self.name.textChanged.connect(self.update_name_value)
self.verificate(self.data_profile, selected_profiles_str)
self.evaluate_option_labels(self.data_profile, selected_profiles_str)
def verificate(self, data_profile, selected_profile_str):
protocol = data_profile.get("protocol", "")
try:
if protocol == "wireguard":
self.process_and_show_labels(data_profile, {
"protocol": ['wireguard', 'residential', 'hidetor'],
"connection": ['browser-only', 'system-wide'],
"location": self.connection_manager.get_location_list(),
"browser": self.connection_manager.get_browser_list(),
"dimentions": self.connection_manager.get_available_resolutions(data_profile.get('id', ''))
}, selected_profile_str)
def evaluate_option_labels(self, data_profile, selected_profile_str):
"""Figure out which data can be changed, so the UI only displays those choices"""
elif protocol in self.SINGBOX_PROTOCOLS:
self.process_and_show_labels(data_profile, {
"protocol": [protocol],
"connection": ['system-wide'],
"location": self.connection_manager.get_location_list(),
}, selected_profile_str)
protocol = data_profile.get("protocol", None)
profile_type = data_profile.get("connection", None)
elif protocol == "residential" or protocol == "hidetor":
self.process_and_show_labels(data_profile, {
"protocol": ['residential', 'wireguard', 'hidetor'],
"connection": ['tor', 'just proxy'],
"location": self.connection_manager.get_location_list(),
"browser": self.connection_manager.get_browser_list(),
"dimentions": self.connection_manager.get_available_resolutions(data_profile.get('id', ''))
}, selected_profile_str)
if not profile_type or not protocol:
error_msg = "You've found a bug, where there is no profile type or protocol field."
print(error_msg)
self.show_a_popup(message=error_msg, title="Missing fields")
return
elif protocol == "open":
self.process_and_show_labels(data_profile, {
"protocol": ['open']
}, selected_profile_str)
except Exception as e:
print(f'An error occurred in verificate: {e}')
if profile_type == "system-wide":
self.process_and_show_labels(data_profile, {
"protocol": ['vless', 'hysteria2', 'wireguard'],
"connection": ['system-wide'],
"location": self.connection_manager.get_location_list(),
}, selected_profile_str)
else:
# Session profiles can't change protocols yet.
self.process_and_show_labels(data_profile, {
"protocol": [protocol],
"connection": ['browser-only', 'system-wide'],
"location": self.connection_manager.get_location_list(),
"browser": self.connection_manager.get_browser_list(),
"dimentions": self.connection_manager.get_available_resolutions(data_profile.get('id', ''))
}, selected_profile_str)
# elif protocol in self.SINGBOX_PROTOCOLS:
# elif protocol == "residential" or protocol == "hidetor":
# self.process_and_show_labels(data_profile, {
# "protocol": ['residential', 'wireguard', 'hidetor'],
# "connection": ['tor', 'just proxy'],
# "location": self.connection_manager.get_location_list(),
# "browser": self.connection_manager.get_browser_list(),
# "dimentions": self.connection_manager.get_available_resolutions(data_profile.get('id', ''))
# }, selected_profile_str)
# elif protocol == "open":
# self.process_and_show_labels(data_profile, {
# "protocol": ['open']
# }, selected_profile_str)
def process_and_show_labels(self, data_profile, parameters, selected_profile_str):
"""Populate the images in the center of the arrows, on the right hand side, with relevant choices"""
protocol = data_profile.get('protocol', "")
connection = data_profile.get('connection', "")
location = data_profile.get('location', "")
@ -568,6 +583,7 @@ class EditorPage(Page):
next_button = QPushButton(self)
next_button.setGeometry(750, 90 + i * 80, 30, 75)
next_button.clicked.connect(
lambda _, k=key, idx=value_index: self.show_next_value(k, idx, parameters))
next_button.show()
@ -611,14 +627,24 @@ class EditorPage(Page):
prev_button.setVisible(True)
next_button.setVisible(True)
if key == 'protocol' or (connection == 'system-wide' and key == 'connection'):
# can't change profile type
if key == 'connection':
prev_button.setDisabled(True)
next_button.setDisabled(True)
# can't change session protocols (yet), because Tor is a different billing system than wireguard/vless/hy,
if connection == 'browser-only' and key == 'protocol':
prev_button.setDisabled(True)
next_button.setDisabled(True)
# disables session profile options for system-profiles, where they are not relevant:
if connection == 'system-wide' and (key == 'browser' or key == 'dimentions'):
prev_button.setVisible(False)
next_button.setVisible(False)
def _protocol_button_asset(self, protocol):
asset_name = self.PROTOCOL_BUTTON_ASSETS.get(protocol, protocol)
return os.path.join(self.btn_path, f"{asset_name}_button.png")
@ -906,6 +932,7 @@ class EditorPage(Page):
self.edit_to_session()
else:
self.show_a_popup(message=result.message, title=str(result.error_type.value))
self.update_status.update_status(result.message)
@ -932,3 +959,17 @@ class EditorPage(Page):
if resume_page:
resume_page.handle_core_action_create_profile(
'CREATE_SESSION_PROFILE', profile_data, 'session')
def show_a_popup(self, message: str, title: str = "Error"):
"""Display a popup with an error"""
error_popup = ErrorPopup(
choice=False,
title=title,
message=message,
end_app = False,
on_answer = None,
passed_result = None,
)
error_popup.show()