forked from Support/sp-hydra-veil-gui
Sync goes through menu_coordinator
This commit is contained in:
parent
4157d462cf
commit
798821cf2a
11 changed files with 241 additions and 109 deletions
|
|
@ -31,6 +31,10 @@ core_logger.propagate = False
|
||||||
from gui.v2.infrastructure.ThreadSafetyTool import ThreadSafetyTool
|
from gui.v2.infrastructure.ThreadSafetyTool import ThreadSafetyTool
|
||||||
mainthread = ThreadSafetyTool()
|
mainthread = ThreadSafetyTool()
|
||||||
|
|
||||||
|
# Sync:
|
||||||
|
from gui.v2.actions.menu_coordinator import sync_now
|
||||||
|
from gui.v2.actions.sync import generate_grid_positions
|
||||||
|
|
||||||
from gui.v2.infrastructure import orm
|
from gui.v2.infrastructure import orm
|
||||||
from gui.v2.infrastructure.navigator import Navigator
|
from gui.v2.infrastructure.navigator import Navigator
|
||||||
from gui.v2.infrastructure.setup_observers import setup_observers
|
from gui.v2.infrastructure.setup_observers import setup_observers
|
||||||
|
|
@ -257,12 +261,13 @@ class CustomWindow(QMainWindow):
|
||||||
"menu", lambda p: p.on_update_check_finished())
|
"menu", lambda p: p.on_update_check_finished())
|
||||||
|
|
||||||
def update_values(self, available_locations, available_browsers, status, is_tor, locations, all_browsers):
|
def update_values(self, available_locations, available_browsers, status, is_tor, locations, all_browsers):
|
||||||
|
|
||||||
if not status:
|
if not status:
|
||||||
self.update_status('Sync failed. Please try again later.')
|
self.update_status('Sync failed. Please try again later.')
|
||||||
return
|
return
|
||||||
|
|
||||||
from PyQt6.QtWidgets import QPushButton
|
self.perform_update_check()
|
||||||
from gui.v2.actions.sync import generate_grid_positions
|
|
||||||
|
|
||||||
self.connection_manager.set_synced(True)
|
self.connection_manager.set_synced(True)
|
||||||
self.connection_manager.store_locations(locations)
|
self.connection_manager.store_locations(locations)
|
||||||
|
|
@ -289,6 +294,7 @@ class CustomWindow(QMainWindow):
|
||||||
"protocol", lambda p: p.enable_protocol_buttons())
|
"protocol", lambda p: p.enable_protocol_buttons())
|
||||||
self.navigator.update_if_cached("menu", self._enable_menu_verification_icons)
|
self.navigator.update_if_cached("menu", self._enable_menu_verification_icons)
|
||||||
|
|
||||||
|
|
||||||
def _enable_menu_verification_icons(self, menu_page):
|
def _enable_menu_verification_icons(self, menu_page):
|
||||||
if hasattr(menu_page, 'refresh_profiles_data'):
|
if hasattr(menu_page, 'refresh_profiles_data'):
|
||||||
menu_page.refresh_profiles_data()
|
menu_page.refresh_profiles_data()
|
||||||
|
|
@ -301,18 +307,33 @@ class CustomWindow(QMainWindow):
|
||||||
if icon.geometry().width() == 20 and icon.geometry().height() == 20:
|
if icon.geometry().width() == 20 and icon.geometry().height() == 20:
|
||||||
icon.setEnabled(True)
|
icon.setEnabled(True)
|
||||||
|
|
||||||
|
|
||||||
|
@mainthread
|
||||||
|
def post_sync(self, result: Result):
|
||||||
|
core_logger.info("Sync coming back to the mainthread UI.")
|
||||||
|
|
||||||
|
if not result.valid:
|
||||||
|
self.update_status('Sync failed. Please try again later.')
|
||||||
|
return
|
||||||
|
|
||||||
|
self.perform_update_check()
|
||||||
|
|
||||||
|
|
||||||
def sync(self):
|
def sync(self):
|
||||||
core_logger.info("User clicked sync button")
|
core_logger.info("User clicked sync button")
|
||||||
if ConfigurationController.get_connection() == 'tor':
|
sync_now(ui_caller=self.post_sync)
|
||||||
self.worker_thread = WorkerThread('SYNC_TOR')
|
|
||||||
else:
|
|
||||||
self.worker_thread = WorkerThread('SYNC')
|
# if ConfigurationController.get_connection() == 'tor':
|
||||||
self.sync_button.setIcon(QtGui.QIcon(
|
# self.worker_thread = WorkerThread('SYNC_TOR')
|
||||||
os.path.join(self.btn_path, 'icon_sync.png')))
|
# else:
|
||||||
self.worker_thread.finished.connect(
|
# self.worker_thread = WorkerThread('SYNC')
|
||||||
lambda: self.perform_update_check())
|
# self.sync_button.setIcon(QtGui.QIcon(
|
||||||
self.worker_thread.sync_output.connect(self.update_values)
|
# os.path.join(self.btn_path, 'icon_sync.png')))
|
||||||
self.worker_thread.start()
|
# self.worker_thread.finished.connect(
|
||||||
|
# lambda: self.perform_update_check())
|
||||||
|
# self.worker_thread.sync_output.connect(self.update_values)
|
||||||
|
# self.worker_thread.start()
|
||||||
|
|
||||||
def _handle_exception(self, identifier, message, trace):
|
def _handle_exception(self, identifier, message, trace):
|
||||||
if issubclass(identifier, UnknownConnectionTypeError):
|
if issubclass(identifier, UnknownConnectionTypeError):
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 1 MiB After Width: | Height: | Size: 1 MiB |
|
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
|
|
@ -1,18 +1,38 @@
|
||||||
from gui.v2.infrastructure.action_registry import register_action
|
from gui.v2.infrastructure.action_registry import register_action
|
||||||
from core.infrastructure.global_state_coordinator import coordinate_evaluation
|
from core.infrastructure.global_state_coordinator import coordinate_evaluation
|
||||||
from core.models.Result import Result, ResultError
|
from core.models.Result import Result, ResultError
|
||||||
|
from core.errors.logger import logger
|
||||||
|
|
||||||
from gui.v2.infrastructure.setup_observers import connection_observer
|
from gui.v2.infrastructure.setup_observers import connection_observer
|
||||||
|
|
||||||
def empty_filler(result: Result) -> Result:
|
from gui.v2.infrastructure.ThreadSafetyTool import ThreadSafetyTool
|
||||||
"""To have a callback, even when one is not required."""
|
mainthread = ThreadSafetyTool()
|
||||||
return result
|
from gui.v2.infrastructure.take_plumbing_action import take_action
|
||||||
|
|
||||||
|
@mainthread
|
||||||
|
def post_state_evaluation(result: Result):
|
||||||
|
"""Success path for initial state evaluation"""
|
||||||
|
print("Initial State evaluation complete.")
|
||||||
|
|
||||||
|
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_CONNECTION)
|
@mainthread
|
||||||
def evaluate_bad_state() -> Result:
|
@register_action(ResultError.ZOMBIE_SYSTEM)
|
||||||
|
def evaluate_bad_state():
|
||||||
"""Start core's evaluation of state with a GUI observer."""
|
"""Start core's evaluation of state with a GUI observer."""
|
||||||
return coordinate_evaluation(connection_observer=connection_observer)
|
# return coordinate_evaluation(connection_observer=connection_observer)
|
||||||
|
take_action(
|
||||||
|
action=coordinate_evaluation,
|
||||||
|
ui_caller=post_state_evaluation,
|
||||||
|
connection_observer=connection_observer
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@register_action(ResultError.SUBSCRIPTION)
|
@register_action(ResultError.SUBSCRIPTION)
|
||||||
def navigate_to_new_sub_page() -> Result:
|
def navigate_to_new_sub_page() -> Result:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# core
|
# core
|
||||||
from core.infrastructure.global_state_coordinator import connected_system_profile_id, connected_session_profile_ids
|
from core.infrastructure.global_state_coordinator import connected_system_profile_id, connected_session_profile_ids
|
||||||
|
|
||||||
|
|
||||||
# from core.services.networking.systemwide.systemwide_wireguard import change_port_then_reconnect
|
# from core.services.networking.systemwide.systemwide_wireguard import change_port_then_reconnect
|
||||||
# from core.services.networking.ports.port_orchestrator import change_wg_port
|
# from core.services.networking.ports.port_orchestrator import change_wg_port
|
||||||
from core.controllers.ConfigurationController import ConfigurationController
|
from core.controllers.ConfigurationController import ConfigurationController
|
||||||
|
|
@ -18,6 +19,7 @@ from core.models.Result import Result, ResultError
|
||||||
from core.errors.logger import logger
|
from core.errors.logger import logger
|
||||||
from core.errors.translate_error import translate_error, get_ignored_exceptions
|
from core.errors.translate_error import translate_error, get_ignored_exceptions
|
||||||
from core.services.payment_phase.payment_state import OverallPaymentCycle
|
from core.services.payment_phase.payment_state import OverallPaymentCycle
|
||||||
|
from core.controllers.SyncController import new_sync
|
||||||
|
|
||||||
# gui
|
# gui
|
||||||
# from gui.v2.actions.payment_actions import wipe_expired_subscription
|
# from gui.v2.actions.payment_actions import wipe_expired_subscription
|
||||||
|
|
@ -27,7 +29,7 @@ from gui.v2.infrastructure.take_plumbing_action import take_action
|
||||||
from gui.v2.infrastructure.screen_size import get_max_screensize
|
from gui.v2.infrastructure.screen_size import get_max_screensize
|
||||||
from gui.v2.infrastructure.setup_observers import (
|
from gui.v2.infrastructure.setup_observers import (
|
||||||
application_version_observer, connection_observer,
|
application_version_observer, connection_observer,
|
||||||
profile_observer, ticket_observer,
|
profile_observer, ticket_observer, client_observer
|
||||||
)
|
)
|
||||||
from gui.v2.actions.error_handlers import navigate_to_new_sub_page
|
from gui.v2.actions.error_handlers import navigate_to_new_sub_page
|
||||||
|
|
||||||
|
|
@ -156,7 +158,7 @@ def NOT_need_tor_warnings(profile_id: int) -> Result:
|
||||||
@register_action(ResultError.RECONNECT)
|
@register_action(ResultError.RECONNECT)
|
||||||
def literally_connect(profile_id: int) -> Result:
|
def literally_connect(profile_id: int) -> Result:
|
||||||
|
|
||||||
print("Literally Connecting...")
|
print(f"Literally Connecting profile {profile_id}...")
|
||||||
|
|
||||||
# Step 1: Get the Profile
|
# Step 1: Get the Profile
|
||||||
profile_result = get_profile(profile_id)
|
profile_result = get_profile(profile_id)
|
||||||
|
|
@ -175,6 +177,7 @@ def literally_connect(profile_id: int) -> Result:
|
||||||
final_result = enable_profile(
|
final_result = enable_profile(
|
||||||
profile=profile,
|
profile=profile,
|
||||||
ignore=ignored,
|
ignore=ignored,
|
||||||
|
asynchronous=False,
|
||||||
profile_observer=profile_observer,
|
profile_observer=profile_observer,
|
||||||
application_version_observer=application_version_observer,
|
application_version_observer=application_version_observer,
|
||||||
connection_observer=connection_observer,
|
connection_observer=connection_observer,
|
||||||
|
|
@ -336,8 +339,10 @@ def disconnect_active(ui_caller: Callable) -> Result:
|
||||||
ui_caller(Result(valid=True))
|
ui_caller(Result(valid=True))
|
||||||
|
|
||||||
|
|
||||||
# def disconnect_active(ui_caller: Callable):
|
def sync_now(ui_caller: Callable):
|
||||||
# take_action(
|
take_action(
|
||||||
# action=disconnect_active_profiles,
|
action=new_sync,
|
||||||
# ui_caller=ui_caller
|
ui_caller=ui_caller,
|
||||||
# )
|
client_observer=client_observer,
|
||||||
|
connection_observer=connection_observer
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -297,6 +297,15 @@ def verification_values(profile: BaseProfile | None) -> list[tuple[str, str]]:
|
||||||
|
|
||||||
def menu_icon_path(btn_path: str, label_name: str, value: Mapping[str, Any], connection_type: str) -> str:
|
def menu_icon_path(btn_path: str, label_name: str, value: Mapping[str, Any], connection_type: str) -> str:
|
||||||
"""Choose menu asset paths outside Qt so protocol mapping remains declarative and reusable."""
|
"""Choose menu asset paths outside Qt so protocol mapping remains declarative and reusable."""
|
||||||
|
|
||||||
|
# print(f"menu_icon_path btn_path is {btn_path}")
|
||||||
|
print(f"menu_icon_path label_name is {label_name}")
|
||||||
|
print(f"menu_icon_path value is {value}")
|
||||||
|
|
||||||
|
# if label_name == "location":
|
||||||
|
# print(f"converting location ({label_name}) to lowercase for {value[label_name]}")
|
||||||
|
# value[label_name] = value[label_name].lower()
|
||||||
|
|
||||||
protocol = str(value.get("protocol", ""))
|
protocol = str(value.get("protocol", ""))
|
||||||
protocol_icons = {
|
protocol_icons = {
|
||||||
"hysteria2": "hysteria2_mini.png",
|
"hysteria2": "hysteria2_mini.png",
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,10 @@ def random_ticket_dispatch(profile_id: int, passed_ui_caller: Callable) -> Resul
|
||||||
random_ticket_result = get_a_random_ticket()
|
random_ticket_result = get_a_random_ticket()
|
||||||
|
|
||||||
if not random_ticket_result.valid:
|
if not random_ticket_result.valid:
|
||||||
return random_ticket_result
|
return random_ticket_result.wrap("User wanted a random ticket, but there aren't any, or fetch failed.")
|
||||||
|
|
||||||
which_ticket = random_ticket_result.data
|
which_ticket = random_ticket_result.data
|
||||||
|
print(f"Using randomly selected ticket {which_ticket}")
|
||||||
|
|
||||||
# this is a redundant sanity check:
|
# this is a redundant sanity check:
|
||||||
if not which_ticket:
|
if not which_ticket:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from core.infrastructure.global_state_coordinator import connected_session_profile_ids, verified_system_profile_id, is_systemwide_on, is_connected, evaluate_state_on_startup
|
from core.infrastructure.global_state_coordinator import connected_session_profile_ids, verified_system_profile_id, is_systemwide_on, is_connected, evaluate_state_on_startup
|
||||||
from gui.v2.infrastructure.take_plumbing_action import take_action
|
from gui.v2.infrastructure.take_plumbing_action import take_action
|
||||||
from gui.v2.actions.error_handlers import empty_filler
|
from gui.v2.actions.error_handlers import post_state_evaluation
|
||||||
from core.controllers.ProfileController import ProfileController
|
from core.controllers.ProfileController import ProfileController
|
||||||
from core.models.BaseProfile import ProfileType
|
from core.models.BaseProfile import ProfileType
|
||||||
from core.models.Result import Result, ResultError
|
from core.models.Result import Result, ResultError
|
||||||
|
|
@ -344,6 +344,32 @@ class MenuPage(Page):
|
||||||
child_label.setPixmap(self._add_browser_warning(pixmap, icon["warning"]))
|
child_label.setPixmap(self._add_browser_warning(pixmap, icon["warning"]))
|
||||||
child_label.show()
|
child_label.show()
|
||||||
|
|
||||||
|
|
||||||
|
# def _load_profile_icon_pixmap(self, image_path, label_name):
|
||||||
|
# pixmap = QPixmap(image_path)
|
||||||
|
# fallback_names = {
|
||||||
|
# 'location': 'default_location_mini.png',
|
||||||
|
# 'browser': 'default_browser_mini.png',
|
||||||
|
# }
|
||||||
|
# fallback_name = fallback_names.get(label_name)
|
||||||
|
|
||||||
|
# if pixmap.isNull() and fallback_name:
|
||||||
|
# pixmap = QPixmap(os.path.join(self.btn_path, fallback_name))
|
||||||
|
|
||||||
|
# if not pixmap.isNull():
|
||||||
|
# # Scaled to optimize memory and ensure high quality
|
||||||
|
# return pixmap.scaled(
|
||||||
|
# 50, 50,
|
||||||
|
# Qt.AspectRatioMode.KeepAspectRatio,
|
||||||
|
# Qt.TransformationMode.SmoothTransformation
|
||||||
|
# )
|
||||||
|
|
||||||
|
# # Placeholder is already 50x50, so no scaling needed
|
||||||
|
# placeholder = QPixmap(50, 50)
|
||||||
|
# placeholder.fill(QtGui.QColor(200, 200, 200))
|
||||||
|
# return placeholder
|
||||||
|
|
||||||
|
|
||||||
def _load_profile_icon_pixmap(self, image_path, label_name):
|
def _load_profile_icon_pixmap(self, image_path, label_name):
|
||||||
pixmap = QPixmap(image_path)
|
pixmap = QPixmap(image_path)
|
||||||
fallback_names = {
|
fallback_names = {
|
||||||
|
|
@ -464,7 +490,7 @@ class MenuPage(Page):
|
||||||
|
|
||||||
def _render_profile_details(self, details):
|
def _render_profile_details(self, details):
|
||||||
|
|
||||||
print(f"details entering _render_profile_details is {details}")
|
# print(f"details entering _render_profile_details is {details}")
|
||||||
|
|
||||||
self.reverse_id = details["id"]
|
self.reverse_id = details["id"]
|
||||||
|
|
||||||
|
|
@ -538,6 +564,11 @@ class MenuPage(Page):
|
||||||
if pixmap.isNull():
|
if pixmap.isNull():
|
||||||
return pixmap
|
return pixmap
|
||||||
|
|
||||||
|
print(f"location code for mini is {location}")
|
||||||
|
|
||||||
|
import time
|
||||||
|
time.sleep(20)
|
||||||
|
|
||||||
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():
|
||||||
|
|
@ -592,7 +623,7 @@ class MenuPage(Page):
|
||||||
|
|
||||||
def post_disconnect(self, result: Result):
|
def post_disconnect(self, result: Result):
|
||||||
"""Recieve the callback after disconnection"""
|
"""Recieve the callback after disconnection"""
|
||||||
print(f"result is {result}")
|
# print(f"result is {result}")
|
||||||
|
|
||||||
# --------------------
|
# --------------------
|
||||||
# BOTTOM LEFT STATUS BAR
|
# BOTTOM LEFT STATUS BAR
|
||||||
|
|
@ -658,10 +689,15 @@ class MenuPage(Page):
|
||||||
self.update_status.update_status(immediate_error.message)
|
self.update_status.update_status(immediate_error.message)
|
||||||
return
|
return
|
||||||
|
|
||||||
def disconnect(self):
|
@mainthread
|
||||||
|
def disconnect(self, profile_id: Optional[int] = None):
|
||||||
self.update_status.update_status("Disconnecting...")
|
self.update_status.update_status("Disconnecting...")
|
||||||
print(f"Disconnecting profile {self.reverse_id}")
|
|
||||||
result = disconnect_profile(profile_id=self.reverse_id, ui_caller=self.post_disconnect)
|
if not profile_id:
|
||||||
|
profile_id = self.reverse_id
|
||||||
|
|
||||||
|
print(f"Disconnecting profile {profile_id}")
|
||||||
|
result = disconnect_profile(profile_id=profile_id, ui_caller=self.post_disconnect)
|
||||||
print("Disconnected")
|
print("Disconnected")
|
||||||
|
|
||||||
# self._set_task_busy(True)
|
# self._set_task_busy(True)
|
||||||
|
|
@ -712,7 +748,7 @@ class MenuPage(Page):
|
||||||
@pyqtSlot(object)
|
@pyqtSlot(object)
|
||||||
def handle_task_result(self, result: MenuResult):
|
def handle_task_result(self, result: MenuResult):
|
||||||
|
|
||||||
print(f"result in handle_task_result is {result}")
|
# print(f"result in handle_task_result is {result}")
|
||||||
|
|
||||||
if "sync_data" in result:
|
if "sync_data" in result:
|
||||||
self.update_status.update_values(*result["sync_data"])
|
self.update_status.update_values(*result["sync_data"])
|
||||||
|
|
@ -854,6 +890,7 @@ class MenuPage(Page):
|
||||||
def observers_subscribe(self):
|
def observers_subscribe(self):
|
||||||
Notifications.subscribe(EventType.SESSION_PROFILE_ENABLE, self.turn_on_session_visuals)
|
Notifications.subscribe(EventType.SESSION_PROFILE_ENABLE, self.turn_on_session_visuals)
|
||||||
Notifications.subscribe(EventType.SESSION_PROFILE_DISABLE, self.turn_off_session_visuals)
|
Notifications.subscribe(EventType.SESSION_PROFILE_DISABLE, self.turn_off_session_visuals)
|
||||||
|
Notifications.subscribe(EventType.SESSION_PROFILE_KILL, self.disconnect)
|
||||||
Notifications.subscribe(EventType.SYSTEM_ENABLE, self.turn_on_system_visuals)
|
Notifications.subscribe(EventType.SYSTEM_ENABLE, self.turn_on_system_visuals)
|
||||||
Notifications.subscribe(EventType.SYSTEM_DISABLE, self.turn_off_system_visuals)
|
Notifications.subscribe(EventType.SYSTEM_DISABLE, self.turn_off_system_visuals)
|
||||||
Notifications.subscribe(EventType.RESUME_ACTIONS, self.trigger_action_button_visuals)
|
Notifications.subscribe(EventType.RESUME_ACTIONS, self.trigger_action_button_visuals)
|
||||||
|
|
@ -861,7 +898,7 @@ class MenuPage(Page):
|
||||||
|
|
||||||
take_action(
|
take_action(
|
||||||
action=evaluate_state_on_startup,
|
action=evaluate_state_on_startup,
|
||||||
ui_caller=empty_filler # do nothing on success.
|
ui_caller=post_state_evaluation
|
||||||
)
|
)
|
||||||
|
|
||||||
def state_refresh(self):
|
def state_refresh(self):
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ from gui.v2.ui.styles.styles import (
|
||||||
checkbox_style,
|
checkbox_style,
|
||||||
combobox_style,
|
combobox_style,
|
||||||
)
|
)
|
||||||
|
from gui.v2.ui.styles.css.settings_styles import TICKET_SETTING_STYLE_A, setting_style_b, setting_evaluate_style_c, setting_evaluate_style_d
|
||||||
|
|
||||||
from gui.v2.ui.widgets.clickable_label import ClickableValueLabel
|
from gui.v2.ui.widgets.clickable_label import ClickableValueLabel
|
||||||
from gui.v2.ui.widgets.terminal_widget import TerminalWidget
|
from gui.v2.ui.widgets.terminal_widget import TerminalWidget
|
||||||
from gui.v2.workers.page_data_worker import PageDataWorker
|
from gui.v2.workers.page_data_worker import PageDataWorker
|
||||||
|
|
@ -1483,18 +1485,25 @@ class Settings(Page):
|
||||||
core_logger.info("User navigated to Settings -> Tickets")
|
core_logger.info("User navigated to Settings -> Tickets")
|
||||||
self.content_layout.setCurrentWidget(self.tickets_page)
|
self.content_layout.setCurrentWidget(self.tickets_page)
|
||||||
self._select_menu_button("Tickets")
|
self._select_menu_button("Tickets")
|
||||||
self._load_random_tickets_state()
|
|
||||||
self._refresh_tickets_inventory()
|
if ConfigurationController.are_tickets_setup():
|
||||||
self._refresh_ticket_recovery_controls()
|
self._load_random_tickets_state()
|
||||||
|
self._refresh_tickets_inventory()
|
||||||
|
else:
|
||||||
|
self._refresh_ticket_recovery_controls()
|
||||||
|
|
||||||
def _load_random_tickets_state(self):
|
def _load_random_tickets_state(self):
|
||||||
if getattr(self, '_random_tickets_state_loaded', False):
|
if getattr(self, '_random_tickets_state_loaded', False):
|
||||||
return
|
return
|
||||||
try:
|
# try:
|
||||||
which_ticket, error_msg = do_we_use_a_random_ticket(ticket_observer)
|
# which_ticket, error_msg = do_we_use_a_random_ticket(ticket_observer)
|
||||||
checked = which_ticket is not None and which_ticket != 'error'
|
# checked = which_ticket is not None and which_ticket != 'error'
|
||||||
except Exception:
|
# except Exception:
|
||||||
checked = False
|
# checked = False
|
||||||
|
|
||||||
|
checked = ConfigurationController.use_random()
|
||||||
|
print(f"in settings, do we use a random ticket? {checked}")
|
||||||
|
|
||||||
self.random_tickets_checkbox.blockSignals(True)
|
self.random_tickets_checkbox.blockSignals(True)
|
||||||
self.random_tickets_checkbox.setChecked(checked)
|
self.random_tickets_checkbox.setChecked(checked)
|
||||||
self.random_tickets_checkbox.blockSignals(False)
|
self.random_tickets_checkbox.blockSignals(False)
|
||||||
|
|
@ -1557,7 +1566,12 @@ class Settings(Page):
|
||||||
page_layout.setSpacing(15)
|
page_layout.setSpacing(15)
|
||||||
page_layout.setContentsMargins(20, 20, 20, 20)
|
page_layout.setContentsMargins(20, 20, 20, 20)
|
||||||
|
|
||||||
title = QLabel("TICKETS")
|
if ConfigurationController.are_tickets_setup():
|
||||||
|
title = QLabel("TICKETS")
|
||||||
|
else:
|
||||||
|
title = QLabel("TICKETS NOT SETUP YET")
|
||||||
|
|
||||||
|
|
||||||
title.setStyleSheet(
|
title.setStyleSheet(
|
||||||
f"color: #808080; font-size: 12px; font-weight: bold; {self.font_style}")
|
f"color: #808080; font-size: 12px; font-weight: bold; {self.font_style}")
|
||||||
page_layout.addWidget(title)
|
page_layout.addWidget(title)
|
||||||
|
|
@ -1566,57 +1580,46 @@ class Settings(Page):
|
||||||
scroll_area.setWidgetResizable(True)
|
scroll_area.setWidgetResizable(True)
|
||||||
scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||||
scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
||||||
scroll_area.setStyleSheet("""
|
scroll_area.setStyleSheet(TICKET_SETTING_STYLE_A)
|
||||||
QScrollArea {
|
|
||||||
background-color: transparent;
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
QScrollArea > QWidget > QWidget {
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
|
|
||||||
scroll_content = QWidget()
|
scroll_content = QWidget()
|
||||||
layout = QVBoxLayout(scroll_content)
|
layout = QVBoxLayout(scroll_content)
|
||||||
layout.setSpacing(15)
|
layout.setSpacing(15)
|
||||||
layout.setContentsMargins(0, 0, 8, 0)
|
layout.setContentsMargins(0, 0, 8, 0)
|
||||||
|
|
||||||
random_group = QGroupBox("Random Ticket Use")
|
|
||||||
random_group.setStyleSheet(
|
|
||||||
f"QGroupBox {{ color: white; padding: 15px; {self.font_style} }}")
|
|
||||||
random_layout = QVBoxLayout(random_group)
|
|
||||||
|
|
||||||
self.random_tickets_checkbox = QCheckBox("Use a random ticket automatically when enabling a profile")
|
if ConfigurationController.are_tickets_setup():
|
||||||
self.random_tickets_checkbox.setStyleSheet(f"color: white; {self.font_style}")
|
random_group = QGroupBox("Random Ticket Use")
|
||||||
self.random_tickets_checkbox.setChecked(False)
|
random_group.setStyleSheet(
|
||||||
self.random_tickets_checkbox.toggled.connect(self._on_random_toggle)
|
f"QGroupBox {{ color: white; padding: 15px; {self.font_style} }}")
|
||||||
self._random_tickets_state_loaded = False
|
random_layout = QVBoxLayout(random_group)
|
||||||
random_layout.addWidget(self.random_tickets_checkbox)
|
|
||||||
layout.addWidget(random_group)
|
|
||||||
|
|
||||||
inventory_group = QGroupBox("Unused Tickets")
|
self.random_tickets_checkbox = QCheckBox("Use a random ticket automatically when enabling a profile")
|
||||||
inventory_group.setStyleSheet(
|
self.random_tickets_checkbox.setStyleSheet(f"color: white; {self.font_style}")
|
||||||
f"QGroupBox {{ color: white; padding: 15px; {self.font_style} }}")
|
self.random_tickets_checkbox.setChecked(False)
|
||||||
inventory_layout = QVBoxLayout(inventory_group)
|
self.random_tickets_checkbox.toggled.connect(self._on_random_toggle)
|
||||||
|
self._random_tickets_state_loaded = False
|
||||||
|
random_layout.addWidget(self.random_tickets_checkbox)
|
||||||
|
layout.addWidget(random_group)
|
||||||
|
|
||||||
self.tickets_inventory_label = QLabel("Loading tickets...")
|
inventory_group = QGroupBox("Unused Tickets")
|
||||||
self.tickets_inventory_label.setStyleSheet(
|
inventory_group.setStyleSheet(
|
||||||
f"color: white; font-size: 13px; {self.font_style}")
|
f"QGroupBox {{ color: white; padding: 15px; {self.font_style} }}")
|
||||||
self.tickets_inventory_label.setWordWrap(True)
|
inventory_layout = QVBoxLayout(inventory_group)
|
||||||
inventory_layout.addWidget(self.tickets_inventory_label)
|
|
||||||
|
|
||||||
self.refresh_tickets_button = QPushButton("Refresh")
|
self.tickets_inventory_label = QLabel("Loading tickets...")
|
||||||
self.refresh_tickets_button.setFixedSize(120, 32)
|
self.tickets_inventory_label.setStyleSheet(
|
||||||
self.refresh_tickets_button.setStyleSheet(f"""
|
f"color: white; font-size: 13px; {self.font_style}")
|
||||||
QPushButton {{
|
self.tickets_inventory_label.setWordWrap(True)
|
||||||
background: #00aaff; color: white; border: none;
|
inventory_layout.addWidget(self.tickets_inventory_label)
|
||||||
border-radius: 5px; font-weight: bold; {self.font_style}
|
|
||||||
}}
|
self.refresh_tickets_button = QPushButton("Refresh")
|
||||||
QPushButton:hover {{ background: #0088cc; }}
|
self.refresh_tickets_button.setFixedSize(120, 32)
|
||||||
""")
|
self.refresh_tickets_button.setStyleSheet(setting_style_b(self.font_style))
|
||||||
self.refresh_tickets_button.clicked.connect(self._refresh_tickets_inventory)
|
|
||||||
inventory_layout.addWidget(self.refresh_tickets_button)
|
self.refresh_tickets_button.clicked.connect(self._refresh_tickets_inventory)
|
||||||
layout.addWidget(inventory_group)
|
inventory_layout.addWidget(self.refresh_tickets_button)
|
||||||
|
layout.addWidget(inventory_group)
|
||||||
|
|
||||||
saved_failure = self._prepared_value(
|
saved_failure = self._prepared_value(
|
||||||
"ticket_failure", self.update_status.get_ticket_verification_failure)
|
"ticket_failure", self.update_status.get_ticket_verification_failure)
|
||||||
|
|
@ -1636,14 +1639,7 @@ class Settings(Page):
|
||||||
self.evaluate_public_key_button = QPushButton("Evaluate Public Key")
|
self.evaluate_public_key_button = QPushButton("Evaluate Public Key")
|
||||||
self.evaluate_public_key_button.setFixedSize(180, 36)
|
self.evaluate_public_key_button.setFixedSize(180, 36)
|
||||||
self.evaluate_public_key_button.setEnabled(has_failure)
|
self.evaluate_public_key_button.setEnabled(has_failure)
|
||||||
self.evaluate_public_key_button.setStyleSheet(f"""
|
self.evaluate_public_key_button.setStyleSheet(setting_evaluate_style_c(self.font_style))
|
||||||
QPushButton {{
|
|
||||||
background: #00aaff; color: white; border: none;
|
|
||||||
border-radius: 5px; font-weight: bold; {self.font_style}
|
|
||||||
}}
|
|
||||||
QPushButton:hover:!disabled {{ background: #0088cc; }}
|
|
||||||
QPushButton:disabled {{ background: #666666; color: #bbbbbb; }}
|
|
||||||
""")
|
|
||||||
self.evaluate_public_key_button.clicked.connect(self.evaluate_ticket_public_key)
|
self.evaluate_public_key_button.clicked.connect(self.evaluate_ticket_public_key)
|
||||||
recovery_layout.addWidget(self.evaluate_public_key_button)
|
recovery_layout.addWidget(self.evaluate_public_key_button)
|
||||||
|
|
||||||
|
|
@ -1664,14 +1660,7 @@ class Settings(Page):
|
||||||
"Prepare Tickets even if validation of the server's signature failed")
|
"Prepare Tickets even if validation of the server's signature failed")
|
||||||
self.prepare_saved_blind_sigs_button.setFixedSize(500, 40)
|
self.prepare_saved_blind_sigs_button.setFixedSize(500, 40)
|
||||||
self.prepare_saved_blind_sigs_button.setEnabled(has_failure)
|
self.prepare_saved_blind_sigs_button.setEnabled(has_failure)
|
||||||
self.prepare_saved_blind_sigs_button.setStyleSheet(f"""
|
self.prepare_saved_blind_sigs_button.setStyleSheet(setting_evaluate_style_d(self.font_style))
|
||||||
QPushButton {{
|
|
||||||
background: #c0392b; color: white; border: none;
|
|
||||||
border-radius: 5px; font-size: 10px; font-weight: bold; {self.font_style}
|
|
||||||
}}
|
|
||||||
QPushButton:hover:!disabled {{ background: #a93226; }}
|
|
||||||
QPushButton:disabled {{ background: #666666; color: #bbbbbb; }}
|
|
||||||
""")
|
|
||||||
self.prepare_saved_blind_sigs_button.clicked.connect(self.prepare_tickets_with_saved_blind_signatures)
|
self.prepare_saved_blind_sigs_button.clicked.connect(self.prepare_tickets_with_saved_blind_signatures)
|
||||||
debug_layout.addWidget(self.prepare_saved_blind_sigs_button)
|
debug_layout.addWidget(self.prepare_saved_blind_sigs_button)
|
||||||
|
|
||||||
|
|
@ -1782,15 +1771,19 @@ class Settings(Page):
|
||||||
|
|
||||||
def _on_random_toggle(self, checked):
|
def _on_random_toggle(self, checked):
|
||||||
core_logger.info(f"User toggled random ticket setting to {'on' if checked else 'off'}")
|
core_logger.info(f"User toggled random ticket setting to {'on' if checked else 'off'}")
|
||||||
try:
|
worked = ConfigurationController.change_random_ticket(checked)
|
||||||
result = modify_random_tickets_setting('on' if checked else 'off', ticket_observer)
|
if not worked:
|
||||||
if not (isinstance(result, dict) and result.get('valid')):
|
self.update_status.update_status('Could not change random ticket setting')
|
||||||
msg = result.get('message', 'failed') if isinstance(result, dict) else 'failed'
|
|
||||||
core_logger.error(f"Could not change random ticket setting: {msg}")
|
# try:
|
||||||
self.update_status.update_status(f'Could not change setting: {msg}')
|
# result = modify_random_tickets_setting('on' if checked else 'off', ticket_observer)
|
||||||
except Exception as e:
|
# if not (isinstance(result, dict) and result.get('valid')):
|
||||||
core_logger.error(f"Exception changing random ticket setting: {e}")
|
# msg = result.get('message', 'failed') if isinstance(result, dict) else 'failed'
|
||||||
self.update_status.update_status(f'Could not change setting: {e}')
|
# core_logger.error(f"Could not change random ticket setting: {msg}")
|
||||||
|
# self.update_status.update_status(f'Could not change setting: {msg}')
|
||||||
|
# except Exception as e:
|
||||||
|
# core_logger.error(f"Exception changing random ticket setting: {e}")
|
||||||
|
# self.update_status.update_status(f'Could not change setting: {e}')
|
||||||
|
|
||||||
def _refresh_tickets_inventory(self):
|
def _refresh_tickets_inventory(self):
|
||||||
if not hasattr(self, 'tickets_inventory_label'):
|
if not hasattr(self, 'tickets_inventory_label'):
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,9 @@ class TicketOrBillingChoicePage(Page):
|
||||||
use_a_ticket(profile_id=profile_id, which_ticket=which_ticket, ui_caller=self.recieve_use_result)
|
use_a_ticket(profile_id=profile_id, which_ticket=which_ticket, ui_caller=self.recieve_use_result)
|
||||||
self.update_status.update_status(f"Using ticket #{which_ticket}...")
|
self.update_status.update_status(f"Using ticket #{which_ticket}...")
|
||||||
|
|
||||||
|
# Navigate right away:
|
||||||
|
self.custom_window.navigator.navigate("menu")
|
||||||
|
|
||||||
|
|
||||||
def recieve_use_result(self, result: Result):
|
def recieve_use_result(self, result: Result):
|
||||||
"""Recieves the callback from gui_uses_ticket"""
|
"""Recieves the callback from gui_uses_ticket"""
|
||||||
|
|
|
||||||
43
gui/v2/ui/styles/css/settings_styles.py
Normal file
43
gui/v2/ui/styles/css/settings_styles.py
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TICKET_SETTING_STYLE_A = """
|
||||||
|
QScrollArea {
|
||||||
|
background-color: transparent;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
QScrollArea > QWidget > QWidget {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def setting_style_b(font_style: str) -> str:
|
||||||
|
return f"""
|
||||||
|
QPushButton {{
|
||||||
|
background: #00aaff; color: white; border: none;
|
||||||
|
border-radius: 5px; font-weight: bold; {font_style}
|
||||||
|
}}
|
||||||
|
QPushButton:hover {{ background: #0088cc; }}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def setting_evaluate_style_c(font_style: str) -> str:
|
||||||
|
return f"""
|
||||||
|
QPushButton {{
|
||||||
|
background: #00aaff; color: white; border: none;
|
||||||
|
border-radius: 5px; font-weight: bold; {font_style}
|
||||||
|
}}
|
||||||
|
QPushButton:hover:!disabled {{ background: #0088cc; }}
|
||||||
|
QPushButton:disabled {{ background: #666666; color: #bbbbbb; }}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setting_evaluate_style_d(font_style: str) -> str:
|
||||||
|
return f"""
|
||||||
|
QPushButton {{
|
||||||
|
background: #c0392b; color: white; border: none;
|
||||||
|
border-radius: 5px; font-size: 10px; font-weight: bold; {font_style}
|
||||||
|
}}
|
||||||
|
QPushButton:hover:!disabled {{ background: #a93226; }}
|
||||||
|
QPushButton:disabled {{ background: #666666; color: #bbbbbb; }}
|
||||||
|
"""
|
||||||
Loading…
Reference in a new issue