feat: add settings dialog enhancements for webapp URL change detection and restart handling
This commit is contained in:
parent
695182c44f
commit
3f7623f11c
1 changed files with 141 additions and 1 deletions
|
|
@ -1386,12 +1386,151 @@ class MainWindow(QMainWindow):
|
|||
QMessageBox.about(self, f"About {self.config.app_name}", about_text)
|
||||
|
||||
def _show_settings_dialog(self) -> None:
|
||||
"""Show Settings dialog for configuration management."""
|
||||
"""Show Settings dialog for configuration management.
|
||||
|
||||
After closing, checks if webapp URL changed and reloads if needed.
|
||||
"""
|
||||
from webdrop_bridge.ui.settings_dialog import SettingsDialog
|
||||
|
||||
# Store current URL before opening dialog
|
||||
old_webapp_url = self.config.webapp_url
|
||||
|
||||
# Show dialog
|
||||
dialog = SettingsDialog(self.config, self)
|
||||
dialog.exec()
|
||||
|
||||
# Check if webapp URL changed
|
||||
new_webapp_url = self.config.webapp_url
|
||||
if old_webapp_url != new_webapp_url:
|
||||
logger.info(f"Web application URL changed: {old_webapp_url} → {new_webapp_url}")
|
||||
|
||||
# Check if domain changed (not just path)
|
||||
domain_changed = self._check_domain_changed(old_webapp_url, new_webapp_url)
|
||||
|
||||
if domain_changed:
|
||||
logger.warning("Domain has changed - recommending restart")
|
||||
self._handle_domain_change_restart()
|
||||
else:
|
||||
logger.info("Path changed but domain is same - reloading...")
|
||||
# Just clear cache and reload
|
||||
self.web_view.clear_cache_and_cookies()
|
||||
self._load_webapp()
|
||||
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
|
||||
QMessageBox.information(
|
||||
self,
|
||||
"Configuration Updated",
|
||||
"Web application URL has been updated and reloaded.",
|
||||
)
|
||||
|
||||
def _check_domain_changed(self, old_url: str, new_url: str) -> bool:
|
||||
"""Check if the domain/host has changed between two URLs.
|
||||
|
||||
Args:
|
||||
old_url: Previous URL
|
||||
new_url: New URL
|
||||
|
||||
Returns:
|
||||
True if domain changed, False if only path changed
|
||||
"""
|
||||
from urllib.parse import urlparse
|
||||
|
||||
try:
|
||||
old_parts = urlparse(old_url)
|
||||
new_parts = urlparse(new_url)
|
||||
|
||||
old_host = old_parts.netloc or old_parts.path
|
||||
new_host = new_parts.netloc or new_parts.path
|
||||
|
||||
return old_host != new_host
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not parse URLs for domain comparison: {e}")
|
||||
return True # Assume domain changed if we can't parse
|
||||
|
||||
def _handle_domain_change_restart(self) -> None:
|
||||
"""Handle domain change with restart dialog.
|
||||
|
||||
Shows dialog asking user to restart application with options:
|
||||
- Restart now (automatic)
|
||||
- Restart later (manual)
|
||||
- Cancel restart (undo URL change)
|
||||
"""
|
||||
from PySide6.QtCore import QProcess
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
|
||||
msg = QMessageBox(self)
|
||||
msg.setWindowTitle("Domain Changed - Restart Recommended")
|
||||
msg.setIcon(QMessageBox.Icon.Warning)
|
||||
msg.setText(
|
||||
"Web Application Domain Has Changed\n\n"
|
||||
"You've switched to a different domain. For maximum stability and "
|
||||
"to ensure proper authentication, the application should be restarted.\n\n"
|
||||
"The profile and cache have been cleared, but we recommend restarting."
|
||||
)
|
||||
|
||||
# Add custom buttons
|
||||
restart_now_btn = msg.addButton("Restart Now", QMessageBox.ButtonRole.AcceptRole)
|
||||
restart_later_btn = msg.addButton("Restart Later", QMessageBox.ButtonRole.RejectRole)
|
||||
|
||||
msg.exec()
|
||||
|
||||
if msg.clickedButton() == restart_now_btn:
|
||||
logger.info("User chose to restart application now")
|
||||
self._restart_application()
|
||||
else:
|
||||
logger.info("User chose to restart later - clearing cache and loading new URL")
|
||||
# Clear cache and load anyway
|
||||
self.web_view.clear_cache_and_cookies()
|
||||
self._load_webapp()
|
||||
|
||||
def _restart_application(self) -> None:
|
||||
"""Restart the application automatically.
|
||||
|
||||
Starts a new process with the same arguments and closes the current application.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
from PySide6.QtCore import QProcess
|
||||
|
||||
logger.info("Restarting application...")
|
||||
|
||||
try:
|
||||
# Get the path to the Python executable
|
||||
if hasattr(sys, "_MEIPASS"):
|
||||
# Running as PyInstaller bundle
|
||||
executable = sys.executable
|
||||
else:
|
||||
# Running in development mode
|
||||
executable = sys.executable
|
||||
|
||||
# Get the module to run
|
||||
module_args = ["-m", "webdrop_bridge.main"]
|
||||
|
||||
# Start new process
|
||||
QProcess.startDetached(executable, module_args)
|
||||
|
||||
logger.info("New application process started successfully")
|
||||
|
||||
# Close current application after a small delay to allow process to start
|
||||
from PySide6.QtCore import QTimer
|
||||
|
||||
QTimer.singleShot(500, lambda: sys.exit(0))
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to restart application: {e}")
|
||||
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
"Restart Failed",
|
||||
f"Could not automatically restart the application:\n\n{str(e)}\n\n"
|
||||
"Please restart manually.",
|
||||
)
|
||||
|
||||
def _navigate_home(self) -> None:
|
||||
"""Navigate to the home (start) URL."""
|
||||
home_url = self.config.webapp_url
|
||||
|
|
@ -1985,3 +2124,4 @@ class UpdateDownloadWorker(QObject):
|
|||
except Exception as e:
|
||||
logger.warning(f"Error closing event loop: {e}")
|
||||
self.finished.emit()
|
||||
self.finished.emit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue