Skip to content

Commit

Permalink
Modified the web management clear profile
Browse files Browse the repository at this point in the history
  • Loading branch information
zitelog committed Sep 29, 2023
1 parent ad61050 commit 11e91cd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
4 changes: 4 additions & 0 deletions common/constants/view/web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ACQUISITION_IS_RUNNING = "Acquisition is running"
WAR_ACQUISITION_IS_RUNNING = (
"You can't close the windows while the acquisition is running"
)
37 changes: 26 additions & 11 deletions view/web/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from view.menu_bar import MenuBar as MenuBarView
from view.error import Error as ErrorView


from common.constants import (
tasks as Tasks,
logger as Logger,
Expand All @@ -39,6 +40,7 @@
details as Details,
)
from common.constants.view import general
from common.constants.view.web import *

from common.settings import DEBUG
from common.config import LogConfigTools
Expand All @@ -47,6 +49,19 @@
logger = logging.getLogger(__name__)


class InitSingletonClass(object):
def __new__(cls):
if not hasattr(cls, "instance"):
cls.instance = super(InitSingletonClass, cls).__new__(cls)
profile = QWebEngineProfile.defaultProfile()
cls.default_download_path = profile.downloadPath()
profile.clearAllVisitedLinks()
cookie_store = profile.cookieStore()
cookie_store.deleteAllCookies()

return cls.instance


class WebEnginePage(QWebEnginePage):
new_page_after_link_with_target_blank_attribute = QtCore.pyqtSignal(QWebEnginePage)

Expand All @@ -73,9 +88,10 @@ class Browser(QWebEngineView):

def __init__(self, parent=None):
super().__init__(parent)
self.singleton = InitSingletonClass()

def reconnect(self):
self.selected_directory = os.path.expanduser("~/Downloads")
self.selected_directory = self.singleton.default_download_path

self.page().profile().setDownloadPath(self.selected_directory)
self.page().profile().downloadRequested.connect(self.__retrieve_download_item)
Expand Down Expand Up @@ -113,7 +129,7 @@ def disconnect_signals(self):

def __handle_download_request(self, download):
if not os.path.isdir(self.selected_directory):
self.selected_directory = os.path.expanduser("~/Downloads")
self.selected_directory = self.singleton.default_download_path
file_dialog = QFileDialog()
file_dialog.setFileMode(QFileDialog.FileMode.Directory)
file_dialog.setDirectory(self.selected_directory)
Expand Down Expand Up @@ -212,8 +228,6 @@ def init(self, case_info, wizard, options=None):
self.start_acquisition_is_started = False
self.stop_acquisition_is_started = False

self.__clear_cache()

self.configuration_general = self.menu_bar.configuration_view.get_tab_from_name(
"configuration_general"
)
Expand Down Expand Up @@ -362,7 +376,6 @@ def __stop_acquisition_is_finished(self):
self.progress_bar.setHidden(True)
self.status.showMessage("")

self.__clear_cache()
profile = QWebEngineProfile.defaultProfile()
profile.clearHttpCache()

Expand Down Expand Up @@ -699,12 +712,6 @@ def load_progress(self, progress):
if progress == 100:
self.navtb.enable_screenshot_buttons()

def __clear_cache(self):
profile = QWebEngineProfile.defaultProfile()
profile.clearAllVisitedLinks()
cookie_store = profile.cookieStore()
cookie_store.deleteAllCookies()

def __update_urlbar(self, q, browser=None):
self.navtb.enable_screenshot_buttons()

Expand Down Expand Up @@ -743,6 +750,14 @@ def __back_to_wizard(self):
self.deleteLater()
self.wizard.reload_case_info()
self.wizard.show()
else:
error_dlg = ErrorView(
QtWidgets.QMessageBox.Icon.Warning,
ACQUISITION_IS_RUNNING,
WAR_ACQUISITION_IS_RUNNING,
"",
)
error_dlg.exec()

def closeEvent(self, event):
event.ignore()
Expand Down

0 comments on commit 11e91cd

Please sign in to comment.