diff --git a/src/openstan/presenters/admin_presenter.py b/src/openstan/presenters/admin_presenter.py index 754ca22..44684ce 100644 --- a/src/openstan/presenters/admin_presenter.py +++ b/src/openstan/presenters/admin_presenter.py @@ -1,4 +1,6 @@ +import os import shutil +import sys import traceback from pathlib import Path from typing import TYPE_CHECKING @@ -7,7 +9,6 @@ from PySide6.QtWidgets import QApplication, QMessageBox from openstan.components import StanErrorMessage, StanInfoMessage -from openstan.data.create_gui_db import create_gui_db from openstan.paths import Paths if TYPE_CHECKING: @@ -182,12 +183,14 @@ def remove_project_from_ui(self) -> None: @Slot() def empty_gui_db(self) -> None: - """Delete and recreate gui.db, then quit the application.""" + """Delete gui.db and restart the application.""" if not self._confirm( "Confirm Reset", "Reset the application?\n\n" - "This will permanently delete all projects, sessions, and users from gui.db " - "and close the application.\n\n" + "This will remove all project records, sessions, and users from gui.db " + "and restart the application.\n\n" + "Your project folders and data will not be affected — " + "you can re-attach them using 'Add Existing Project' on startup.\n\n" "This action cannot be undone.", icon=QMessageBox.Icon.Critical, ): @@ -201,14 +204,25 @@ def empty_gui_db(self) -> None: try: if gui_db_path.exists(): gui_db_path.unlink() - create_gui_db(gui_db_path) except Exception: # noqa: BLE001 traceback.print_exc() StanErrorMessage(parent=self.view).showMessage( - "Failed to recreate gui.db. The application will now close." + "Failed to delete gui.db. The application will now close." ) + QApplication.quit() + return - QApplication.quit() + # Restart — the new process will recreate gui.db on startup + argv = list(getattr(sys, "orig_argv", sys.argv)) + argv[0] = sys.executable + try: + os.execv(sys.executable, argv) + except OSError: + traceback.print_exc() + StanErrorMessage(parent=self.view).showMessage( + "Failed to restart the application. The application will now close." + ) + QApplication.quit() @Slot() def open_anonymise_tool(self) -> None: diff --git a/src/openstan/views/admin_view.py b/src/openstan/views/admin_view.py index d0f059a..6b1a154 100644 --- a/src/openstan/views/admin_view.py +++ b/src/openstan/views/admin_view.py @@ -104,15 +104,17 @@ def __init__(self, parent=None) -> None: lbl_empty_title = StanLabel("##### Reset Application") lbl_empty_info = StanLabel( - "Deletes and recreates gui.db, then closes the application. " - "All projects, sessions, and users will be permanently lost. " + "Removes all project records, sessions, and users from gui.db " + "and restarts the application. Project folders and data are not affected — " + "re-attach them using 'Add Existing Project' on startup. " "This action cannot be undone." ) lbl_empty_info.setWordWrap(True) self.button_empty_db = StanButton("Empty Database && Restart") self.button_empty_db.setToolTip( - "Delete and recreate gui.db, then restart the application — all projects, sessions, and users will be permanently lost" + "Remove all project records, sessions, and users from gui.db and restart — " + "project folders and data are unaffected" ) self.button_empty_db.setStyleSheet( "StanButton { color: palette(highlight); font-weight: bold; }"