Added Connection type popup

This commit is contained in:
Your Name 2025-04-26 03:57:59 +01:00
parent 781f4fc9c4
commit 6e7751db01

View file

@ -1,4 +1,4 @@
from PyQt6.QtWidgets import QComboBox,QButtonGroup, QLineEdit,QMainWindow, QLabel, QWidget, QVBoxLayout, QStackedWidget, QApplication, QPushButton, QTextEdit, QFrame, QHBoxLayout, QVBoxLayout, QScrollArea, QSystemTrayIcon, QMessageBox, QGridLayout, QCheckBox, QStackedLayout, QGroupBox
from PyQt6.QtWidgets import QComboBox,QButtonGroup, QLineEdit,QMainWindow, QLabel, QWidget, QVBoxLayout, QStackedWidget, QApplication, QPushButton, QTextEdit, QFrame, QHBoxLayout, QVBoxLayout, QScrollArea, QSystemTrayIcon, QMessageBox, QGridLayout, QCheckBox, QStackedLayout, QGroupBox, QDialog
from PyQt6.QtGui import QIcon, QPixmap,QIcon, QPixmap, QTransform, QPainter, QColor, QFont, QPen
from PyQt6 import QtGui
from PyQt6 import QtCore
@ -326,10 +326,7 @@ class CustomWindow(QMainWindow):
self.current_profile_id = None
self.connection_manager = ConnectionManager()
current_connection = self.get_current_connection()
if current_connection is None:
ConfigurationController.set_connection('system')
current_connection = 'system'
current_connection = 'system' #For Default toggle behavior
self.is_tor_mode = current_connection == 'tor'
self.is_animating = False
self.animation_step = 0
@ -408,12 +405,80 @@ class CustomWindow(QMainWindow):
self.check_logging()
self.init_ui()
current_connection = self.get_current_connection()
self.is_tor_mode = current_connection == 'tor'
self.set_toggle_state(self.is_tor_mode)
def get_current_connection(self):
try:
return ConfigurationController.get_connection()
except UnknownConnectionTypeError:
return None
self.setup_popup()
return ConfigurationController.get_connection()
def setup_popup(self):
connection_dialog = QDialog(self)
connection_dialog.setWindowTitle("Connection Type")
connection_dialog.setWindowFlags(Qt.WindowType.Dialog | Qt.WindowType.WindowStaysOnTopHint | Qt.WindowType.CustomizeWindowHint | Qt.WindowType.WindowTitleHint)
connection_dialog.setModal(True)
connection_dialog.setFixedSize(400, 200)
layout = QVBoxLayout(connection_dialog)
label = QLabel("Please set your preference for connecting to Simplified Privacy's billing server.")
label.setWordWrap(True)
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
label.setStyleSheet("font-size: 12px; margin-bottom: 20px; color: black;")
button_layout = QHBoxLayout()
regular_btn = QPushButton("Regular")
tor_btn = QPushButton("Tor")
button_style = """
QPushButton {
background-color: #2b2b2b;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 12px;
}
QPushButton:hover {
background-color: #3b3b3b;
}
QPushButton:pressed {
background-color: #1b1b1b;
}
"""
regular_btn.setStyleSheet(button_style)
tor_btn.setStyleSheet(button_style)
button_layout.addWidget(regular_btn)
button_layout.addWidget(tor_btn)
layout.addWidget(label)
layout.addLayout(button_layout)
def set_regular_connection():
ConfigurationController.set_connection('system')
self.is_tor_mode = False
self.set_toggle_state(False)
connection_dialog.accept()
def set_tor_connection():
ConfigurationController.set_connection('tor')
self.is_tor_mode = True
self.set_toggle_state(True)
connection_dialog.accept()
regular_btn.clicked.connect(set_regular_connection)
tor_btn.clicked.connect(set_tor_connection)
connection_dialog.exec()
return ConfigurationController.get_connection()
def _setup_gui_directory(self):
os.makedirs(self.gui_dir, exist_ok=True)
@ -1528,7 +1593,7 @@ class MenuPage(Page):
self.update_status.update_status('Profile is already being enabled...')
return
profile = ProfileController.get(int(self.reverse_id))
is_tor = ConfigurationController.get_connection() == 'tor'
is_tor = self.update_status.get_current_connection() == 'tor'
if profile.connection.code == 'tor' and not profile.application_version.installed and not is_tor:
message = f'You are using a Tor profile, but the associated browser is not installed. If you want the browser to be downloaded with Tor, you must switch to a Tor connection. Otherwise, proceed with a clearweb connection.'
@ -1710,7 +1775,7 @@ class MenuPage(Page):
def change_app_page(self, text, Is_changed):
self.update_status.update_status(str(text))
if Is_changed:
current_connection = ConfigurationController.get_connection()
current_connection = self.update_status.get_current_connection()
profile = ProfileController.get(int(self.reverse_id))
if current_connection != 'tor' and profile.connection.code == 'tor':
message = f'You are using a Tor profile, but the profile subscription is missing or expired. If you want the billing to be done thourgh Tor, you must switch to a Tor connection. Otherwise, proceed with a clearweb connection.'
@ -4592,7 +4657,7 @@ class Settings(Page):
stats = [
("Config Path", config_path),
("Client Version", Constants.HV_CLIENT_VERSION_NUMBER),
("Connection", ConfigurationController.get_connection()),
("Connection", self.update_status.get_current_connection()),
]
for i, (label, value) in enumerate(stats):