From 7910586e1a2d4dc9268c0a141f2cde038c08188c Mon Sep 17 00:00:00 2001 From: SimplifiedPrivacy Date: Wed, 1 Jul 2026 13:47:13 -0400 Subject: [PATCH] Legacy Database clients flow into recovery prompt --- gui/__main__.py | 89 ++++++++++++++-------- gui/__pycache__/main_ui.cpython-312.pyc | Bin 43473 -> 43497 bytes gui/assets/yaml_mappings/locations.yaml | 54 ------------- gui/assets/yaml_mappings/mapping_one.yaml | 8 -- gui/assets/yaml_mappings/operators.yaml | 19 ----- gui/v2/ui/pages/payment_details_page.py | 10 ++- 6 files changed, 68 insertions(+), 112 deletions(-) delete mode 100644 gui/assets/yaml_mappings/locations.yaml delete mode 100644 gui/assets/yaml_mappings/mapping_one.yaml delete mode 100644 gui/assets/yaml_mappings/operators.yaml 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 39261e116c8cfa3bc6ba2fba3af24bf027979858..8bb45ea08e91928d23f9f7257399a0731ab09710 100644 GIT binary patch delta 662 zcmcb3nd#+aCa%-Gyj%=GFwN28IQS*OhE8D%o6CvTI=2JXg(^Ra_V-@dGF$cwN!vqN2?O z+mOqOp$!a^|7-7q%K>%SUR1KZU>9~-DI6$wNoOHk4z4fsvSJueu0wY-l4aHxm8>r- z*#a%|(VNN0m^JyCeuvFvDU0u{%qmJc3H|Cs6iQ|Ve&=;F{aPVo6i`SF*7cm%xt1#a8XM869XHs(FC>| zlJfIqXUfi&pTKrYSn`IZ{&h{8i<&ljqAzQDUJy~cp>0PN1gE zb4+BIMFb#$Fu~=zi0(xZ-OD2SKo_4f->=5ly}2vSf>G;&SmY-LM$SOS4!0XTLf3iZ zFY?GQVY;qhbWy?Rx`O{j1^=r&0UwxwDmFih7v^OB#i(ATIC*`h=w{)}f6R;ylZA4% zB`%2Nf((%Xo6+yv>D%l75vWCGb71Z*7NBQziqbePhU4yjK~FrD+E^EeA)cE)=EH04xB`` xr0+<);23_zEMkV@btz!r8eEn#YGAk!mjnzF&puN&V3Mn!;v@p34z1v41OQv6=1Kqn delta 551 zcmaEPnd#zXCa%-Gyj%=Gkg2_q>ycd&|>=x5~Trs|iZrt7=pCzs}?=9Lt0 zJ|x@D!FX%3mzuL6FHlDV!ve+YN;VgjY_2HTZC;?}%PJ}e6#fAe7rd@$b5YUef^EnZ z#n8ztI{V-M}>uWw1f;qP+1X9+MkV=AT$MpEWRJW}H2l#YBhsij?+b z3ll}A+X|BtOzb%r6pcS}GDz!eUTz}8EW`)#@dTIaBDxnvbgzi$Z@zB6UyZSK^Yl0i zM&`?6k&|!4%P}*EM{WKYFU$!HU*1e{7Dk)Ns=3-Cm&I~B+-~p)_4{`E_WFMWs>);B zoRNErg>m6z=b|*AZjZ?ui;P$p#61}|KPxI=2Znxl)l?w)wknKY1!VOLPV#YqH6-CDuV2mpt*z90Yq 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...')