Singbox Car profiles directly display pre-made images for editor page. Also edit page now uses threading action module to update

This commit is contained in:
SimplifiedPrivacy 2026-11-07 12:25:51 -05:00
parent 1fe14ff97b
commit 0317d967b5
3 changed files with 77 additions and 40 deletions

View file

@ -1,6 +1,8 @@
# core # core
from core.infrastructure.state_management.global_state_controller import connected_system_profile_id, connected_session_profile_ids, is_connected 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.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.controllers.SessionStateController import SessionStateController
# from core.services.networking.systemwide.systemwide_wireguard import change_port_then_reconnect # from core.services.networking.systemwide.systemwide_wireguard import change_port_then_reconnect
@ -139,7 +141,7 @@ def NOT_need_tor_warnings(profile_id: int) -> Result:
profile = profile_result.data profile = profile_result.data
# Actual Profile is a Tor Profile: # Actual Profile is a Tor Profile:
if profile.connection.code != "tor": if profile.protocol != ProtocolChoice.TOR:
return Result(valid=True) # no warning needed, it's not even Tor return Result(valid=True) # no warning needed, it's not even Tor
# Config shows a non-Tor connection to download apps: # Config shows a non-Tor connection to download apps:
@ -381,5 +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. 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
)
# atexit.register(disconnect_active(ui_caller=finish)) # atexit.register(disconnect_active(ui_caller=finish))

View file

@ -11,7 +11,6 @@ from PyQt6 import QtCore, QtGui
from core.controllers.ProfileController import ProfileController from core.controllers.ProfileController import ProfileController
from core.controllers.LocationController import LocationController from core.controllers.LocationController import LocationController
from core.models.Result import Result, ResultError from core.models.Result import Result, ResultError
from core.controllers.profile_state.update_profile import update_profile
from core.controllers.profile_state.data_filters import get_supported_protocols_for_location from core.controllers.profile_state.data_filters import get_supported_protocols_for_location
from core.models.BaseProfile import ProfileType from core.models.BaseProfile import ProfileType
@ -23,7 +22,7 @@ from gui.v2.ui.popups.confirmation_popup import ConfirmationPopup
from gui.v2.ui.popups.error_popup import ErrorPopup from gui.v2.ui.popups.error_popup import ErrorPopup
from gui.v2.workers.page_data_worker import PageDataWorker from gui.v2.workers.page_data_worker import PageDataWorker
from gui.v2.actions.menu_profiles import match_core_profiles from gui.v2.actions.menu_profiles import match_core_profiles
from gui.v2.actions.menu_coordinator import edit_profile
class EditorPage(Page): class EditorPage(Page):
SINGBOX_PROTOCOLS = ("hysteria2", "vless") SINGBOX_PROTOCOLS = ("hysteria2", "vless")
@ -314,8 +313,12 @@ class EditorPage(Page):
else: else:
self.display.setGeometry(0, 60, 540, 405) self.display.setGeometry(0, 60, 540, 405)
self.display.show() self.display.show()
self.display.setPixmap(self._encrypted_proxy_display_pixmap( # self.display.setPixmap(self._encrypted_proxy_display_pixmap(
protocol, location).scaled( # protocol, location).scaled(
self.display.setPixmap(QPixmap(os.path.join(
self.btn_path, f"{protocol}_{location}.png")).scaled(
self.display.size(), self.display.size(),
Qt.AspectRatioMode.KeepAspectRatio, Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation)) Qt.TransformationMode.SmoothTransformation))
@ -664,39 +667,39 @@ class EditorPage(Page):
asset_name = self.PROTOCOL_BUTTON_ASSETS.get(protocol, protocol) asset_name = self.PROTOCOL_BUTTON_ASSETS.get(protocol, protocol)
return os.path.join(self.btn_path, f"{asset_name}_button.png") return os.path.join(self.btn_path, f"{asset_name}_button.png")
def _encrypted_proxy_display_pixmap(self, protocol, location): # def _encrypted_proxy_display_pixmap(self, protocol, location):
pixmap = QPixmap(os.path.join(self.btn_path, f"{protocol}.png")) # pixmap = QPixmap(os.path.join(self.btn_path, f"{protocol}.png"))
if pixmap.isNull(): # if pixmap.isNull():
pixmap = QPixmap(os.path.join(self.btn_path, "system_wide_global.png")) # pixmap = QPixmap(os.path.join(self.btn_path, "system_wide_global.png"))
if pixmap.isNull(): # if pixmap.isNull():
return pixmap # return pixmap
location_pixmap = QPixmap(os.path.join( # location_pixmap = QPixmap(os.path.join(
self.btn_path, f"icon_mini_{location}.png")) # self.btn_path, f"icon_mini_{location}.png"))
if location_pixmap.isNull(): # if location_pixmap.isNull():
location_pixmap = QPixmap(os.path.join( # location_pixmap = QPixmap(os.path.join(
self.btn_path, "default_location_mini.png")) # self.btn_path, "default_location_mini.png"))
if location_pixmap.isNull(): # if location_pixmap.isNull():
return pixmap # return pixmap
icon_size = max(42, min(72, int(min(pixmap.width(), pixmap.height()) * 0.22))) # icon_size = max(42, min(72, int(min(pixmap.width(), pixmap.height()) * 0.22)))
location_pixmap = location_pixmap.scaled( # location_pixmap = location_pixmap.scaled(
icon_size, # icon_size,
icon_size, # icon_size,
Qt.AspectRatioMode.KeepAspectRatio, # Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation) # Qt.TransformationMode.SmoothTransformation)
x = int(pixmap.width() * 0.58) # x = int(pixmap.width() * 0.58)
if protocol == 'hysteria2': # if protocol == 'hysteria2':
y = int(pixmap.height() * 0.35) # y = int(pixmap.height() * 0.35)
else: # else:
y = int(pixmap.height() * 0.30) # y = int(pixmap.height() * 0.30)
x = min(max(0, x), max(0, pixmap.width() - location_pixmap.width())) # x = min(max(0, x), max(0, pixmap.width() - location_pixmap.width()))
y = min(max(0, y), max(0, pixmap.height() - location_pixmap.height())) # y = min(max(0, y), max(0, pixmap.height() - location_pixmap.height()))
painter = QPainter(pixmap) # painter = QPainter(pixmap)
painter.drawPixmap(x, y, location_pixmap) # painter.drawPixmap(x, y, location_pixmap)
painter.end() # painter.end()
return pixmap # return pixmap
def on_sync_complete_for_edit_profile(self, available_locations, available_browsers, status, is_tor, locations, all_browsers): def on_sync_complete_for_edit_profile(self, available_locations, available_browsers, status, is_tor, locations, all_browsers):
if status: if status:
@ -931,16 +934,24 @@ class EditorPage(Page):
self._prefetched_profiles = None self._prefetched_profiles = None
def update_core_profiles(self, key, new_value): def update_core_profiles(self, key, new_value):
"""Send to action module to update the profile data"""
profile_id = int(self.update_status.current_profile_id) profile_id = int(self.update_status.current_profile_id)
self.which_key_changed = key
# Sends to core directly, edit_profile(
result = update_profile(profile_id, key, new_value) profile_id=profile_id,
key=key,
new_value=new_value,
ui_caller=self.recieve_edit_result
)
def recieve_edit_result(self, result: Result):
"""After edit is complete, display the result."""
if result.valid: if result.valid:
self.update_status.update_status( self.update_status.update_status(
f'Updated profile {profile_id}') f'Updated profile')
if key == "resolution": if self.which_key_changed == "resolution":
self.update_res = True self.update_res = True
if result.data == "edit_to_session": if result.data == "edit_to_session":

View file

@ -224,7 +224,17 @@ class ResumePage(Page):
if location_info and hasattr(location_info, 'operator') and location_info.operator: if location_info and hasattr(location_info, 'operator') and location_info.operator:
operator_name = location_info.operator.name or "" operator_name = location_info.operator.name or ""
if operator_name != 'Simplified Privacy' and operator_name != "": # if operator_name != 'Simplified Privacy' and operator_name != "":
if profile_1.get('protocol') in self.SINGBOX_PROTOCOLS:
image_path = os.path.join(
self.btn_path, f"{profile_1['protocol']}_{location_text}.png")
main_label = QLabel(self)
main_label.setGeometry(10, 130, 500, 375)
main_label.setPixmap(QPixmap(image_path))
main_label.setScaledContents(True)
main_label.show()
self.labels_creados.append(main_label)
elif operator_name != 'Simplified Privacy' and operator_name != "":
text_color = "white" text_color = "white"
if self.connection_type != "system-wide": if self.connection_type != "system-wide":
text_color = "black" text_color = "black"