115 lines
4.8 KiB
Python
Executable file
115 lines
4.8 KiB
Python
Executable file
import os
|
|
|
|
from PyQt6.QtWidgets import QLabel, QPushButton
|
|
from PyQt6.QtGui import QPixmap
|
|
from PyQt6.QtCore import Qt
|
|
|
|
from core.controllers.PolicyController import PolicyController
|
|
from core.Errors import (
|
|
CommandNotFoundError,
|
|
PolicyAssignmentError,
|
|
PolicyInstatementError,
|
|
)
|
|
|
|
from gui.v2.ui.pages.Page import Page
|
|
|
|
|
|
class SystemwidePromptPage(Page):
|
|
def __init__(self, page_stack, main_window=None, parent=None):
|
|
super().__init__("Systemwide", page_stack, main_window, parent)
|
|
self.btn_path = main_window.btn_path
|
|
self.update_status = main_window
|
|
self.button_back.setVisible(True)
|
|
self.button_back.clicked.connect(self.back_to_install)
|
|
self.button_next.setVisible(False)
|
|
self.button_go.setVisible(False)
|
|
self.status_label = QLabel(self)
|
|
self.status_label.setGeometry(80, 430, 640, 40)
|
|
self.status_label.setStyleSheet("font-size: 14px; color: cyan;")
|
|
self.setup_ui()
|
|
|
|
def setup_ui(self):
|
|
self.title.setGeometry(20, 50, 760, 40)
|
|
self.title.setText("Enable \"no sudo\" systemwide")
|
|
description = QLabel(self)
|
|
description.setGeometry(80, 100, 640, 120)
|
|
description.setWordWrap(True)
|
|
description.setStyleSheet("font-size: 14px; color: cyan;")
|
|
description.setText("If you're using Systemwide profiles, you may wish to enable them without having to enter the sudo password each time for convenience. This requires the sudo password to setup profiles and disable them (for security), but not to turn it on each time. You can choose to set this up now or later in the options menu.")
|
|
|
|
icon_label = QLabel(self)
|
|
icon_label.setGeometry(80, 300, 64, 64)
|
|
icon_pix = QPixmap(os.path.join(
|
|
self.btn_path, "wireguard_system_wide.png"))
|
|
icon_label.setPixmap(icon_pix.scaled(
|
|
64, 64, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation))
|
|
yes_button = QPushButton("Yes, enable system-wide profiles", self)
|
|
yes_button.setGeometry(170, 300, 300, 50)
|
|
yes_button.setStyleSheet("""
|
|
QPushButton {
|
|
background: #007AFF;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
font-size: 13px;
|
|
font-weight: bold;
|
|
}
|
|
QPushButton:hover {
|
|
background: #0056CC;
|
|
}
|
|
""")
|
|
yes_button.clicked.connect(self.enable_systemwide)
|
|
no_button = QPushButton("Not now", self)
|
|
no_button.setGeometry(170, 370, 120, 40)
|
|
no_button.setStyleSheet("""
|
|
QPushButton {
|
|
background: #007AFF;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
font-size: 13px;
|
|
font-weight: bold;
|
|
}
|
|
QPushButton:hover {
|
|
background: #0056CC;
|
|
}
|
|
""")
|
|
no_button.clicked.connect(self.skip_systemwide)
|
|
self.refresh_status()
|
|
|
|
def refresh_status(self):
|
|
privilege_policy = PolicyController.get('privilege')
|
|
if privilege_policy is not None and PolicyController.is_instated(privilege_policy):
|
|
self.status_label.setText(
|
|
"Current status: system-wide policy is enabled.")
|
|
self.status_label.setStyleSheet("font-size: 14px; color: #2ecc71;")
|
|
else:
|
|
self.status_label.setText(
|
|
"Current status: system-wide policy is disabled.")
|
|
self.status_label.setStyleSheet("font-size: 14px; color: #e67e22;")
|
|
|
|
def enable_systemwide(self):
|
|
try:
|
|
privilege_policy = PolicyController.get('privilege')
|
|
if privilege_policy is not None:
|
|
PolicyController.instate(privilege_policy)
|
|
self.update_status.mark_systemwide_prompt_shown()
|
|
self.refresh_status()
|
|
self.update_status.update_status("System-wide policy enabled")
|
|
self.custom_window.navigator.navigate("menu")
|
|
except CommandNotFoundError as e:
|
|
self.status_label.setText(str(e))
|
|
self.status_label.setStyleSheet("font-size: 14px; color: red;")
|
|
except (PolicyAssignmentError, PolicyInstatementError) as e:
|
|
self.status_label.setText(str(e))
|
|
self.status_label.setStyleSheet("font-size: 14px; color: red;")
|
|
except Exception:
|
|
self.status_label.setText("Failed to enable system-wide policy")
|
|
self.status_label.setStyleSheet("font-size: 14px; color: red;")
|
|
|
|
def skip_systemwide(self):
|
|
self.update_status.mark_systemwide_prompt_shown()
|
|
self.custom_window.navigator.navigate("menu")
|
|
|
|
def back_to_install(self):
|
|
self.custom_window.navigator.navigate("install_system_package")
|