diff --git a/src/gui/ytsage_gui_dialogs/ytsage_dialogs_custom.py b/src/gui/ytsage_gui_dialogs/ytsage_dialogs_custom.py index ce78d59..61218d0 100644 --- a/src/gui/ytsage_gui_dialogs/ytsage_dialogs_custom.py +++ b/src/gui/ytsage_gui_dialogs/ytsage_dialogs_custom.py @@ -30,6 +30,7 @@ from PySide6.QtWidgets import ( from src.core.ytsage_yt_dlp import get_yt_dlp_path from src.utils.ytsage_constants import YTDLP_DOCS_URL +from src.utils.ytsage_config_manager import ConfigManager if TYPE_CHECKING: from src.gui.ytsage_gui_main import YTSageApp # only for type hints (no runtime import) @@ -554,6 +555,7 @@ class CustomOptionsDialog(QDialog): # Initialize dialog with current settings (after all widgets and styles are set) self._initialize_cookie_settings() + self._initialize_proxy_settings() def _initialize_cookie_settings(self) -> None: """Initialize the dialog with current cookie settings from parent""" @@ -583,6 +585,22 @@ class CustomOptionsDialog(QDialog): # No cookies configured - ensure file radio is selected by default self.cookie_file_radio.setChecked(True) + def _initialize_proxy_settings(self) -> None: + """Initialize the dialog with current proxy settings from config""" + # Load proxy settings from config + proxy_url = ConfigManager.get("proxy_url") + geo_proxy_url = ConfigManager.get("geo_proxy_url") + + # Set proxy field values if they exist + if proxy_url: + self.proxy_url_input.setText(proxy_url) + + if geo_proxy_url: + self.geo_proxy_url_input.setText(geo_proxy_url) + + # Update validation status + self.validate_proxy_inputs() + def on_cookie_source_changed(self) -> None: """Handle cookie source radio button changes""" if self.cookie_file_radio.isChecked(): @@ -683,7 +701,20 @@ class CustomOptionsDialog(QDialog): geo_proxy = self.geo_proxy_url_input.text().strip() if not main_proxy and not geo_proxy: - self.proxy_status.setText("") + # Check if there are saved settings + saved_main = ConfigManager.get("proxy_url") + saved_geo = ConfigManager.get("geo_proxy_url") + + if saved_main or saved_geo: + status_parts = [] + if saved_main: + status_parts.append(f"Saved main proxy: {saved_main}") + if saved_geo: + status_parts.append(f"Saved geo proxy: {saved_geo}") + self.proxy_status.setText(" | ".join(status_parts)) + self.proxy_status.setStyleSheet("color: #888888; font-style: italic;") + else: + self.proxy_status.setText("") return issues = [] diff --git a/src/gui/ytsage_gui_main.py b/src/gui/ytsage_gui_main.py index 37f07c3..8018773 100644 --- a/src/gui/ytsage_gui_main.py +++ b/src/gui/ytsage_gui_main.py @@ -45,6 +45,7 @@ from src.gui.ytsage_gui_format_table import FormatTableMixin from src.gui.ytsage_gui_video_info import VideoInfoMixin from src.utils.ytsage_constants import ICON_PATH, SOUND_PATH, SUBPROCESS_CREATIONFLAGS from src.utils.ytsage_logger import logger +from src.utils.ytsage_config_manager import ConfigManager try: import yt_dlp @@ -110,9 +111,9 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from # Initialize cookie settings - ensure they start clean self.cookie_file_path = None self.browser_cookies_option = None - # Initialize proxy settings - self.proxy_url = None - self.geo_proxy_url = None + # Initialize proxy settings from config + self.proxy_url = ConfigManager.get("proxy_url") + self.geo_proxy_url = ConfigManager.get("geo_proxy_url") self.speed_limit_value = None # Store speed limit value self.speed_limit_unit_index = 0 # Store speed limit unit index (0: KB/s, 1: MB/s) self.download_section = None @@ -1411,26 +1412,37 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from proxy_url = dialog.get_proxy_url() geo_proxy_url = dialog.get_geo_proxy_url() - # Clear existing proxy settings - self.proxy_url = None - self.geo_proxy_url = None + # Update instance variables + self.proxy_url = proxy_url + self.geo_proxy_url = geo_proxy_url + # Save proxy settings to config + ConfigManager.set("proxy_url", proxy_url) + ConfigManager.set("geo_proxy_url", geo_proxy_url) + + # Show confirmation messages if proxy_url: - self.proxy_url = proxy_url logger.info(f"Main proxy set: {self.proxy_url}") QMessageBox.information( self, "Proxy Set", - f"Main proxy set: {proxy_url}", + f"Main proxy set and saved: {proxy_url}", ) if geo_proxy_url: - self.geo_proxy_url = geo_proxy_url logger.info(f"Geo-verification proxy set: {self.geo_proxy_url}") QMessageBox.information( self, "Geo Proxy Set", - f"Geo-verification proxy set: {geo_proxy_url}", + f"Geo-verification proxy set and saved: {geo_proxy_url}", + ) + + # Show a combined message if both are cleared + if not proxy_url and not geo_proxy_url and (ConfigManager.get("proxy_url") or ConfigManager.get("geo_proxy_url")): + QMessageBox.information( + self, + "Proxy Settings Cleared", + "All proxy settings have been cleared and saved.", ) def show_about_dialog(self) -> None: # ADDED METHOD HERE diff --git a/src/utils/ytsage_config_manager.py b/src/utils/ytsage_config_manager.py index 062d358..bf83ace 100644 --- a/src/utils/ytsage_config_manager.py +++ b/src/utils/ytsage_config_manager.py @@ -74,6 +74,8 @@ class ConfigManager: "speed_limit_unit_index": 0, "cookie_file_path": None, "last_used_cookie_file": None, + "proxy_url": None, + "geo_proxy_url": None, "auto_update_ytdlp": True, "auto_update_frequency": "daily", "last_update_check": 0,