From 8dc09916196dc28b2981a4bfcc890c4870abc0f4 Mon Sep 17 00:00:00 2001 From: oop7 <110548351+oop7@users.noreply.github.com> Date: Tue, 28 Apr 2026 13:30:13 +0300 Subject: [PATCH] Persist cookie settings across sessions Restore cookie configuration on startup when previously active and the user opted to remember them. If config indicates a file source and the path exists, set cookie_file_path; if browser source, set browser_cookies_option. Treat missing "cookie_remember" as true by default. If the user did not opt to remember cookies, reset cookie_active to false. Added logging for restored settings and initialization state. --- ytsage/gui/ytsage_gui_main.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/ytsage/gui/ytsage_gui_main.py b/ytsage/gui/ytsage_gui_main.py index 40794f5..089ea18 100644 --- a/ytsage/gui/ytsage_gui_main.py +++ b/ytsage/gui/ytsage_gui_main.py @@ -330,13 +330,31 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin, AnalysisMixin): logger.exception(f"Error playing notification sound: {e}") def _initialize_cookie_settings_from_config(self) -> None: - """Initialize cookie settings - cookies are NOT auto-activated on startup. - User must explicitly click Apply in the dialog each session.""" - # Cookies always start inactive on app launch - # User must click Apply in Custom Options dialog to activate them + """Initialize cookie settings and restore from last session if active.""" self.cookie_file_path = None self.browser_cookies_option = None - logger.debug("Cookie settings initialized - no cookies active (user must apply manually)") + + # Check if the user wants to remember cookies across sessions + remember_val = ConfigManager.get("cookie_remember") + should_remember = True if remember_val is None else remember_val + + if ConfigManager.get("cookie_active") and should_remember: + source = ConfigManager.get("cookie_source") + if source == "file": + saved_path = ConfigManager.get("cookie_file_path") + if saved_path and Path(saved_path).exists(): + self.cookie_file_path = Path(saved_path) + logger.info(f"Restored cookie file from previous session: {self.cookie_file_path}") + elif source == "browser": + browser = ConfigManager.get("cookie_browser") + profile = ConfigManager.get("cookie_browser_profile") + if browser: + self.browser_cookies_option = f"{browser}:{profile}" if profile else browser + logger.info(f"Restored browser cookies from previous session: {self.browser_cookies_option}") + else: + # Revert activation back if the user opted NOT to remember them + ConfigManager.set("cookie_active", False) + logger.debug("Cookie settings initialized - no cookies active") def init_ui(self) -> None: self.setWindowTitle(f"{_('app.title')} {_('app.version', version=self.version)}")