diff --git a/gui/__main__.py b/gui/__main__.py index 29579fd..2b23078 100644 --- a/gui/__main__.py +++ b/gui/__main__.py @@ -1,24 +1,76 @@ from core.errors.logger import logger -from core.models.manage.session_management import init_session, get_session, close_session, create_ALL_tables, create_ONLY_db_version_table, get_path +from core.models.manage.session_management import init_session, get_session, close_session, create_ALL_tables, create_ONLY_db_version_table, get_path, does_it_exist, does_db_version_table_exist from core.models.manage.version_check import check_database_compatibility, insert_new_version, get_custom_message from core.Constants import Constants # generic import os import sys +# ============================================================================ +# DISPLAY CHOICES AND RECOVERY UI +# ============================================================================ +def recovery_dialog(custom_error, db_version_you_have): + """This ends the app by forcing them to delete the database, move it, or just quit.""" + + from v2.ui.popups.Database_version import show_recovery_dialog + choice = show_recovery_dialog({"message": custom_error, "db_version": db_version_you_have, "status": "version_mismatch"}) + logger.info(f"[DB MANAGEMENT] From the database error options, the user picked {choice}") + + if choice == 1: + if os.path.exists(database_path): + os.remove(database_path) + logger.info(f"[DB MANAGEMENT] Deleted the DB file at {database_path}") + logger.info(f"[DB MANAGEMENT] Closing the app gracefully, for them to reboot..") + sys.exit() + + elif choice == 2: + logger.info(f"[DB MANAGEMENT] User opted to move the DB file.") + from v2.ui.popups.pick_folder_to_move import launch_file_picker + launch_file_picker(database_path) + sys.exit() + + else: + logger.error(f"[DB MANAGEMENT] User opted to close the app WITHOUT wiping the database, even though they need to.") + sys.exit() + # ============================================================================ # INITIALIZE DATABASE # ============================================================================ +# Does the database exist? +system_path = get_path() +database_path = system_path / "storage.db" +main_db_exists = does_it_exist(database_path) -# (engine, Session, _session all initialized from session_management) -init_session() +# Setup operations on the main DB which create it +init_session() # (engine, Session, _session all initialized from session_management) session = get_session() -create_ONLY_db_version_table() + +# does the version checker table exist? +version_table_exists = does_db_version_table_exist() + +# are they upgrading from a legacy version? +# that would mean the table existed, but not the version table, +if not version_table_exists and main_db_exists: + logger.info(f"[DB MANAGEMENT] We are dealing with a legacy database, we need to transition the user.") + + # shut down db connection + close_session() + + # THEN DISPLAY CHOICES AND RECOVERY UI + custom_error = "You're using a Legacy version of the Database scheme. Please delete it and fetch the new data." + db_version_you_have = "Old System" + recovery_dialog(custom_error, db_version_you_have) + sys.exit() + +# If they're still here, then if it's NOT a legacy version, + +# and the new version table doesn't exist, then create it: +if not version_table_exists: + create_ONLY_db_version_table() # ============================================================================ # COMPARE DB VERISONS # ============================================================================ - compatability_dict = check_database_compatibility(session) reason = compatability_dict.get("reason", "error") is_compatable = compatability_dict.get("result", False) @@ -75,29 +127,6 @@ else: # shut down db connection close_session() -# ============================================================================ -# THEN DISPLAY CHOICES AND RECOVERY UI -# ============================================================================ - from v2.ui.popups.Database_version import show_recovery_dialog - choice = show_recovery_dialog({"message": custom_error, "db_version": db_version_you_have, "status": "version_mismatch"}) - logger.info(f"[DB MANAGEMENT] From the database error options, the user picked {choice}") + # THEN DISPLAY CHOICES AND RECOVERY UI + recovery_dialog(custom_error, db_version_you_have) - system_path = get_path() - database_path = system_path / "storage.db" - - if choice == 1: - if os.path.exists(database_path): - os.remove(database_path) - logger.info(f"[DB MANAGEMENT] Deleted the DB file at {database_path}") - logger.info(f"[DB MANAGEMENT] Closing the app gracefully, for them to reboot..") - sys.exit() - - elif choice == 2: - logger.info(f"[DB MANAGEMENT] User opted to move the DB file.") - from v2.ui.popups.pick_folder_to_move import launch_file_picker - launch_file_picker(database_path) - sys.exit() - - else: - logger.error(f"[DB MANAGEMENT] User opted to close the app WITHOUT wiping the database, even though they need to.") - sys.exit() diff --git a/gui/__pycache__/main_ui.cpython-312.pyc b/gui/__pycache__/main_ui.cpython-312.pyc index 39261e1..8bb45ea 100644 Binary files a/gui/__pycache__/main_ui.cpython-312.pyc and b/gui/__pycache__/main_ui.cpython-312.pyc differ diff --git a/gui/assets/yaml_mappings/locations.yaml b/gui/assets/yaml_mappings/locations.yaml deleted file mode 100644 index 97ee248..0000000 --- a/gui/assets/yaml_mappings/locations.yaml +++ /dev/null @@ -1,54 +0,0 @@ -fields: - - name: country_code - path: ['country', 'code'] - required: true - - - name: code # this is city code - path: ['code'] - required: true - - - name: id - path: ['id'] - - - name: country_name - path: ['country', 'name'] - - - name: name # this is CITY name - path: ['name'] - - - name: time_zone - path: ['time_zone', 'code'] - - - name: operator_id - path: ['operator_id'] - required: true - - - name: provider_name - path: ['provider', 'name'] - - - name: is_proxy_capable - path: ['is_proxy_capable'] - - - name: is_wireguard_capable - path: ['is_wireguard_capable'] - required: true - - - name: is_hysteria2_capable - path: ['is_hysteria2_capable'] - - - name: is_vless_capable - path: ['is_vless_capable'] - - -# original version: - # locations.append(( - # location['country']['code'], - # location['code'], - # location['id'], - # location['country']['name'], - # location['name'], - # location['time_zone']['code'], - # location['operator_id'], - # location['provider']['name'], - # location['is_proxy_capable'], - # location['is_wireguard_capable'])) diff --git a/gui/assets/yaml_mappings/mapping_one.yaml b/gui/assets/yaml_mappings/mapping_one.yaml deleted file mode 100644 index 903eaba..0000000 --- a/gui/assets/yaml_mappings/mapping_one.yaml +++ /dev/null @@ -1,8 +0,0 @@ -fields: - - name: group_a_code - path: ['group_a', 'code'] - - name: code - path: ['code'] - - name: id - path: ['id'] - required: true diff --git a/gui/assets/yaml_mappings/operators.yaml b/gui/assets/yaml_mappings/operators.yaml deleted file mode 100644 index f7e9b8f..0000000 --- a/gui/assets/yaml_mappings/operators.yaml +++ /dev/null @@ -1,19 +0,0 @@ -fields: - - name: id - path: ['id'] - required: true - - - name: name - path: ['name'] - - - name: public_key # this is ed25519 - path: ['public_key'] - - - name: nostr_public_key - path: ['nostr_public_key'] - - - name: nostr_profile_reference - path: ['nostr_profile_reference'] - - - name: nostr_attestation_event_reference - path: ['nostr_attestation', 'event_reference'] diff --git a/gui/v2/ui/pages/payment_details_page.py b/gui/v2/ui/pages/payment_details_page.py index 7ace9a3..ffe9dca 100755 --- a/gui/v2/ui/pages/payment_details_page.py +++ b/gui/v2/ui/pages/payment_details_page.py @@ -2,7 +2,7 @@ import os from PyQt6.QtWidgets import QApplication, QLabel, QLineEdit, QPushButton from PyQt6.QtGui import QIcon, QPixmap -from PyQt6.QtCore import QSize, QTimer +from PyQt6.QtCore import QSize, QTimer, QThread from PyQt6 import QtCore from gui.v2.ui.pages.Page import Page @@ -340,6 +340,14 @@ class PaymentDetailsPage(Page): self._populate_ticket_fields(invoice) if self.ticket_poll_timer.isActive(): self.ticket_poll_timer.stop() + + ### NEW THREAD SAFETY DEBUG SECTION #### + # print(f"Timer starting from thread: {QThread.currentThread()}") + # print(f"Main thread is: {QApplication.instance().thread()}") + # if QThread.currentThread() != QApplication.instance().thread(): + # print("⚠️ WARNING: Not on main thread!") + ############################################################### + self.ticket_poll_timer.start(3000) self.update_status.update_status('Awaiting ticket payment...')